View Issue Details

IDProjectCategoryView StatusLast Update
0037339FPCCompilerpublic2020-07-16 22:44
ReporterBoris Matkov Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.2.0 
Fixed in Version3.3.1 
Summary0037339: Regression: cast Variant to NativeInt is broken
DescriptionRegression: cast Variant to NativeInt is broken
Steps To ReproduceThis code can be compiled in FPC 3.0.4 and any Delphi version succesfully:

function VarToObj(const Value: Variant): TObject;
begin
  Result := TObject(Pointer(NativeInt(Value)));
end;

But in FPC 3.2.0 I get the error:
Error: Illegal type conversion: "Variant" to "NativeInt"
Tagspatch, regression, variant
Fixed in Revision45797
FPCOldBugId
FPCTarget-
Attached Files

Activities

Marco van de Voort

2020-07-13 12:52

manager   ~0123965

Please indicate the target (OS and 32/64-bit) for all test cases.

Serge Anvarov

2020-07-13 16:17

reporter   ~0123984

In Delphi NativeInt is native, i.e. alias for PtrInt. In FPC NativeInt is a distinct type (I don't remember the reason anymore). The same error ($H+):
function VarToString(const Value: Variant): string;
begin
  Result := string(TFileName(Value))); // TFileName = type string;
end;

Sergey Larin

2020-07-14 08:41

reporter   ~0123995

The attached patch solves this issue.
variant-assign-nativeint.patch (2,455 bytes)   
diff --git a/rtl/inc/variant.inc b/rtl/inc/variant.inc
index 840750bd96..253c90efcd 100644
--- a/rtl/inc/variant.inc
+++ b/rtl/inc/variant.inc
@@ -203,6 +203,19 @@ begin
   Variantmanager.varfromInt64(Dest,Source);
 end;
 
+
+operator :=(const source : NativeInt) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
+begin
+  dest:=PtrInt(source);
+end;
+
+
+operator :=(const source : NativeUInt) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
+begin
+  dest:=PtrUInt(source);
+end;
+
+
 { Boolean }
 
 operator :=(const source : boolean) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
@@ -395,6 +408,18 @@ begin
 end;
 
 
+operator :=(const source : variant) dest : NativeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+begin
+  PtrInt(dest):=source;
+end;
+
+
+operator :=(const source : variant) dest : NativeUInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+begin
+  PtrUInt(dest):=source;
+end;
+
+
 { Boolean }
 
 operator :=(const source : variant) dest : boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
diff --git a/rtl/inc/varianth.inc b/rtl/inc/varianth.inc
index 4f1c4d5bd6..a5443648d6 100644
--- a/rtl/inc/varianth.inc
+++ b/rtl/inc/varianth.inc
@@ -242,6 +242,8 @@ operator :=(const source : dword) dest : variant;{$ifdef SYSTEMINLINE}inline;{$e
 operator :=(const source : longint) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
 operator :=(const source : qword) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
 operator :=(const source : int64) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
+operator :=(const source : NativeInt) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
+operator :=(const source : NativeUInt) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
 
 { Boolean }
 operator :=(const source : boolean) dest : variant;{$ifdef SYSTEMINLINE}inline;{$endif}
@@ -299,6 +301,8 @@ operator :=(const source : variant) dest : dword;{$ifdef SYSTEMINLINE}inline;{$e
 operator :=(const source : variant) dest : longint;{$ifdef SYSTEMINLINE}inline;{$endif}
 operator :=(const source : variant) dest : qword;{$ifdef SYSTEMINLINE}inline;{$endif}
 operator :=(const source : variant) dest : int64;{$ifdef SYSTEMINLINE}inline;{$endif}
+operator :=(const source : variant) dest : NativeInt;{$ifdef SYSTEMINLINE}inline;{$endif}
+operator :=(const source : variant) dest : NativeUInt;{$ifdef SYSTEMINLINE}inline;{$endif}
 
 { Boolean }
 operator :=(const source : variant) dest : boolean;{$ifdef SYSTEMINLINE}inline;{$endif}
variant-assign-nativeint.patch (2,455 bytes)   

Sven Barth

2020-07-14 11:44

manager   ~0124000

@Serge Anvarov: no, in Delphi NativeInt/NativeUInt are built-in types (and PtrInt/PtrUInt don't exist in Delphi). See 0029444 which was the cause for that change.

Florian

2020-07-16 22:44

administrator   ~0124104

Thanks for the patch, applied.

Issue History

Date Modified Username Field Change
2020-07-13 07:55 Boris Matkov New Issue
2020-07-13 12:52 Marco van de Voort Note Added: 0123965
2020-07-13 16:17 Serge Anvarov Note Added: 0123984
2020-07-14 08:41 Sergey Larin Note Added: 0123995
2020-07-14 08:41 Sergey Larin File Added: variant-assign-nativeint.patch
2020-07-14 09:19 Sergey Larin Tag Attached: regression
2020-07-14 09:19 Sergey Larin Tag Attached: variant
2020-07-14 09:19 Sergey Larin Tag Attached: patch
2020-07-14 11:44 Sven Barth Note Added: 0124000
2020-07-16 22:44 Florian Assigned To => Florian
2020-07-16 22:44 Florian Status new => resolved
2020-07-16 22:44 Florian Resolution open => fixed
2020-07-16 22:44 Florian Fixed in Version => 3.3.1
2020-07-16 22:44 Florian Fixed in Revision => 45797
2020-07-16 22:44 Florian FPCTarget => -
2020-07-16 22:44 Florian Note Added: 0124104