Browse Source

* fix #39506: add assignment operator overloads for all string types so that assignments of constant strings can be handled correctly
+ added adjusted/extended test (the test isn't enabled by default however as it requires libffi on most platforms)

Sven/Sarah Barth 3 years ago
parent
commit
52ed79c7f3
2 changed files with 64 additions and 2 deletions
  1. 20 2
      packages/rtl-objpas/src/inc/rtti.pp
  2. 44 0
      tests/webtbs/tw39506.pp

+ 20 - 2
packages/rtl-objpas/src/inc/rtti.pp

@@ -158,7 +158,10 @@ type
     function GetReferenceToRawData: Pointer;
     function GetReferenceToRawData: Pointer;
     procedure ExtractRawData(ABuffer: Pointer);
     procedure ExtractRawData(ABuffer: Pointer);
     procedure ExtractRawDataNoCopy(ABuffer: Pointer);
     procedure ExtractRawDataNoCopy(ABuffer: Pointer);
-    class operator := (const AValue: String): TValue; inline;
+    class operator := (const AValue: ShortString): TValue; inline;
+    class operator := (const AValue: AnsiString): TValue; inline;
+    class operator := (const AValue: UnicodeString): TValue; inline;
+    class operator := (const AValue: WideString): TValue; inline;
     class operator := (AValue: LongInt): TValue; inline;
     class operator := (AValue: LongInt): TValue; inline;
     class operator := (AValue: Single): TValue; inline;
     class operator := (AValue: Single): TValue; inline;
     class operator := (AValue: Double): TValue; inline;
     class operator := (AValue: Double): TValue; inline;
@@ -2369,7 +2372,22 @@ begin
     Move((@FData.FAsPointer)^, ABuffer^, DataSize);
     Move((@FData.FAsPointer)^, ABuffer^, DataSize);
 end;
 end;
 
 
-class operator TValue.:=(const AValue: String): TValue;
+class operator TValue.:=(const AValue: ShortString): TValue;
+begin
+  Make(@AValue, System.TypeInfo(AValue), Result);
+end;
+
+class operator TValue.:=(const AValue: AnsiString): TValue;
+begin
+  Make(@AValue, System.TypeInfo(AValue), Result);
+end;
+
+class operator TValue.:=(const AValue: UnicodeString): TValue;
+begin
+  Make(@AValue, System.TypeInfo(AValue), Result);
+end;
+
+class operator TValue.:=(const AValue: WideString): TValue;
 begin
 begin
   Make(@AValue, System.TypeInfo(AValue), Result);
   Make(@AValue, System.TypeInfo(AValue), Result);
 end;
 end;

+ 44 - 0
tests/webtbs/tw39506.pp

@@ -0,0 +1,44 @@
+{ %INTERACTIVE }
+{ %NOTE=This test requires libffi on most platforms }
+
+program tw39506;
+
+{$if not defined(cpui386)}
+{$define useffi}
+{$endif}
+{$if defined(cpux86_64) and defined(win64)}
+{$undef useffi}
+{$endif}
+
+uses
+{$ifdef useffi}
+  ffi.manager,
+{$endif}
+  rtti,
+  typinfo;
+
+var
+  ok: Boolean = False;
+
+procedure p(aArg1: ShortString; aArg2: AnsiString; aArg3: UnicodeString; aArg4: WideString);
+begin
+  if aArg1 <> 'hello' then
+    Halt(1);
+  if aArg2 <> 'world' then
+    Halt(2);
+  if aArg3 <> 'foo' then
+    Halt(3);
+  if aArg4 <> 'bar' then
+    Halt(4);
+  ok := True;
+end;
+
+var
+  a: TValueArray;
+begin
+  a := [ShortString('hello'), AnsiString('world'), UnicodeString('foo'), WideString('bar')];
+  Invoke(@p,a,ccReg,nil,false,false);
+  if not ok then
+    Halt(5);
+end.
+