Browse Source

* LLVM workaround

Michaël Van Canneyt 2 months ago
parent
commit
3c5b049f6b
2 changed files with 19 additions and 0 deletions
  1. 5 0
      rtl/objpas/sysutils/sysutilh.inc
  2. 14 0
      rtl/objpas/sysutils/sysutils.inc

+ 5 - 0
rtl/objpas/sysutils/sysutilh.inc

@@ -348,7 +348,12 @@ Type
   { Type Helpers}
   {$i syshelph.inc}
 
+  {$IFDEF CPULLVM}
+  // LLVM does not allow the constref use.
+  procedure FreeAndNil(var obj);
+  {$else}    
   procedure FreeAndNil(constref obj : TObject);
+  {$ENDIF}
   procedure FreeMemAndNil(var p);
 
   { interface handling }

+ 14 - 0
rtl/objpas/sysutils/sysutils.inc

@@ -157,6 +157,19 @@ end;
   { OS utility code }
   {$i osutil.inc}
 
+    {$IFDEF CPULLVM}
+    // LLVM does not like the constref construction. 
+    // So when LLVM is used, we keep the untyped version.
+    // This allows users of other platforms to enjoy the type safety of FreeAndNil.
+    procedure FreeAndNil(var obj);
+      var 
+        temp: tobject;
+      begin
+        temp:=tobject(obj);
+        pointer(obj):=nil;
+        temp.free;
+      end;
+    {$ELSE}
     procedure FreeAndNil(constref obj: TObject);
       type
         PObject = ^TObject;
@@ -167,6 +180,7 @@ end;
         PObject(@obj)^:=nil;
         temp.free;
       end;
+    {$ENDIF}
 
     procedure FreeMemAndNil(var p);