SHARE
TWEET

Untitled

a guest Sep 11th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use winapi::um::minwinbase::*;
  2. use winapi::um::winbase::*;
  3.  
  4. fn main() {
  5.   unsafe {
  6.     println!("===Fixed, then 0 (fails to realloc)");
  7.     let fixed1 = LocalAlloc(LMEM_FIXED, 40);
  8.     println!("fixed1_ptr: {:p}", fixed1);
  9.     println!("fixed1_size: {}", LocalSize(fixed1));
  10.     println!("fixed1_flags: {}", LocalFlags(fixed1));
  11.     let fixed2 = LocalReAlloc(fixed1, 80, 0);
  12.     println!("fixed2_ptr: {:p}", fixed2);
  13.     println!("fixed2_size: {}", LocalSize(fixed2));
  14.     println!("fixed2_flags: {}", LocalFlags(fixed2));
  15.     if fixed2.is_null() {
  16.       LocalFree(fixed1)
  17.     } else {
  18.       LocalFree(fixed2)
  19.     };
  20.  
  21.     println!("===Fixed, then Modify (does nothing I guess)");
  22.     let fixed1 = LocalAlloc(LMEM_FIXED, 40);
  23.     println!("fixed1_ptr: {:p}", fixed1);
  24.     println!("fixed1_size: {}", LocalSize(fixed1));
  25.     println!("fixed1_flags: {}", LocalFlags(fixed1));
  26.     let fixed2 = LocalReAlloc(fixed1, 80, LMEM_MODIFY);
  27.     println!("fixed2_ptr: {:p}", fixed2);
  28.     println!("fixed2_size: {}", LocalSize(fixed2));
  29.     println!("fixed2_flags: {}", LocalFlags(fixed2));
  30.     if fixed2.is_null() {
  31.       LocalFree(fixed1)
  32.     } else {
  33.       LocalFree(fixed2)
  34.     };
  35.  
  36.     println!("===Fixed, then Modify+Movable (does nothing I guess)");
  37.     let fixed1 = LocalAlloc(LMEM_FIXED, 40);
  38.     println!("fixed1_ptr: {:p}", fixed1);
  39.     println!("fixed1_size: {}", LocalSize(fixed1));
  40.     println!("fixed1_flags: {}", LocalFlags(fixed1));
  41.     let fixed2 = LocalReAlloc(fixed1, 80, LMEM_MODIFY|LMEM_MOVEABLE);
  42.     println!("fixed2_ptr: {:p}", fixed2);
  43.     println!("fixed2_size: {}", LocalSize(fixed2));
  44.     println!("fixed2_flags: {}", LocalFlags(fixed2));
  45.     if fixed2.is_null() {
  46.       LocalFree(fixed1)
  47.     } else {
  48.       LocalFree(fixed2)
  49.     };
  50.  
  51.     println!("<><><><><><><><><><><><><><><><><><><><><><><><><><><><>");
  52.  
  53.     println!("===Movable, then 0 (resizes and ptr moves)");
  54.     let fixed1 = LocalAlloc(LMEM_MOVEABLE, 40);
  55.     let fixed1_ptr = LocalLock(fixed1);
  56.     println!("fixed1_ptr: {:p}", fixed1_ptr);
  57.     println!("fixed1_size: {}", LocalSize(fixed1));
  58.     println!("fixed1_flags: {}", LocalFlags(fixed1));
  59.     assert!(LocalUnlock(fixed1) == 0);
  60.     let fixed2 = LocalReAlloc(fixed1, 800, 0);
  61.     let fixed2_ptr = LocalLock(fixed2);
  62.     println!("fixed2_ptr: {:p}", fixed2_ptr);
  63.     println!("fixed2_size: {}", LocalSize(fixed2));
  64.     println!("fixed2_flags: {}", LocalFlags(fixed2));
  65.     if fixed2.is_null() {
  66.       LocalFree(fixed1)
  67.     } else {
  68.       LocalFree(fixed2)
  69.     };
  70.  
  71.     println!("===Movable, then Modify (ptr moves, no resize)");
  72.     let fixed1 = LocalAlloc(LMEM_MOVEABLE, 40);
  73.     let fixed1_ptr = LocalLock(fixed1);
  74.     println!("fixed1_ptr: {:p}", fixed1_ptr);
  75.     println!("fixed1_size: {}", LocalSize(fixed1));
  76.     println!("fixed1_flags: {}", LocalFlags(fixed1));
  77.     assert!(LocalUnlock(fixed1) == 0);
  78.     let fixed2 = LocalReAlloc(fixed1, 800, LMEM_MODIFY);
  79.     println!("fixed2_ptr: {:p}", fixed2);
  80.     println!("fixed2_size: {}", LocalSize(fixed2));
  81.     println!("fixed2_flags: {}", LocalFlags(fixed2));
  82.     if fixed2.is_null() {
  83.       LocalFree(fixed1)
  84.     } else {
  85.       LocalFree(fixed2)
  86.     };
  87.  
  88.     println!("===Movable, then Modify+Movable (ptr moves... becomes fixed?)");
  89.     let fixed1 = LocalAlloc(LMEM_MOVEABLE, 40);
  90.     let fixed1_ptr = LocalLock(fixed1);
  91.     println!("fixed1_ptr: {:p}", fixed1_ptr);
  92.     println!("fixed1_size: {}", LocalSize(fixed1));
  93.     println!("fixed1_flags: {}", LocalFlags(fixed1));
  94.     assert!(LocalUnlock(fixed1) == 0);
  95.     let fixed2 = LocalReAlloc(fixed1, 800, LMEM_MODIFY | LMEM_MOVEABLE);
  96.     println!("fixed2_ptr: {:p}", fixed2);
  97.     println!("fixed2_size: {}", LocalSize(fixed2));
  98.     println!("fixed2_flags: {}", LocalFlags(fixed2));
  99.     if fixed2.is_null() {
  100.       LocalFree(fixed1)
  101.     } else {
  102.       LocalFree(fixed2)
  103.     };
  104.  
  105.     println!("<><><><><><><><><><><><><><><><><><><><><><><><><><><><>");
  106.  
  107.     println!("===LockedMovable, then 0 (fails)");
  108.     let fixed1 = LocalAlloc(LMEM_MOVEABLE, 40);
  109.     let fixed1_ptr = LocalLock(fixed1);
  110.     println!("fixed1_ptr: {:p}", fixed1_ptr);
  111.     println!("fixed1_size: {}", LocalSize(fixed1));
  112.     println!("fixed1_flags: {}", LocalFlags(fixed1));
  113.     let fixed2 = LocalReAlloc(fixed1, 800, 0);
  114.     println!("fixed2_ptr: {:p}", fixed2);
  115.     println!("fixed2_size: {}", LocalSize(fixed2));
  116.     println!("fixed2_flags: {}", LocalFlags(fixed2));
  117.     if fixed2.is_null() {
  118.       LocalFree(fixed1)
  119.     } else {
  120.       LocalFree(fixed2)
  121.     };
  122.  
  123.     println!("===LockedMovable, then Modify (ptr moves)");
  124.     let fixed1 = LocalAlloc(LMEM_MOVEABLE, 40);
  125.     let fixed1_ptr = LocalLock(fixed1);
  126.     println!("fixed1_ptr: {:p}", fixed1_ptr);
  127.     println!("fixed1_size: {}", LocalSize(fixed1));
  128.     println!("fixed1_flags: {}", LocalFlags(fixed1));
  129.     let fixed2 = LocalReAlloc(fixed1, 800, LMEM_MODIFY);
  130.     println!("fixed2_ptr: {:p}", fixed2);
  131.     println!("fixed2_size: {}", LocalSize(fixed2));
  132.     println!("fixed2_flags: {}", LocalFlags(fixed2));
  133.     if fixed2.is_null() {
  134.       LocalFree(fixed1)
  135.     } else {
  136.       LocalFree(fixed2)
  137.     };
  138.  
  139.     println!("===LockedMovable, then Modify+Movable (ptr moves and stays movable)");
  140.     let fixed1 = LocalAlloc(LMEM_MOVEABLE, 40);
  141.     let fixed1_ptr = LocalLock(fixed1);
  142.     println!("fixed1_ptr: {:p}", fixed1_ptr);
  143.     println!("fixed1_size: {}", LocalSize(fixed1));
  144.     println!("fixed1_flags: {}", LocalFlags(fixed1));
  145.     let fixed2 = LocalReAlloc(fixed1, 800, LMEM_MODIFY | LMEM_MOVEABLE);
  146.     println!("fixed2_ptr: {:p}", fixed2);
  147.     println!("fixed2_size: {}", LocalSize(fixed2));
  148.     println!("fixed2_flags: {}", LocalFlags(fixed2));
  149.     if fixed2.is_null() {
  150.       LocalFree(fixed1)
  151.     } else {
  152.       LocalFree(fixed2)
  153.     };
  154.   }
  155. }
  156.  
  157. ==================================================================
  158. ==================================================================
  159. ==================================================================
  160. ==================================================================
  161. ==================================================================
  162.  
  163.  
  164.  
  165. D:\dev\fenestroj>cargo run --example local_demo
  166.    Compiling fenestroj v0.0.4-alpha.0 (D:\dev\fenestroj)
  167.     Finished dev [unoptimized + debuginfo] target(s) in 0.46s
  168.      Running `target\debug\examples\local_demo.exe`
  169. ===Fixed, then 0 (fails to realloc)
  170. fixed1_ptr: 0x22c26baee20
  171. fixed1_size: 40
  172. fixed1_flags: 0
  173. fixed2_ptr: 0x0
  174. fixed2_size: 0
  175. fixed2_flags: 32768
  176. ===Fixed, then Modify (does nothing I guess)
  177. fixed1_ptr: 0x22c26baea60
  178. fixed1_size: 40
  179. fixed1_flags: 0
  180. fixed2_ptr: 0x22c26baea60
  181. fixed2_size: 40
  182. fixed2_flags: 0
  183. ===Fixed, then Modify+Movable (does nothing I guess)
  184. fixed1_ptr: 0x22c26bae910
  185. fixed1_size: 40
  186. fixed1_flags: 0
  187. fixed2_ptr: 0x22c26bae910
  188. fixed2_size: 40
  189. fixed2_flags: 0
  190. <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  191. ===Movable, then 0 (resizes and ptr moves)
  192. fixed1_ptr: 0x22c26ba5ca0
  193. fixed1_size: 40
  194. fixed1_flags: 1
  195. fixed2_ptr: 0x22c26baf070
  196. fixed2_size: 800
  197. fixed2_flags: 1
  198. ===Movable, then Modify (ptr moves, no resize)
  199. fixed1_ptr: 0x22c26ba5ca0
  200. fixed1_size: 40
  201. fixed1_flags: 1
  202. fixed2_ptr: 0x22c26d10008
  203. fixed2_size: 40
  204. fixed2_flags: 0
  205. ===Movable, then Modify+Movable (ptr moves... becomes fixed?)
  206. fixed1_ptr: 0x22c26ba5ca0
  207. fixed1_size: 40
  208. fixed1_flags: 1
  209. fixed2_ptr: 0x22c26d10008
  210. fixed2_size: 40
  211. fixed2_flags: 0
  212. <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  213. ===LockedMovable, then 0 (fails)
  214. fixed1_ptr: 0x22c26ba5ca0
  215. fixed1_size: 40
  216. fixed1_flags: 1
  217. fixed2_ptr: 0x0
  218. fixed2_size: 0
  219. fixed2_flags: 32768
  220. ===LockedMovable, then Modify (ptr moves)
  221. fixed1_ptr: 0x22c26ba5ca0
  222. fixed1_size: 40
  223. fixed1_flags: 1
  224. fixed2_ptr: 0x22c26d10008
  225. fixed2_size: 40
  226. fixed2_flags: 1
  227. ===LockedMovable, then Modify+Movable (ptr moves and stays movable)
  228. fixed1_ptr: 0x22c26ba5ca0
  229. fixed1_size: 40
  230. fixed1_flags: 1
  231. fixed2_ptr: 0x22c26d10008
  232. fixed2_size: 40
  233. fixed2_flags: 1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top