Răsfoiți Sursa

* readded support for ReturnIfGrowHeapFails

peter 21 ani în urmă
părinte
comite
cd35d3fd5e
2 a modificat fișierele cu 27 adăugiri și 6 ștergeri
  1. 21 5
      rtl/inc/heap.inc
  2. 6 1
      rtl/inc/heaph.inc

+ 21 - 5
rtl/inc/heap.inc

@@ -816,10 +816,15 @@ begin
       result := SysOSAlloc(size);
       result := SysOSAlloc(size);
     { try again }
     { try again }
     if result=nil then
     if result=nil then
-   begin
+    begin
       result := SysOSAlloc(size);
       result := SysOSAlloc(size);
-      if result=nil then
-        HandleError(203);
+      if (result=nil) then
+        begin
+          if ReturnNilIfGrowHeapFails then
+            exit
+          else
+            HandleError(203);
+        end;
     end;
     end;
     { set the total new heap size }
     { set the total new heap size }
     inc(internal_memavail,size);
     inc(internal_memavail,size);
@@ -873,12 +878,17 @@ var
   poc: poschunk;
   poc: poschunk;
   s: ptrint;
   s: ptrint;
 begin
 begin
+  result:=nil;
   { try to find a block in one of the freelists per size }
   { try to find a block in one of the freelists per size }
   s := size shr blockshr;
   s := size shr blockshr;
   pcurr := freelists_fixed[s];
   pcurr := freelists_fixed[s];
   { no free blocks ? }
   { no free blocks ? }
   if not assigned(pcurr) then
   if not assigned(pcurr) then
-    pcurr := alloc_oschunk(s, size);
+    begin
+      pcurr := alloc_oschunk(s, size);
+      if not assigned(pcurr) then
+        exit;
+    end;
   { get a pointer to the block we should return }
   { get a pointer to the block we should return }
   result := pointer(pcurr)+sizeof(tmemchunk_fixed_hdr);
   result := pointer(pcurr)+sizeof(tmemchunk_fixed_hdr);
   { flag as in-use }
   { flag as in-use }
@@ -902,6 +912,7 @@ var
   pbest : pmemchunk_var;
   pbest : pmemchunk_var;
 {$endif}
 {$endif}
 begin
 begin
+  result:=nil;
 {$ifdef BESTMATCH}
 {$ifdef BESTMATCH}
   pbest := nil;
   pbest := nil;
 {$endif}
 {$endif}
@@ -935,6 +946,8 @@ begin
    begin
    begin
     // all os-chunks full, allocate a new one
     // all os-chunks full, allocate a new one
     pcurr := alloc_oschunk(0, size);
     pcurr := alloc_oschunk(0, size);
+    if not assigned(pcurr) then
+      exit;
   end;
   end;
 
 
      { get pointer of the block we should return }
      { get pointer of the block we should return }
@@ -1290,7 +1303,10 @@ end;
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.34  2004-06-27 19:47:27  florian
+  Revision 1.35  2004-06-29 20:50:32  peter
+    * readded support for ReturnIfGrowHeapFails
+
+  Revision 1.34  2004/06/27 19:47:27  florian
     * fixed heap corruption on sparc
     * fixed heap corruption on sparc
 
 
   Revision 1.33  2004/06/27 11:57:18  florian
   Revision 1.33  2004/06/27 11:57:18  florian

+ 6 - 1
rtl/inc/heaph.inc

@@ -45,6 +45,8 @@ const
   growheapsizesmall : ptrint=32*1024; { fixed-size small blocks will grow with 32k }
   growheapsizesmall : ptrint=32*1024; { fixed-size small blocks will grow with 32k }
   growheapsize1 : ptrint=256*1024;  { < 256k will grow with 256k }
   growheapsize1 : ptrint=256*1024;  { < 256k will grow with 256k }
   growheapsize2 : ptrint=1024*1024; { > 256k will grow with 1m }
   growheapsize2 : ptrint=1024*1024; { > 256k will grow with 1m }
+var
+  ReturnNilIfGrowHeapFails : boolean;
 
 
 { Default MemoryManager functions }
 { Default MemoryManager functions }
 Function  SysGetmem(Size:ptrint):Pointer;
 Function  SysGetmem(Size:ptrint):Pointer;
@@ -93,7 +95,10 @@ Procedure AsmFreemem(var p:pointer);
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.10  2004-06-20 09:24:40  peter
+  Revision 1.11  2004-06-29 20:50:32  peter
+    * readded support for ReturnIfGrowHeapFails
+
+  Revision 1.10  2004/06/20 09:24:40  peter
   fixed go32v2 compile
   fixed go32v2 compile
 
 
   Revision 1.9  2004/06/17 16:16:13  peter
   Revision 1.9  2004/06/17 16:16:13  peter