]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR modula2/125544: ISO reallocate does not call allocate if the address is NIL
authorGaius Mulley <gaiusmod2@gmail.com>
Tue, 2 Jun 2026 11:14:51 +0000 (12:14 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Tue, 2 Jun 2026 11:14:51 +0000 (12:14 +0100)
This bugfix is for the ISO Storage.REALLOCATE procedure which is a GNU
extension.  It should behave in the same way as the PIM version by
first checking whether the pointer parameter is NIL and then calling
ALLOCATE.

gcc/m2/ChangeLog:

PR modula2/125544
* gm2-libs-iso/Storage.def (REALLOCATE): Updated comment
describing new behavior.
* gm2-libs-iso/Storage.mod (REALLOCATE): Check addr
and call ALLOCATE if NIL else call lowerReallocate.
(lowerReallocate): New procedure.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
gcc/m2/gm2-libs-iso/Storage.def
gcc/m2/gm2-libs-iso/Storage.mod

index 24bf8537896f531dabc665bf7ec21b12b63d87d8..586fb20ae67d715eefbd470358a700f1459adca7 100644 (file)
@@ -28,7 +28,8 @@ PROCEDURE DEALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL);
   *)
 
 PROCEDURE REALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL);
-  (* Attempts to reallocate, amount of storage.  Effectively it
+  (* If addr is NIL then ALLOCATE is called otherwise it
+     attempts to reallocate amount of storage.  Effectively it
      calls ALLOCATE, copies the amount of data pointed to by
      addr into the new space and DEALLOCATES the addr.
      This procedure is a GNU extension.
index 4f853bf2fcfa5f94ab04ca86cc3df7fe40a8d850..153386b96dce20dada8c3f53ce964796afc65ea1 100644 (file)
@@ -89,17 +89,18 @@ BEGIN
 END DEALLOCATE ;
 
 
-PROCEDURE REALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL);
-  (* Attempts to reallocate, amount of storage.  Effectively it
-     calls ALLOCATE, copies the amount of data pointed to by
-     addr into the new space and DEALLOCATES the addr.
-     This procedure is a GNU extension.
-  *)
+(*
+   LowerReallocate - attempts to reallocate amount of storage by
+                     calling ALLOCATE and then coping the amount of data
+                     pointed to by addr into the new space.
+                     Lastly the original addr is deallocated.
+*)
+
+PROCEDURE LowerReallocate (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL) ;
 VAR
    newa: SYSTEM.ADDRESS ;
    n   : CARDINAL ;
 BEGIN
-   assert (initialized) ;
    IF NOT IsIn (storageTree, addr)
    THEN
       RAISE (storageException, ORD(pointerToUnallocatedStorage),
@@ -115,6 +116,24 @@ BEGIN
    END ;
    DEALLOCATE(addr, n) ;
    addr := newa
+END LowerReallocate ;
+
+
+PROCEDURE REALLOCATE (VAR addr: SYSTEM.ADDRESS; amount: CARDINAL);
+  (* If addr is NIL then ALLOCATE is called otherwise it
+     attempts to reallocate amount of storage.  Effectively it
+     calls ALLOCATE, copies the amount of data pointed to by
+     addr into the new space and DEALLOCATES the addr.
+     This procedure is a GNU extension.
+  *)
+BEGIN
+   assert (initialized) ;
+   IF addr = NIL
+   THEN
+      ALLOCATE (addr, amount)
+   ELSE
+      LowerReallocate (addr, amount)
+   END
 END REALLOCATE ;