STORAGE.LST 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  1. Listing:
  2. 1 (* Release 3.10 *)
  3. 2 (*-------------------------------------------------------------------------*
  4. 3 * *
  5. 4 * STORAGE.MOD - Dynamic memory allocation *
  6. 5 * *
  7. 6 * COPYRIGHT (C) 1987..1992 Clarion Software Corporation. *
  8. 7 * All Rights Reserved *
  9. 8 * *
  10. 9 *--------------------------------------------------------------------------*)
  11. 10
  12. 11 (*%F _fdata *)
  13. 12 (*# call(seg_name=>null),data(seg_name=>null) *)
  14. 13 (*%E *)
  15. 14 (*%T _fdata *)
  16. 15 (*# call(ds_entry=>null) *)
  17. 16 (*%E *)
  18. 17 (*# module(implementation=>off) *)
  19. 18 (*# check(stack=>off,index=>off,range=>off,overflow=>off,nil_ptr=>off) *)
  20. 19
  21. 20 IMPLEMENTATION MODULE Storage;
  22. 21
  23. 22 (*
  24. 23 N.B. See also MSTORAGE.MOD, which replaces this module in the
  25. 24 DOS multi-language libraries, and in DOS overlay and DLL models
  26. 25 *)
  27. 26
  28. 27 IMPORT SYSTEM, Lib, CoreMain, CoreSig, ModCore;
  29. 28 (*%T _OS2 *)
  30. 29 IMPORT CoreMem, Dos;
  31. 30 (*%T _mthread *)
  32. 31 IMPORT Process;
  33. 32 (*%E *)
  34. 33 (*%E *)
  35. 34
  36. 35 CONST
  37. 36 EndMarker = 0FFFFH;
  38. 37 Align = 4;
  39. 38
  40. 39 (*%F _OS2 *)
  41. 40 VAR
  42. 41 NearHeapSetup : BOOLEAN;
  43. 42 FarHeapSetup : BOOLEAN;
  44. 43 LastBlock : FarHeapRecPtr;
  45. 44 (*%E _OS2 *)
  46. 45
  47. 46 (*%F _OS2 *)
  48. 47 (*# save,call(reg_param=>(ax)) *)
  49. 48 PROCEDURE FarHeapShrink():CARDINAL;
  50. 49 VAR
  51. 50 Curr,Prev,New : FarHeapRecPtr;
  52. 51 BEGIN
  53. 52 Curr := MainHeap;
  54. 53 Prev := FarNIL;
  55. 54 WHILE Curr^.size # EndMarker DO
  56. 55 Prev := Curr;
  57. 56 Curr := Curr^.next;
  58. 57 END; (*WHILE*)
  59. 58 New := [Seg(Prev^) + Prev^.size:0];
  60. 59 LastBlock := Prev;
  61. 60 IF (New = Curr) & (Prev^.size > 4) THEN (* Last free block is last block *)
  62. 61 ModCore.AdjustMem(Seg(Prev^) + 4);
  63. 62 RETURN 0;
  64. 63 END; (*IF*)
  65. 64 RETURN 1;
  66. 65 END FarHeapShrink;
  67. 66 (*# restore *)
  68. 67 (*%E _OS2 *)
  69. 68
  70. 69 (*%F _OS2 *)
  71. 70 (*# save,call(reg_param=>(ax)) *)
  72. 71 PROCEDURE FarHeapRestore;
  73. 72 BEGIN
  74. 73 ModCore.AdjustMem(0);
  75. 74 LastBlock := LastBlock^.next;
  76. 75 LastBlock^.size := EndMarker;
  77. 76 LastBlock^.next := MainHeap;
  78. 77 END FarHeapRestore;
  79. 78 (*# restore *)
  80. 79 (*%E _OS2 *)
  81. 80
  82. 81 (*%F _OS2 *)
  83. 82 (*# save,call(reg_param=>(ax)) *)
  84. 83 PROCEDURE FarHeapFix(Space:CARDINAL);
  85. 84 VAR
  86. 85 Curr,Prev,New : FarHeapRecPtr;
  87. 86 BEGIN
  88. 87 Curr := MainHeap;
  89. 88 Prev := FarNIL;
  90. 89 WHILE Curr^.size # EndMarker DO
  91. 90 Prev := Curr;
  92. 91 Curr := Curr^.next;
  93. 92 END; (*WHILE*)
  94. 93 New := [Seg(Prev^) + Prev^.size:0];
  95. 94 LastBlock := Prev;
  96. 95 IF (New = Curr) & (Prev^.size > Space + 4) THEN (* Last free block is last block *)
  97. 96 Prev^.size := Space;
  98. 97 New := [Seg(Prev^) + Space:0];
  99. 98 Prev^.next := New;
  100. 99 New^.size := EndMarker;
  101. 100 New^.next := MainHeap;
  102. 101 ModCore.AdjustMem(Seg(Prev^)+Space+4);
  103. 102 END; (*IF*)
  104. 103 END FarHeapFix;
  105. 104 (*# restore *)
  106. 105 (*%E _OS2 *)
  107. 106
  108. 107 (*%F _OS2 *)
  109. 108 PROCEDURE InitFarHeap():FarHeapRecPtr;
  110. 109 TYPE
  111. 110 (*# save, data(near_ptr=>off) *)
  112. 111 CPtr = POINTER TO CARDINAL;
  113. 112 (*# restore *)
  114. 113 VAR
  115. 114 P : CPtr;
  116. 115 Size,Start : CARDINAL;
  117. 116 BEGIN
  118. 117 FarHeapSetup := TRUE;
  119. 118 CoreMain._shr_mem := FarHeapShrink;
  120. 119 CoreMain._fix_mem := FarHeapFix;
  121. 120 CoreMain._res_mem := FarHeapRestore;
  122. 121 CoreMain._fmodmemsetup := TRUE;
  123. 122 P := [Lib.PSP:2 CPtr];
  124. 123 Start := ModCore._getheapmem();
  125. 124 Size := P^ - Start;
  126. 125 MainHeap:=FarMakeHeap(Start, Size);
  127. 126 RETURN MainHeap;
  128. 127 END InitFarHeap;
  129. 128 (*%E _OS2 *)
  130. 129
  131. 130 (*%F _OS2 *)
  132. 131 PROCEDURE InitNearHeap(): NearHeapRecPtr;
  133. 132
  134. 133 VAR
  135. 134 Size, Start: CARDINAL;
  136. 135 BEGIN
  137. 136 NearHeapSetup := TRUE;
  138. 137 Size := CoreMain._heap_size;
  139. 138 Start := CARDINAL(ADR(CoreMain._near_heap_start));
  140. 139 IF LONGCARD(Size) + LONGCARD(Start) > 0FFFEH THEN
  141. 140 Size := 0FFFEH - Start;
  142. 141 END;
  143. 142 NearHeap := NearMakeHeap(NearADR(CoreMain._near_heap_start), Size);
  144. 143 RETURN NearHeap;
  145. 144 END InitNearHeap;
  146. 145 (*%E _OS2 *)
  147. 146
  148. 147 (*%F _OS2 *)
  149. 148 PROCEDURE FarMakeHeap(Source:CARDINAL;Size:CARDINAL):FarHeapRecPtr;
  150. 149 VAR
  151. 150 storage,first,last: FarHeapRecPtr;
  152. 151 ie : CARDINAL;
  153. 152 BEGIN
  154. 153 (*%T _mthread *)
  155. 154 ie := SYSTEM.GetFlags();
  156. 155 SYSTEM.DI;
  157. 156 (*%E *)
  158. 157 storage := [Source:0];
  159. 158 first := [Source+1:0];
  160. 159 last := [Source+Size-1:0];
  161. 160 storage^.next := first;
  162. 161 storage^.size := 0;
  163. 162 first^.next := last;
  164. 163 last^.next := storage;
  165. 164 first^.size := Size-2;
  166. 165 last^.size := EndMarker;
  167. 166 (*%T _mthread *)
  168. 167 SYSTEM.SetFlags(ie);;
  169. 168 (*%E *)
  170. 169 RETURN storage;
  171. 170 END FarMakeHeap;
  172. 171 (*%E _OS2 *)
  173. 172
  174. 173 (*%F _OS2 *)
  175. 174 PROCEDURE FarHeapAllocate(Source:FarHeapRecPtr;VAR A:FarADDRESS;Size:CARDINAL);
  176. 175 VAR
  177. 176 res,prev,split : FarHeapRecPtr;
  178. 177 ie : CARDINAL;
  179. 178 BEGIN
  180. 179 (*%T _mthread *)
  181. 180 ie := SYSTEM.GetFlags();
  182. 181 SYSTEM.DI;
  183. 182 (*%E *)
  184. 183 IF ~FarHeapSetup & (Source = MainHeap) THEN
  185. 184 Source := InitFarHeap();
  186. 185 END; (*IF*)
  187. 186 IF Size = 0 THEN
  188. 187 INC(Size);
  189. 188 END; (*IF*)
  190. 189 prev := Source;
  191. 190 WHILE prev^.next^.size < Size DO
  192. 191 prev := prev^.next;
  193. 192 END; (*WHILE *)
  194. 193 res := prev^.next;
  195. 194 IF res^.size = EndMarker THEN (* heap run out of space *)
  196. 195 (*%T _mthread *)
  197. 196 SYSTEM.EI;
  198. 197 (*%E *)
  199. 198 IF Check THEN
  200. 199 Lib.RunTimeError(CoreSig._FatalErrorPos(),90H,'FarHeapAllocate : Out Of Space');
  201. 200 END; (*IF*)
  202. 201 A := FarNIL;
  203. 202 (*%T _mthread *)
  204. 203 SYSTEM.SetFlags(ie);;
  205. 204 (*%E *)
  206. 205 RETURN;
  207. 206 END; (*IF*)
  208. 207 IF res^.size = Size THEN (* block correct size *)
  209. 208 prev^.next := res^.next;
  210. 209 ELSE (* split block, bottom half returned, top half linked to free chain *)
  211. 210 split := [Seg(res^) + Size:0];
  212. 211 prev^.next := split;
  213. 212 split^.next := res^.next;
  214. 213 split^.size := res^.size - Size;
  215. 214 END; (*IF*)
  216. 215 (*%T _mthread *)
  217. 216 SYSTEM.SetFlags(ie);;
  218. 217 (*%E *)
  219. 218 A := FarADR(res^);
  220. 219 END FarHeapAllocate;
  221. 220 (*%E _OS2 *)
  222. 221
  223. 222 (*%F _OS2 *)
  224. 223 PROCEDURE FarHeapAvail(Source: FarHeapRecPtr) : CARDINAL;
  225. 224 (* returns the largest block size available for allocation in paragraphs *)
  226. 225 VAR
  227. 226 size : CARDINAL;
  228. 227 p : FarHeapRecPtr;
  229. 228 ie : CARDINAL;
  230. 229 BEGIN
  231. 230 (*%T _mthread *)
  232. 231 ie := SYSTEM.GetFlags();
  233. 232 SYSTEM.DI;
  234. 233 (*%E *)
  235. 234 IF ~FarHeapSetup & (Source = MainHeap) THEN
  236. 235 Source := InitFarHeap();
  237. 236 END; (*IF*)
  238. 237 p := Source^.next;
  239. 238 size := 0;
  240. 239 WHILE p^.size # EndMarker DO
  241. 240 IF p^.size > size THEN
  242. 241 size := p^.size;
  243. 242 END; (*IF*)
  244. 243 p := p^.next;
  245. 244 END; (*WHILE*)
  246. 245 (*%T _mthread *)
  247. 246 SYSTEM.SetFlags(ie);;
  248. 247 (*%E *)
  249. 248 RETURN size;
  250. 249 END FarHeapAvail;
  251. 250 (*%E _OS2 *)
  252. 251
  253. 252 (*%F _OS2 *)
  254. 253 PROCEDURE FarHeapTotalAvail(Source:FarHeapRecPtr):CARDINAL;
  255. 254 (* Returns the total heap available for allocation in paragraphs *)
  256. 255 VAR
  257. 256 size : CARDINAL;
  258. 257 p : FarHeapRecPtr;
  259. 258 ie : CARDINAL;
  260. 259 BEGIN
  261. 260 (*%T _mthread *)
  262. 261 ie := SYSTEM.GetFlags();
  263. 262 SYSTEM.DI;
  264. 263 (*%E *)
  265. 264 IF ~FarHeapSetup & (Source = MainHeap) THEN
  266. 265 Source := InitFarHeap();
  267. 266 END; (*IF*)
  268. 267 p := Source^.next;
  269. 268 size := 0;
  270. 269 WHILE p^.size # EndMarker DO
  271. 270 INC(size,p^.size);
  272. 271 p := p^.next;
  273. 272 END; (*WHILE*)
  274. 273 (*%T _mthread *)
  275. 274 SYSTEM.SetFlags(ie);;
  276. 275 (*%E *)
  277. 276 RETURN size;
  278. 277 END FarHeapTotalAvail;
  279. 278 (*%E _OS2 *)
  280. 279
  281. 280 (*%F _OS2 *)
  282. 281 PROCEDURE FarHeapDeallocate(Source:FarHeapRecPtr;VAR A:FarADDRESS;Size:CARDINAL);
  283. 282 VAR
  284. 283 target,prev,split : FarHeapRecPtr;
  285. 284 tseg : CARDINAL;
  286. 285 ie : CARDINAL;
  287. 286 BEGIN
  288. 287 IF (Seg(A^) = 0) OR (Ofs(A^) # 0) THEN
  289. 288 Lib.RunTimeError(CoreSig._FatalErrorPos(),91H,'FarHeapDeallocate : Invalid Argument');
  290. 289 END; (*IF*)
  291. 290 (*%T _mthread *)
  292. 291 ie := SYSTEM.GetFlags();
  293. 292 SYSTEM.DI;
  294. 293 (*%E *)
  295. 294 IF Size = 0 THEN
  296. 295 INC(Size);
  297. 296 END; (*IF*)
  298. 297 target := A;
  299. 298 prev := Source;
  300. 299 tseg := Seg(target^);
  301. 300 WHILE Seg(prev^.next^) < tseg DO
  302. 301 prev := prev^.next;
  303. 302 END; (*WHILE*)
  304. 303 IF Seg(prev^) + prev^.size = tseg THEN (* amalgamate with prev *)
  305. 304 prev^.size := prev^.size + Size;
  306. 305 target := prev;
  307. 306 ELSIF Seg(prev^) + prev^.size > tseg THEN (* Heap corrupt *)
  308. 307 (*%T _mthread *)
  309. 308 SYSTEM.EI;
  310. 309 (*%E *)
  311. 310 Lib.RunTimeError(CoreSig._FatalErrorPos(),92H,'FarHeapDeallocate : Heap Corrupt');
  312. 311 ELSE (* link after prev *)
  313. 312 target^.next := prev^.next;
  314. 313 prev^.next := target;
  315. 314 target^.size := Size;
  316. 315 END; (*IF*)
  317. 316 IF (target^.next^.size # EndMarker) & (Seg(target^.next^) = Seg(target^) + target^.size) THEN
  318. 317 (* amalgamate with next block *)
  319. 318 target^.size := target^.size+target^.next^.size;
  320. 319 target^.next := target^.next^.next;
  321. 320 END; (*IF*)
  322. 321 A := SYSTEM.FarNIL;
  323. 322 (*%T _mthread *)
  324. 323 SYSTEM.SetFlags(ie);;
  325. 324 (*%E *)
  326. 325 END FarHeapDeallocate;
  327. 326 (*%E _OS2 *)
  328. 327
  329. 328 (*%F _OS2 *)
  330. 329 PROCEDURE FarHeapChangeAlloc(Source : FarHeapRecPtr; (* source heap *)
  331. 330 A : FarADDRESS; (* block to change *)
  332. 331 OldSize, (* old size of block *)
  333. 332 NewSize : CARDINAL) (* new size of block *)
  334. 333 (* in paragraphs *)
  335. 334 : BOOLEAN; (* if sucessful *)
  336. 335
  337. 336 (* This procedure attempts to change the size of an allocated block
  338. 337 It returns TRUE if succeeded (only expansion can fail)
  339. 338 *)
  340. 339
  341. 340 VAR
  342. 341 target,prev,
  343. 342 split : FarHeapRecPtr;
  344. 343 tseg : CARDINAL;
  345. 344 result : BOOLEAN;
  346. 345 extendsize : CARDINAL;
  347. 346 Res : FarADDRESS;
  348. 347 ie: CARDINAL;
  349. 348 BEGIN
  350. 349 IF (CARDINAL(Seg(A^))=0)OR(CARDINAL(Ofs(A^))<>0) THEN
  351. 350 Lib.RunTimeError(CoreSig._FatalErrorPos(), 93H, 'FarHeapChangeAlloc : Invalid Argument');
  352. 351 END;
  353. 352 IF OldSize = NewSize THEN RETURN TRUE END;
  354. 353 IF OldSize > NewSize THEN
  355. 354 target := [CARDINAL(Seg(A^))+NewSize:0];
  356. 355 FarHeapDeallocate(Source,target,OldSize-NewSize);
  357. 356 RETURN TRUE;
  358. 357 END;
  359. 358 extendsize := NewSize-OldSize;
  360. 359 (*%T _mthread *)
  361. 360 ie := SYSTEM.GetFlags(); SYSTEM.DI;
  362. 361 (*%E *)
  363. 362 target := A;
  364. 363 prev := Source;
  365. 364 tseg := Seg(target^);
  366. 365 WHILE CARDINAL(Seg(prev^.next^)) < tseg DO
  367. 366 prev := prev^.next;
  368. 367 END;
  369. 368 IF (prev^.next^.size <> EndMarker) AND
  370. 369 (CARDINAL(Seg(prev^.next^)) = CARDINAL(Seg(target^))+OldSize) AND
  371. 370 (extendsize <= prev^.next^.size) THEN
  372. 371 IF (extendsize = prev^.next^.size) THEN
  373. 372 prev^.next := prev^.next^.next
  374. 373 ELSE
  375. 374 split := [CARDINAL(Seg(target^))+NewSize:0];
  376. 375 split^.next := prev^.next^.next;
  377. 376 split^.size := prev^.next^.size - extendsize;
  378. 377 prev^.next := split;
  379. 378 END;
  380. 379 result := TRUE;
  381. 380 ELSE
  382. 381 result := FALSE;
  383. 382 END;
  384. 383 (*%T _mthread *)
  385. 384 SYSTEM.SetFlags(ie);;
  386. 385 (*%E *)
  387. 386 RETURN result;
  388. 387 END FarHeapChangeAlloc;
  389. 388 (*%E _OS2 *)
  390. 389
  391. 390 (*%F _OS2 *)
  392. 391 PROCEDURE FarHeapChangeSize(Source:FarHeapRecPtr;VAR A:FarADDRESS;OldSize,NewSize:CARDINAL);
  393. 392 (* This procedure will change the size of an allocated block avoiding*)
  394. 393 (* any copy of data if possible. Calls HeapChangeAlloc. *)
  395. 394 VAR
  396. 395 na : FarADDRESS;
  397. 396 BEGIN
  398. 397 IF ~FarHeapChangeAlloc(Source,A,OldSize,NewSize) THEN
  399. 398 FarHeapAllocate(Source,na,NewSize);
  400. 399 IF na # FarNIL THEN
  401. 400 Lib.FarWordMove(A,na,OldSize * 8);
  402. 401 FarHeapDeallocate(Source,A,OldSize);
  403. 402 END; (*IF*)
  404. 403 A := na;
  405. 404 END; (*IF*)
  406. 405 END FarHeapChangeSize;
  407. 406 (*%E _OS2 *)
  408. 407
  409. 408 (*%F _OS2 *)
  410. 409 PROCEDURE FarAllocate(VAR a:FarADDRESS;size:CARDINAL);
  411. 410 VAR
  412. 411 ps : CARDINAL;
  413. 412 BEGIN
  414. 413 IF size > 0FFF0H THEN
  415. 414 ps := 1000H;
  416. 415 ELSE
  417. 416 ps := (size + 15) DIV 16;
  418. 417 END; (*IF*)
  419. 418 FarHeapAllocate(MainHeap,a,ps);
  420. 419 IF ClearOnAllocate & (a # FarNIL) THEN
  421. 420 Lib.FarWordFill(a,ps*8,0);
  422. 421 END; (*IF*)
  423. 422 END FarAllocate;
  424. 423 (*%E _OS2 *)
  425. 424
  426. 425 (*%F _OS2 *)
  427. 426 PROCEDURE FarDeallocate(VAR a:FarADDRESS;size:CARDINAL);
  428. 427 VAR
  429. 428 ps : CARDINAL;
  430. 429 BEGIN
  431. 430 IF size > 0FFF0H THEN
  432. 431 ps := 1000H;
  433. 432 ELSE
  434. 433 ps := (size + 15) DIV 16;
  435. 434 END; (*IF*)
  436. 435 FarHeapDeallocate(MainHeap,a,ps);
  437. 436 END FarDeallocate;
  438. 437 (*%E _OS2 *)
  439. 438
  440. 439 (*%F _OS2 *)
  441. 440 PROCEDURE FarAvailable(size:CARDINAL):BOOLEAN;
  442. 441 VAR
  443. 442 ps : CARDINAL;
  444. 443 BEGIN
  445. 444 IF size = 0 THEN
  446. 445 ps := 1;
  447. 446 ELSIF size > 0FFF0H THEN
  448. 447 ps := 1000H;
  449. 448 ELSE
  450. 449 ps := (size + 15) DIV 16;
  451. 450 END; (*IF*)
  452. 451 RETURN ps <= FarHeapAvail(MainHeap);
  453. 452 END FarAvailable;
  454. 453 (*%E _OS2 *)
  455. 454
  456. 455 (*%T _OS2 *)
  457. 456 PROCEDURE FarMakeHeap( Source : CARDINAL; (* base segment of heap *)
  458. 457 Size : CARDINAL (* size in paragraphs *)
  459. 458 ) : FarHeapRecPtr;
  460. ***** ^ undeclared identifier
  461. 459 BEGIN
  462. 460 Lib.RunTimeError(CoreSig._FatalErrorPos(), 099H, 'FarMakeHeap : Not Supported Under OS2 *)');
  463. ***** ^ not supported yet
  464. ***** ^ not supported yet
  465. ***** ^ not supported yet
  466. ***** ^ not supported yet
  467. ***** ^ not supported yet
  468. ***** ^ not supported yet
  469. 461 RETURN FarNIL;
  470. ***** ^ undeclared identifier
  471. 462 END FarMakeHeap;
  472. ***** ^ not supported yet
  473. 463
  474. 464
  475. 465 PROCEDURE FarHeapAllocate(Source : FarHeapRecPtr; (* source heap *)
  476. ***** ^ undeclared identifier
  477. 466 VAR A : FarADDRESS; (* result *)
  478. ***** ^ undeclared identifier
  479. 467 Size : CARDINAL); (* request size in paragraphs *)
  480. 468
  481. 469 BEGIN
  482. 470 Lib.RunTimeError(CoreSig._FatalErrorPos(), 099H, 'FarHeapAllocate : Not Supported Under OS2 *)');
  483. ***** ^ not supported yet
  484. ***** ^ not supported yet
  485. ***** ^ not supported yet
  486. ***** ^ not supported yet
  487. ***** ^ not supported yet
  488. ***** ^ not supported yet
  489. 471 END FarHeapAllocate;
  490. ***** ^ not supported yet
  491. 472
  492. 473
  493. 474 PROCEDURE FarHeapAvail(Source: FarHeapRecPtr) : CARDINAL;
  494. ***** ^ undeclared identifier
  495. 475 (* returns the largest block size available for allocation in paragraphs *)
  496. 476
  497. 477 BEGIN
  498. 478 Lib.RunTimeError(CoreSig._FatalErrorPos(), 099H, 'FarHeapAvail : Not Supported Under OS2 *)');
  499. ***** ^ not supported yet
  500. ***** ^ not supported yet
  501. ***** ^ not supported yet
  502. ***** ^ not supported yet
  503. ***** ^ not supported yet
  504. ***** ^ not supported yet
  505. 479 RETURN 0;
  506. 480 END FarHeapAvail;
  507. ***** ^ not supported yet
  508. 481
  509. 482
  510. 483 PROCEDURE FarHeapTotalAvail(Source: FarHeapRecPtr) : CARDINAL;
  511. ***** ^ undeclared identifier
  512. 484
  513. 485 BEGIN
  514. 486 Lib.RunTimeError(CoreSig._FatalErrorPos(), 099H, 'FarHeapTotalAvail : Not Supported Under OS2 *)');
  515. ***** ^ not supported yet
  516. ***** ^ not supported yet
  517. ***** ^ not supported yet
  518. ***** ^ not supported yet
  519. ***** ^ not supported yet
  520. ***** ^ not supported yet
  521. 487 RETURN 0;
  522. 488 END FarHeapTotalAvail;
  523. ***** ^ not supported yet
  524. 489
  525. 490
  526. 491
  527. 492 PROCEDURE FarHeapDeallocate(Source : FarHeapRecPtr; (* source heap *)
  528. ***** ^ undeclared identifier
  529. 493 VAR A: FarADDRESS;
  530. ***** ^ undeclared identifier
  531. 494 Size : CARDINAL ); (* size of block
  532. 495 in paragraphs *)
  533. 496 BEGIN
  534. 497 Lib.RunTimeError(CoreSig._FatalErrorPos(), 099H, 'FarHeapDeallocate: Not Supported Under OS2 *)');
  535. ***** ^ not supported yet
  536. ***** ^ not supported yet
  537. ***** ^ not supported yet
  538. ***** ^ not supported yet
  539. ***** ^ not supported yet
  540. ***** ^ not supported yet
  541. 498 END FarHeapDeallocate;
  542. ***** ^ not supported yet
  543. 499
  544. 500
  545. 501 PROCEDURE FarHeapChangeAlloc(Source : FarHeapRecPtr; (* source heap *)
  546. ***** ^ undeclared identifier
  547. 502 A : FarADDRESS; (* block to change *)
  548. ***** ^ undeclared identifier
  549. 503 OldSize, (* old size of block *)
  550. 504 NewSize : CARDINAL) (* new size of block *)
  551. 505 (* in paragraphs *)
  552. 506 : BOOLEAN; (* if sucessful *)
  553. 507
  554. 508 (* This procedure attempts to change the size of an allocated block
  555. 509 It returns TRUE if succeeded (only expansion can fail)
  556. 510 *)
  557. 511
  558. 512 BEGIN
  559. 513 Lib.RunTimeError(CoreSig._FatalErrorPos(), 099H, 'FarHeapChangeAlloc: Not Supported Under OS2 *)');
  560. ***** ^ not supported yet
  561. ***** ^ not supported yet
  562. ***** ^ not supported yet
  563. ***** ^ not supported yet
  564. ***** ^ not supported yet
  565. ***** ^ not supported yet
  566. 514 RETURN FALSE;
  567. 515 END FarHeapChangeAlloc;
  568. ***** ^ not supported yet
  569. 516
  570. 517
  571. 518
  572. 519 PROCEDURE FarHeapChangeSize(Source : FarHeapRecPtr; (* source heap *)
  573. ***** ^ undeclared identifier
  574. 520 VAR A : FarADDRESS; (* block to change *)
  575. ***** ^ undeclared identifier
  576. 521 OldSize, (* old size of block *)
  577. 522 NewSize : CARDINAL ); (* new size of block
  578. 523 in paragraphs *)
  579. 524
  580. 525 (*
  581. 526 This procedure will change the size of an allocated block
  582. 527 avoiding any copy of data if possible
  583. 528 calls HeapChangeAlloc
  584. 529 *)
  585. 530
  586. 531 BEGIN
  587. 532 Lib.RunTimeError(CoreSig._FatalErrorPos(), 099H, 'FarHeapChangeSize: Not Supported Under OS2 *)');
  588. ***** ^ not supported yet
  589. ***** ^ not supported yet
  590. ***** ^ not supported yet
  591. ***** ^ not supported yet
  592. ***** ^ not supported yet
  593. ***** ^ not supported yet
  594. 533 END FarHeapChangeSize;
  595. ***** ^ not supported yet
  596. 534
  597. 535
  598. 536 PROCEDURE FarAllocate(VAR a: FarADDRESS; size: CARDINAL);
  599. ***** ^ undeclared identifier
  600. 537
  601. 538 VAR
  602. 539 Res: FarADDRESS;
  603. ***** ^ undeclared identifier
  604. 540 BEGIN
  605. 541 IF size = 0 THEN size := 2 END;
  606. 542 IF ClearOnAllocate THEN
  607. ***** ^ undeclared identifier
  608. 543 Res := CoreMem._fcalloc(1, size);
  609. ***** ^ not supported yet
  610. ***** ^ not supported yet
  611. ***** ^ not supported yet
  612. ***** ^ not supported yet
  613. 544 ELSE
  614. 545 Res := CoreMem._fmalloc(size);
  615. ***** ^ not supported yet
  616. ***** ^ not supported yet
  617. ***** ^ not supported yet
  618. ***** ^ not supported yet
  619. 546 END;
  620. 547 IF Res = FarNIL THEN
  621. ***** ^ not supported yet
  622. ***** ^ undeclared identifier
  623. 548 IF Check THEN
  624. ***** ^ undeclared identifier
  625. 549 Lib.RunTimeError(CoreSig._FatalErrorPos(), 94H, 'FarAllocate: Out Of Memory');
  626. ***** ^ not supported yet
  627. ***** ^ not supported yet
  628. ***** ^ not supported yet
  629. ***** ^ not supported yet
  630. ***** ^ not supported yet
  631. ***** ^ not supported yet
  632. 550 END;
  633. 551 END;
  634. 552 a := Res;
  635. ***** ^ not supported yet
  636. ***** ^ not supported yet
  637. 553 END FarAllocate;
  638. ***** ^ not supported yet
  639. 554
  640. 555
  641. 556 PROCEDURE FarDeallocate(VAR a: FarADDRESS; size: CARDINAL);
  642. ***** ^ undeclared identifier
  643. 557
  644. 558 BEGIN
  645. 559 CoreMem._ffree(a);
  646. ***** ^ not supported yet
  647. ***** ^ not supported yet
  648. ***** ^ not supported yet
  649. 560 a:= SYSTEM.FarNIL;
  650. ***** ^ not supported yet
  651. ***** ^ not supported yet
  652. ***** ^ not supported yet
  653. 561 END FarDeallocate;
  654. ***** ^ not supported yet
  655. 562
  656. 563
  657. 564 PROCEDURE FarAvailable(size: CARDINAL) : BOOLEAN;
  658. 565
  659. 566 BEGIN
  660. 567 RETURN TRUE;
  661. 568 END FarAvailable;
  662. ***** ^ not supported yet
  663. 569 (*%E *)
  664. 570
  665. 571 PROCEDURE NearMakeHeap(Source: NearADDRESS; Size: CARDINAL): NearHeapRecPtr;
  666. ***** ^ undeclared identifier
  667. ***** ^ undeclared identifier
  668. 572 (* ========== *)
  669. 573 VAR Storage, FirstFree: NearHeapRecPtr;
  670. ***** ^ undeclared identifier
  671. 574 BEGIN
  672. 575 Size := (Size DIV Align) * Align;
  673. 576 IF Size < Align*3 THEN
  674. 577 Lib.RunTimeError(CoreSig._FatalErrorPos(), 95H, 'NearMakeHeap: Size Too Small');
  675. ***** ^ not supported yet
  676. ***** ^ not supported yet
  677. ***** ^ not supported yet
  678. ***** ^ not supported yet
  679. ***** ^ not supported yet
  680. ***** ^ not supported yet
  681. 578 END;
  682. 579 IF Source = SYSTEM.NearNIL THEN
  683. ***** ^ not supported yet
  684. ***** ^ not supported yet
  685. ***** ^ not supported yet
  686. 580 Lib.RunTimeError(CoreSig._FatalErrorPos(), 89H, 'NearMakeHeap: Invalid Argument');
  687. ***** ^ not supported yet
  688. ***** ^ not supported yet
  689. ***** ^ not supported yet
  690. ***** ^ not supported yet
  691. ***** ^ not supported yet
  692. ***** ^ not supported yet
  693. 581 END;
  694. 582 Storage := NearHeapRecPtr(Source);
  695. ***** ^ not supported yet
  696. ***** ^ undeclared identifier
  697. ***** ^ not supported yet
  698. 583 FirstFree := NearHeapRecPtr(CARDINAL(Source)+CARDINAL(Align));
  699. ***** ^ not supported yet
  700. ***** ^ undeclared identifier
  701. ***** ^ not supported yet
  702. ***** ^ not supported yet
  703. 584 Storage^.size := Size;
  704. ***** ^ not supported yet
  705. ***** ^ not supported yet
  706. 585 Storage^.next := FirstFree;
  707. ***** ^ not supported yet
  708. ***** ^ not supported yet
  709. ***** ^ not supported yet
  710. 586 FirstFree^.size := Size - Align;
  711. ***** ^ not supported yet
  712. ***** ^ not supported yet
  713. 587 FirstFree^.next := SYSTEM.NearNIL;
  714. ***** ^ not supported yet
  715. ***** ^ not supported yet
  716. ***** ^ not supported yet
  717. ***** ^ not supported yet
  718. 588 RETURN Storage;
  719. ***** ^ not supported yet
  720. 589 END NearMakeHeap;
  721. ***** ^ not supported yet
  722. 590
  723. 591 PROCEDURE NearHeapAllocate(Source: NearHeapRecPtr; VAR A: NearADDRESS; Size: CARDINAL);
  724. ***** ^ undeclared identifier
  725. ***** ^ undeclared identifier
  726. 592 (* ======== *)
  727. 593 VAR
  728. 594 Base, Free, New: NearHeapRecPtr;
  729. ***** ^ undeclared identifier
  730. 595 (*%T _OS2 *)
  731. 596 Res: NearADDRESS;
  732. ***** ^ undeclared identifier
  733. 597 (*%E *)
  734. 598 BEGIN
  735. 599 (*%F _OS2 *)
  736. 600 (*%F _DLL *)
  737. 601 IF (NOT NearHeapSetup) AND (Source = NearHeap) THEN
  738. 602 Source := InitNearHeap();
  739. 603 END;
  740. 604 (*%E *)
  741. 605 (*%E *)
  742. 606 (*%T _OS2 *)
  743. 607 IF Source = NearHeap THEN
  744. ***** ^ not supported yet
  745. ***** ^ undeclared identifier
  746. 608 IF Size = 0 THEN Size := 2 END;
  747. 609 IF ClearOnAllocate THEN
  748. ***** ^ undeclared identifier
  749. 610 Res := CoreMem._ncalloc(1, Size);
  750. ***** ^ not supported yet
  751. ***** ^ not supported yet
  752. ***** ^ not supported yet
  753. ***** ^ not supported yet
  754. 611 ELSE
  755. 612 Res := CoreMem._nmalloc(Size);
  756. ***** ^ not supported yet
  757. ***** ^ not supported yet
  758. ***** ^ not supported yet
  759. ***** ^ not supported yet
  760. 613 END;
  761. 614 IF Res = NearNIL THEN
  762. ***** ^ not supported yet
  763. ***** ^ undeclared identifier
  764. 615 IF Check THEN
  765. ***** ^ undeclared identifier
  766. 616 Lib.RunTimeError(CoreSig._FatalErrorPos(), 98H, 'NearAllocate: Out Of Memory');
  767. ***** ^ not supported yet
  768. ***** ^ not supported yet
  769. ***** ^ not supported yet
  770. ***** ^ not supported yet
  771. ***** ^ not supported yet
  772. ***** ^ not supported yet
  773. 617 END;
  774. 618 END;
  775. 619 A := Res;
  776. ***** ^ not supported yet
  777. ***** ^ not supported yet
  778. 620 RETURN;
  779. 621 END;
  780. 622 (*%E *)
  781. 623 IF Source = SYSTEM.NearNIL THEN
  782. ***** ^ not supported yet
  783. ***** ^ not supported yet
  784. ***** ^ not supported yet
  785. 624 Lib.RunTimeError(CoreSig._FatalErrorPos(), 8AH, 'NearHeapAllocate: Invalid Argument');
  786. ***** ^ not supported yet
  787. ***** ^ not supported yet
  788. ***** ^ not supported yet
  789. ***** ^ not supported yet
  790. ***** ^ not supported yet
  791. ***** ^ not supported yet
  792. 625 END;
  793. 626 IF Size < Align THEN
  794. 627 Size := Align;
  795. 628 ELSE
  796. 629 Size := ( (Size+Align-1) DIV Align) * Align;
  797. 630 IF Size = 0 THEN
  798. 631 Size:=MAX(CARDINAL);
  799. ***** ^ undeclared identifier
  800. ***** ^ not supported yet
  801. 632 END;
  802. 633 END;
  803. 634 Base := Source;
  804. ***** ^ not supported yet
  805. ***** ^ not supported yet
  806. 635 LOOP
  807. 636 Free := Base^.next;
  808. ***** ^ not supported yet
  809. ***** ^ not supported yet
  810. ***** ^ not supported yet
  811. 637 IF Free = SYSTEM.NearNIL THEN
  812. ***** ^ not supported yet
  813. ***** ^ not supported yet
  814. ***** ^ not supported yet
  815. 638 IF Check THEN
  816. ***** ^ undeclared identifier
  817. 639 Lib.RunTimeError(CoreSig._FatalErrorPos(), 96H, 'NearHeapAllocate: Out Of Memory');
  818. ***** ^ not supported yet
  819. ***** ^ not supported yet
  820. ***** ^ not supported yet
  821. ***** ^ not supported yet
  822. ***** ^ not supported yet
  823. ***** ^ not supported yet
  824. 640 ELSE
  825. 641 A := SYSTEM.NearNIL;
  826. ***** ^ not supported yet
  827. ***** ^ not supported yet
  828. ***** ^ not supported yet
  829. 642 RETURN;
  830. 643 END;
  831. 644 ELSIF Free^.size >= Size THEN
  832. ***** ^ not supported yet
  833. ***** ^ not supported yet
  834. 645 EXIT;
  835. 646 END;
  836. 647 Base := Free;
  837. ***** ^ not supported yet
  838. ***** ^ not supported yet
  839. 648 END;
  840. 649 IF Free^.size = Size THEN
  841. ***** ^ not supported yet
  842. ***** ^ not supported yet
  843. 650 Base^.next := Free^.next;
  844. ***** ^ not supported yet
  845. ***** ^ not supported yet
  846. ***** ^ not supported yet
  847. ***** ^ not supported yet
  848. 651 ELSE
  849. 652 New := NearHeapRecPtr(CARDINAL(Free)+Size);
  850. ***** ^ not supported yet
  851. ***** ^ undeclared identifier
  852. ***** ^ not supported yet
  853. ***** ^ not supported yet
  854. 653 Base^.next := New;
  855. ***** ^ not supported yet
  856. ***** ^ not supported yet
  857. ***** ^ not supported yet
  858. 654 New^.size := Free^.size - Size;
  859. ***** ^ not supported yet
  860. ***** ^ not supported yet
  861. ***** ^ not supported yet
  862. ***** ^ not supported yet
  863. 655 New^.next := Free^.next;
  864. ***** ^ not supported yet
  865. ***** ^ not supported yet
  866. ***** ^ not supported yet
  867. ***** ^ not supported yet
  868. 656 END;
  869. 657 IF ClearOnAllocate THEN
  870. ***** ^ undeclared identifier
  871. 658 Lib.WordFill ( ADR(Free^) , Size DIV 2 , 0 );
  872. ***** ^ not supported yet
  873. ***** ^ not supported yet
  874. ***** ^ undeclared identifier
  875. ***** ^ not supported yet
  876. ***** ^ not supported yet
  877. 659 END;
  878. 660 A := NearADDRESS(Free);
  879. ***** ^ not supported yet
  880. ***** ^ undeclared identifier
  881. ***** ^ not supported yet
  882. 661 END NearHeapAllocate;
  883. ***** ^ not supported yet
  884. 662
  885. 663 PROCEDURE NearHeapDeallocate(Source: NearHeapRecPtr; VAR A: NearADDRESS; Size: CARDINAL );
  886. ***** ^ undeclared identifier
  887. ***** ^ undeclared identifier
  888. 664
  889. 665 VAR
  890. 666 Curr, Base, Free: NearHeapRecPtr;
  891. ***** ^ undeclared identifier
  892. 667
  893. 668 BEGIN
  894. 669 IF (Source = SYSTEM.NearNIL) OR (A = SYSTEM.NearNIL) THEN
  895. ***** ^ not supported yet
  896. ***** ^ not supported yet
  897. ***** ^ not supported yet
  898. ***** ^ not supported yet
  899. ***** ^ not supported yet
  900. ***** ^ not supported yet
  901. 670 Lib.RunTimeError(CoreSig._FatalErrorPos(), 8BH, 'NearHeapDeallocate: Invalid Argument');
  902. ***** ^ not supported yet
  903. ***** ^ not supported yet
  904. ***** ^ not supported yet
  905. ***** ^ not supported yet
  906. ***** ^ not supported yet
  907. ***** ^ not supported yet
  908. 671 END;
  909. 672 (*%T _OS2 *)
  910. 673 IF Source = NearHeap THEN
  911. ***** ^ not supported yet
  912. ***** ^ undeclared identifier
  913. 674 CoreMem._nfree(A);
  914. ***** ^ not supported yet
  915. ***** ^ not supported yet
  916. ***** ^ not supported yet
  917. 675 A:= NearADDRESS(NIL);
  918. ***** ^ not supported yet
  919. ***** ^ undeclared identifier
  920. ***** ^ not supported yet
  921. 676 RETURN;
  922. 677 END;
  923. 678 (*%E *)
  924. 679 IF Size < Align THEN
  925. 680 Size := Align;
  926. 681 ELSE
  927. 682 Size := ( (Size+Align-1) DIV Align) * Align;
  928. 683 IF Size = 0 THEN
  929. 684 Size:=MAX(CARDINAL);
  930. ***** ^ undeclared identifier
  931. ***** ^ not supported yet
  932. 685 END;
  933. 686 END;
  934. 687 Curr := NearHeapRecPtr(A);
  935. ***** ^ not supported yet
  936. ***** ^ undeclared identifier
  937. ***** ^ not supported yet
  938. 688 A := SYSTEM.NearNIL;
  939. ***** ^ not supported yet
  940. ***** ^ not supported yet
  941. ***** ^ not supported yet
  942. 689 Base:=Source;
  943. ***** ^ not supported yet
  944. ***** ^ not supported yet
  945. 690 LOOP
  946. 691 Free := Base^.next;
  947. ***** ^ not supported yet
  948. ***** ^ not supported yet
  949. ***** ^ not supported yet
  950. 692 IF (Free = SYSTEM.NearNIL) OR (CARDINAL(Curr) < CARDINAL(Free)) THEN EXIT; END;
  951. ***** ^ not supported yet
  952. ***** ^ not supported yet
  953. ***** ^ not supported yet
  954. ***** ^ not supported yet
  955. ***** ^ not supported yet
  956. 693 Base := Free;
  957. ***** ^ not supported yet
  958. ***** ^ not supported yet
  959. 694 END;
  960. 695 IF CARDINAL(Base) + Base^.size = CARDINAL(Curr) THEN
  961. ***** ^ not supported yet
  962. ***** ^ not supported yet
  963. ***** ^ not supported yet
  964. ***** ^ not supported yet
  965. 696 INC ( Base^.size , Size );
  966. ***** ^ undeclared identifier
  967. ***** ^ not supported yet
  968. ***** ^ not supported yet
  969. ***** ^ not supported yet
  970. 697 Curr := Base;
  971. ***** ^ not supported yet
  972. ***** ^ not supported yet
  973. 698 ELSE
  974. 699 Base^.next := Curr;
  975. ***** ^ not supported yet
  976. ***** ^ not supported yet
  977. ***** ^ not supported yet
  978. 700 Curr^.next := Free;
  979. ***** ^ not supported yet
  980. ***** ^ not supported yet
  981. ***** ^ not supported yet
  982. 701 Curr^.size := Size;
  983. ***** ^ not supported yet
  984. ***** ^ not supported yet
  985. 702 END;
  986. 703 IF (Free # SYSTEM.NearNIL) AND (CARDINAL(Curr) + Curr^.size = CARDINAL(Free)) THEN
  987. ***** ^ not supported yet
  988. ***** ^ not supported yet
  989. ***** ^ not supported yet
  990. ***** ^ not supported yet
  991. ***** ^ not supported yet
  992. ***** ^ not supported yet
  993. ***** ^ not supported yet
  994. 704 INC ( Curr^.size, Free^.size);
  995. ***** ^ undeclared identifier
  996. ***** ^ not supported yet
  997. ***** ^ not supported yet
  998. ***** ^ not supported yet
  999. ***** ^ not supported yet
  1000. 705 Curr^.next := Free^.next;
  1001. ***** ^ not supported yet
  1002. ***** ^ not supported yet
  1003. ***** ^ not supported yet
  1004. ***** ^ not supported yet
  1005. 706 END;
  1006. 707 END NearHeapDeallocate;
  1007. ***** ^ not supported yet
  1008. 708
  1009. 709 PROCEDURE NearHeapAvail(Source: NearHeapRecPtr): CARDINAL;
  1010. ***** ^ undeclared identifier
  1011. 710
  1012. 711 VAR
  1013. 712 Curr: NearHeapRecPtr;
  1014. ***** ^ undeclared identifier
  1015. 713 Size, av: CARDINAL;
  1016. 714 BEGIN
  1017. 715 (*%F _OS2 *)
  1018. 716 (*%F _DLL *)
  1019. 717 IF (NOT NearHeapSetup) AND (Source = NearHeap) THEN
  1020. 718 Source := InitNearHeap();
  1021. 719 END;
  1022. 720 (*%E *)
  1023. 721 (*%E *)
  1024. 722 (*%T _OS2 *)
  1025. 723 IF Source = NearHeap THEN
  1026. ***** ^ not supported yet
  1027. ***** ^ undeclared identifier
  1028. 724 av := CoreMem._memmax();
  1029. ***** ^ not supported yet
  1030. ***** ^ not supported yet
  1031. ***** ^ not supported yet
  1032. 725 IF av <= 4 THEN
  1033. 726 av := 0;
  1034. 727 ELSE
  1035. 728 DEC(av, 4);
  1036. ***** ^ undeclared identifier
  1037. ***** ^ not supported yet
  1038. 729 END;
  1039. 730 RETURN av;
  1040. 731 END;
  1041. 732 (*%E *)
  1042. 733 IF Source = SYSTEM.NearNIL THEN
  1043. ***** ^ not supported yet
  1044. ***** ^ not supported yet
  1045. ***** ^ not supported yet
  1046. 734 Lib.RunTimeError(CoreSig._FatalErrorPos(), 8CH, 'NearHeapAvail: Invalid Argument');
  1047. ***** ^ not supported yet
  1048. ***** ^ not supported yet
  1049. ***** ^ not supported yet
  1050. ***** ^ not supported yet
  1051. ***** ^ not supported yet
  1052. ***** ^ not supported yet
  1053. 735 END;
  1054. 736 Curr := Source^.next;
  1055. ***** ^ not supported yet
  1056. ***** ^ not supported yet
  1057. ***** ^ not supported yet
  1058. 737 Size := 0;
  1059. 738 WHILE Curr # SYSTEM.NearNIL DO
  1060. ***** ^ not supported yet
  1061. ***** ^ not supported yet
  1062. ***** ^ not supported yet
  1063. 739 IF Size < Curr^.size THEN
  1064. ***** ^ not supported yet
  1065. ***** ^ not supported yet
  1066. 740 Size := Curr^.size;
  1067. ***** ^ not supported yet
  1068. ***** ^ not supported yet
  1069. 741 END;
  1070. 742 Curr := Curr^.next;
  1071. ***** ^ not supported yet
  1072. ***** ^ not supported yet
  1073. ***** ^ not supported yet
  1074. 743 END;
  1075. 744 RETURN Size;
  1076. 745 END NearHeapAvail;
  1077. ***** ^ not supported yet
  1078. 746
  1079. 747
  1080. 748 PROCEDURE NearHeapTotalAvail(Source: NearHeapRecPtr): CARDINAL;
  1081. ***** ^ undeclared identifier
  1082. 749
  1083. 750 VAR
  1084. 751 Curr: NearHeapRecPtr;
  1085. ***** ^ undeclared identifier
  1086. 752 Size: CARDINAL;
  1087. 753 BEGIN
  1088. 754 (*%F _OS2 *)
  1089. 755 (*%F _DLL *)
  1090. 756 IF (NOT NearHeapSetup) AND (Source = NearHeap) THEN
  1091. 757 Source := InitNearHeap();
  1092. 758 END;
  1093. 759 (*%E *)
  1094. 760 (*%E *)
  1095. 761 (*%T _OS2 *)
  1096. 762 IF Source = NearHeap THEN
  1097. ***** ^ not supported yet
  1098. ***** ^ undeclared identifier
  1099. 763 RETURN CoreMem.nearcoreleft();
  1100. ***** ^ not supported yet
  1101. ***** ^ not supported yet
  1102. ***** ^ not supported yet
  1103. 764 END;
  1104. 765 (*%E *)
  1105. 766 IF Source = SYSTEM.NearNIL THEN
  1106. ***** ^ not supported yet
  1107. ***** ^ not supported yet
  1108. ***** ^ not supported yet
  1109. 767 Lib.RunTimeError(CoreSig._FatalErrorPos(), 8DH, 'NearHeapTotalAvail: Invalid Argument');
  1110. ***** ^ not supported yet
  1111. ***** ^ not supported yet
  1112. ***** ^ not supported yet
  1113. ***** ^ not supported yet
  1114. ***** ^ not supported yet
  1115. ***** ^ not supported yet
  1116. 768 END;
  1117. 769 Curr := Source^.next;
  1118. ***** ^ not supported yet
  1119. ***** ^ not supported yet
  1120. ***** ^ not supported yet
  1121. 770 Size := 0;
  1122. 771 WHILE Curr # SYSTEM.NearNIL DO
  1123. ***** ^ not supported yet
  1124. ***** ^ not supported yet
  1125. ***** ^ not supported yet
  1126. 772 INC ( Size , Curr^.size );
  1127. ***** ^ undeclared identifier
  1128. ***** ^ not supported yet
  1129. ***** ^ not supported yet
  1130. 773 Curr := Curr^.next;
  1131. ***** ^ not supported yet
  1132. ***** ^ not supported yet
  1133. ***** ^ not supported yet
  1134. 774 END;
  1135. 775 RETURN Size;
  1136. 776 END NearHeapTotalAvail;
  1137. ***** ^ not supported yet
  1138. 777
  1139. 778
  1140. 779 PROCEDURE Merge(LowRec, HighRec: NearHeapRecPtr);
  1141. ***** ^ undeclared identifier
  1142. 780
  1143. 781 BEGIN
  1144. 782 IF (LowRec = SYSTEM.NearNIL) AND (HighRec = SYSTEM.NearNIL) AND
  1145. ***** ^ not supported yet
  1146. ***** ^ not supported yet
  1147. ***** ^ not supported yet
  1148. ***** ^ not supported yet
  1149. ***** ^ not supported yet
  1150. ***** ^ not supported yet
  1151. 783 (NearHeapRecPtr(CARDINAL(LowRec)+LowRec^.size) = HighRec) THEN
  1152. ***** ^ undeclared identifier
  1153. ***** ^ not supported yet
  1154. ***** ^ not supported yet
  1155. ***** ^ not supported yet
  1156. ***** ^ not supported yet
  1157. 784 LowRec^.next:=HighRec^.next;
  1158. ***** ^ not supported yet
  1159. ***** ^ not supported yet
  1160. ***** ^ not supported yet
  1161. ***** ^ not supported yet
  1162. 785 INC(LowRec^.size, HighRec^.size);
  1163. ***** ^ undeclared identifier
  1164. ***** ^ not supported yet
  1165. ***** ^ not supported yet
  1166. ***** ^ not supported yet
  1167. ***** ^ not supported yet
  1168. 786 END;
  1169. 787 END Merge;
  1170. ***** ^ not supported yet
  1171. 788
  1172. 789 PROCEDURE NearHeapChangeSize(Source: NearHeapRecPtr; VAR A: NearADDRESS;
  1173. ***** ^ undeclared identifier
  1174. ***** ^ undeclared identifier
  1175. 790 OldSize, NewSize : CARDINAL);
  1176. 791
  1177. 792 VAR
  1178. 793 OldA: NearADDRESS;
  1179. ***** ^ undeclared identifier
  1180. 794 BEGIN
  1181. 795 IF (Source = SYSTEM.NearNIL) OR (A = SYSTEM.NearNIL) THEN
  1182. ***** ^ not supported yet
  1183. ***** ^ not supported yet
  1184. ***** ^ not supported yet
  1185. ***** ^ not supported yet
  1186. ***** ^ not supported yet
  1187. ***** ^ not supported yet
  1188. 796 Lib.RunTimeError(CoreSig._FatalErrorPos(), 8EH, 'NearHeapChangeSize: Invalid Argument');
  1189. ***** ^ not supported yet
  1190. ***** ^ not supported yet
  1191. ***** ^ not supported yet
  1192. ***** ^ not supported yet
  1193. ***** ^ not supported yet
  1194. ***** ^ not supported yet
  1195. 797 END;
  1196. 798 IF NearHeapChangeAlloc(Source, A, OldSize, NewSize) THEN
  1197. ***** ^ undeclared identifier
  1198. ***** ^ not supported yet
  1199. ***** ^ not supported yet
  1200. ***** ^ not supported yet
  1201. 799 RETURN;
  1202. 800 END;
  1203. 801 OldA := A;
  1204. ***** ^ not supported yet
  1205. ***** ^ not supported yet
  1206. 802 NearHeapAllocate(Source, A, NewSize);
  1207. ***** ^ not supported yet
  1208. ***** ^ not supported yet
  1209. ***** ^ not supported yet
  1210. ***** ^ not supported yet
  1211. 803 Lib.WordMove(ADR(OldA^), ADR(A^), OldSize DIV 2);
  1212. ***** ^ not supported yet
  1213. ***** ^ not supported yet
  1214. ***** ^ undeclared identifier
  1215. ***** ^ not supported yet
  1216. ***** ^ undeclared identifier
  1217. ***** ^ not supported yet
  1218. ***** ^ not supported yet
  1219. 804 NearHeapDeallocate(Source, OldA, OldSize);
  1220. ***** ^ not supported yet
  1221. ***** ^ not supported yet
  1222. ***** ^ not supported yet
  1223. ***** ^ not supported yet
  1224. 805 END NearHeapChangeSize;
  1225. ***** ^ not supported yet
  1226. 806
  1227. 807 PROCEDURE NearHeapChangeAlloc(Source: NearHeapRecPtr; A: NearADDRESS;
  1228. ***** ^ undeclared identifier
  1229. ***** ^ undeclared identifier
  1230. 808 OldSize, NewSize : CARDINAL): BOOLEAN;
  1231. 809
  1232. 810 VAR
  1233. 811 Curr, SplitRec, NextRec, PrevRec, NewRec: NearHeapRecPtr;
  1234. ***** ^ undeclared identifier
  1235. 812 Temp: NearHeapRec;
  1236. ***** ^ undeclared identifier
  1237. 813 SplitSize: CARDINAL;
  1238. 814 (*%T _OS2 *)
  1239. 815 T: NearADDRESS;
  1240. ***** ^ undeclared identifier
  1241. 816 (*%E *)
  1242. 817 BEGIN
  1243. 818 IF (Source = SYSTEM.NearNIL) OR (A = SYSTEM.NearNIL) THEN
  1244. ***** ^ not supported yet
  1245. ***** ^ not supported yet
  1246. ***** ^ not supported yet
  1247. ***** ^ not supported yet
  1248. ***** ^ not supported yet
  1249. ***** ^ not supported yet
  1250. 819 Lib.RunTimeError(CoreSig._FatalErrorPos(), 8FH, 'NearHeapChangeAlloc: Invalid Argument');
  1251. ***** ^ not supported yet
  1252. ***** ^ not supported yet
  1253. ***** ^ not supported yet
  1254. ***** ^ not supported yet
  1255. ***** ^ not supported yet
  1256. ***** ^ not supported yet
  1257. 820 END;
  1258. 821 (*%T _OS2 *)
  1259. 822 IF Source = NearHeap THEN
  1260. ***** ^ not supported yet
  1261. ***** ^ undeclared identifier
  1262. 823 T := CoreMem._nexpand(A, NewSize);
  1263. ***** ^ not supported yet
  1264. ***** ^ not supported yet
  1265. ***** ^ not supported yet
  1266. ***** ^ not supported yet
  1267. ***** ^ not supported yet
  1268. 824 RETURN T # NearNIL;
  1269. ***** ^ not supported yet
  1270. ***** ^ undeclared identifier
  1271. 825 END;
  1272. 826 (*%E *)
  1273. 827 IF NewSize < Align THEN
  1274. 828 NewSize := Align;
  1275. 829 ELSE
  1276. 830 NewSize := ( (NewSize+Align-1) DIV Align) * Align;
  1277. 831 IF NewSize = 0 THEN
  1278. 832 NewSize:=MAX(CARDINAL);
  1279. ***** ^ undeclared identifier
  1280. ***** ^ not supported yet
  1281. 833 END;
  1282. 834 END;
  1283. 835 IF OldSize < Align THEN
  1284. 836 OldSize := Align;
  1285. 837 ELSE
  1286. 838 OldSize := ( (OldSize+Align-1) DIV Align) * Align;
  1287. 839 IF OldSize = 0 THEN
  1288. 840 OldSize:=MAX(CARDINAL);
  1289. ***** ^ undeclared identifier
  1290. ***** ^ not supported yet
  1291. 841 END;
  1292. 842 END;
  1293. 843 IF OldSize = NewSize THEN RETURN TRUE END;
  1294. 844 Curr:=NearHeapRecPtr(A);
  1295. ***** ^ not supported yet
  1296. ***** ^ undeclared identifier
  1297. ***** ^ not supported yet
  1298. 845 NextRec:=Source;
  1299. ***** ^ not supported yet
  1300. ***** ^ not supported yet
  1301. 846 LOOP
  1302. 847 PrevRec:=NextRec;
  1303. ***** ^ not supported yet
  1304. ***** ^ not supported yet
  1305. 848 NextRec:=NextRec^.next;
  1306. ***** ^ not supported yet
  1307. ***** ^ not supported yet
  1308. ***** ^ not supported yet
  1309. 849 IF (NextRec = SYSTEM.NearNIL) OR (CARDINAL(NextRec) > CARDINAL(Curr)) THEN EXIT END;
  1310. ***** ^ not supported yet
  1311. ***** ^ not supported yet
  1312. ***** ^ not supported yet
  1313. ***** ^ not supported yet
  1314. ***** ^ not supported yet
  1315. 850 END;
  1316. 851 IF OldSize > NewSize THEN
  1317. 852 SplitSize:=OldSize-NewSize;
  1318. 853 SplitRec:=NearHeapRecPtr(CARDINAL(Curr)+NewSize);
  1319. ***** ^ not supported yet
  1320. ***** ^ undeclared identifier
  1321. ***** ^ not supported yet
  1322. ***** ^ not supported yet
  1323. 854 SplitRec^.size:=SplitSize;
  1324. ***** ^ not supported yet
  1325. ***** ^ not supported yet
  1326. 855 SplitRec^.next:=NextRec;
  1327. ***** ^ not supported yet
  1328. ***** ^ not supported yet
  1329. ***** ^ not supported yet
  1330. 856 PrevRec^.next:=SplitRec;
  1331. ***** ^ not supported yet
  1332. ***** ^ not supported yet
  1333. ***** ^ not supported yet
  1334. 857 Merge(SplitRec, NextRec);
  1335. ***** ^ not supported yet
  1336. ***** ^ not supported yet
  1337. ***** ^ not supported yet
  1338. 858 RETURN TRUE;
  1339. 859 END;
  1340. 860 IF (NextRec # SYSTEM.NearNIL) AND (NearHeapRecPtr(CARDINAL(Curr)+OldSize) = NextRec) THEN (* Next Block is free *)
  1341. ***** ^ not supported yet
  1342. ***** ^ not supported yet
  1343. ***** ^ not supported yet
  1344. ***** ^ undeclared identifier
  1345. ***** ^ not supported yet
  1346. ***** ^ not supported yet
  1347. ***** ^ not supported yet
  1348. 861 Temp.size := OldSize+NextRec^.size;
  1349. ***** ^ not supported yet
  1350. ***** ^ not supported yet
  1351. ***** ^ not supported yet
  1352. ***** ^ not supported yet
  1353. 862 Temp.next := NextRec^.next;
  1354. ***** ^ not supported yet
  1355. ***** ^ not supported yet
  1356. ***** ^ not supported yet
  1357. ***** ^ not supported yet
  1358. 863 IF Temp.size = NewSize THEN
  1359. ***** ^ not supported yet
  1360. ***** ^ not supported yet
  1361. 864 PrevRec^.next := Temp.next;
  1362. ***** ^ not supported yet
  1363. ***** ^ not supported yet
  1364. ***** ^ not supported yet
  1365. ***** ^ not supported yet
  1366. 865 ELSE
  1367. 866 NewRec := NearHeapRecPtr(CARDINAL(Curr)+NewSize);
  1368. ***** ^ not supported yet
  1369. ***** ^ undeclared identifier
  1370. ***** ^ not supported yet
  1371. ***** ^ not supported yet
  1372. 867 PrevRec^.next := NewRec;
  1373. ***** ^ not supported yet
  1374. ***** ^ not supported yet
  1375. ***** ^ not supported yet
  1376. 868 NewRec^.size := Temp.size-NewSize;
  1377. ***** ^ not supported yet
  1378. ***** ^ not supported yet
  1379. ***** ^ not supported yet
  1380. ***** ^ not supported yet
  1381. 869 NewRec^.next := Temp.next;
  1382. ***** ^ not supported yet
  1383. ***** ^ not supported yet
  1384. ***** ^ not supported yet
  1385. ***** ^ not supported yet
  1386. 870 END;
  1387. 871 RETURN TRUE;
  1388. 872 ELSE
  1389. 873 RETURN FALSE;
  1390. 874 END;
  1391. 875 END NearHeapChangeAlloc;
  1392. ***** ^ not supported yet
  1393. 876
  1394. 877
  1395. 878 (*%F _DLL *)
  1396. 879 PROCEDURE NearAllocate(VAR a: NearADDRESS; size: CARDINAL);
  1397. 880
  1398. 881 BEGIN
  1399. 882 NearHeapAllocate(NearHeap,a,size);
  1400. 883 END NearAllocate;
  1401. 884
  1402. 885
  1403. 886 PROCEDURE NearDeallocate(VAR a: NearADDRESS; size: CARDINAL);
  1404. 887
  1405. 888 BEGIN
  1406. 889 NearHeapDeallocate(NearHeap,a,size);
  1407. 890 END NearDeallocate;
  1408. 891
  1409. 892
  1410. 893 PROCEDURE NearAvailable(size: CARDINAL) : BOOLEAN;
  1411. 894
  1412. 895 BEGIN
  1413. 896 RETURN size <= NearHeapAvail(NearHeap);
  1414. 897 END NearAvailable;
  1415. 898 (*%E *)
  1416. 899
  1417. 900 (*%T _DLL *)
  1418. 901 PROCEDURE NearAllocate(VAR a: NearADDRESS; size: CARDINAL);
  1419. ***** ^ undeclared identifier
  1420. 902
  1421. 903 BEGIN
  1422. 904 a := NearNIL;
  1423. ***** ^ not supported yet
  1424. ***** ^ undeclared identifier
  1425. 905 END NearAllocate;
  1426. ***** ^ not supported yet
  1427. 906
  1428. 907
  1429. 908 PROCEDURE NearDeallocate(VAR a: NearADDRESS; size: CARDINAL);
  1430. ***** ^ undeclared identifier
  1431. 909
  1432. 910 BEGIN
  1433. 911 END NearDeallocate;
  1434. ***** ^ not supported yet
  1435. 912
  1436. 913
  1437. 914 PROCEDURE NearAvailable(size: CARDINAL) : BOOLEAN;
  1438. 915
  1439. 916 BEGIN
  1440. 917 RETURN FALSE;
  1441. 918 END NearAvailable;
  1442. ***** ^ not supported yet
  1443. 919 (*%E *)
  1444. 920
  1445. 921
  1446. 922 (*%F _OS2 *)
  1447. 923 PROCEDURE SegAllocate(Size: CARDINAL): CARDINAL;
  1448. 924
  1449. 925 VAR
  1450. 926 S: FarADDRESS;
  1451. 927 BEGIN
  1452. 928 FarAllocate(S, Size);
  1453. 929 RETURN Seg(S^);
  1454. 930 END SegAllocate;
  1455. 931
  1456. 932 PROCEDURE SegDeallocate(Sel: CARDINAL; Size: CARDINAL);
  1457. 933
  1458. 934 VAR
  1459. 935 S: FarADDRESS;
  1460. 936 BEGIN
  1461. 937 S := [Sel: 0];
  1462. 938 FarDeallocate(S, Size);
  1463. 939 END SegDeallocate;
  1464. 940 (*%E *)
  1465. 941
  1466. 942 (*%T _OS2 *)
  1467. 943 PROCEDURE SegAllocate(Size: CARDINAL): CARDINAL;
  1468. 944
  1469. 945 VAR
  1470. 946 S: CARDINAL;
  1471. 947 BEGIN
  1472. 948 IF Dos.AllocSeg(Size, S, 0) = 0 THEN
  1473. ***** ^ not supported yet
  1474. ***** ^ not supported yet
  1475. ***** ^ not supported yet
  1476. 949 RETURN S;
  1477. 950 END;
  1478. 951 RETURN 0;
  1479. 952 END SegAllocate;
  1480. ***** ^ not supported yet
  1481. 953
  1482. 954 PROCEDURE SegDeallocate(Sel: CARDINAL; Size: CARDINAL);
  1483. 955
  1484. 956 BEGIN
  1485. 957 IF Dos.FreeSeg(Sel) # 0 THEN END;
  1486. ***** ^ not supported yet
  1487. ***** ^ not supported yet
  1488. ***** ^ not supported yet
  1489. 958 END SegDeallocate;
  1490. ***** ^ not supported yet
  1491. 959 (*%E *)
  1492. 960
  1493. 961 BEGIN
  1494. 962 Check := TRUE;
  1495. ***** ^ undeclared identifier
  1496. 963 ClearOnAllocate := FALSE;
  1497. ***** ^ undeclared identifier
  1498. 964 NearHeap := NearHeapRecPtr(0FFFFH);
  1499. ***** ^ undeclared identifier
  1500. ***** ^ undeclared identifier
  1501. ***** ^ not supported yet
  1502. 965 (*%F _OS2 *)
  1503. 966 MainHeap := [SYSTEM.HeapBase: 0];
  1504. 967 NearHeapSetup := FALSE;
  1505. 968 FarHeapSetup := FALSE;
  1506. 969 (*%E *)
  1507. 970 END Storage.
  1508. ***** ^ not supported yet
  1509. 537 errors