Browse Source

+ add a test to ensure that array constructors correctly handle managed types (though there might be a temp floating around for longer than one might expect)

git-svn-id: trunk@36243 -
svenbarth 8 years ago
parent
commit
d073e07244
2 changed files with 52 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 51 0
      tests/test/tarrconstr7.pp

+ 1 - 0
.gitattributes

@@ -12096,6 +12096,7 @@ tests/test/tarrconstr3.pp svneol=native#text/pascal
 tests/test/tarrconstr4.pp svneol=native#text/pascal
 tests/test/tarrconstr5.pp svneol=native#text/pascal
 tests/test/tarrconstr6.pp svneol=native#text/pascal
+tests/test/tarrconstr7.pp svneol=native#text/pascal
 tests/test/tasm1.pp svneol=native#text/plain
 tests/test/tasm10.pp svneol=native#text/plain
 tests/test/tasm2.inc svneol=native#text/plain

+ 51 - 0
tests/test/tarrconstr7.pp

@@ -0,0 +1,51 @@
+program tarrconstr7;
+
+{$mode objfpc}
+
+type
+  TTest = class(TInterfacedObject, IInterface)
+    function _AddRef : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
+    function _Release : longint;{$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
+  end;
+
+var
+  gRefCount: LongInt = 0;
+
+function TTest._AddRef: LongInt; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
+begin
+  Result := inherited _AddRef;
+  gRefCount := Result;
+end;
+
+function TTest._Release: LongInt; {$IFNDEF WINDOWS}cdecl{$ELSE}stdcall{$ENDIF};
+begin
+  Result := inherited _Release;
+  gRefCount := Result;
+end;
+
+procedure TestArrConstr(const aIntf: IInterface);
+var
+  a: array of IInterface;
+begin
+  a := [aIntf];
+  a := Nil;
+end;
+
+procedure Test;
+var
+  t: IInterface;
+  c: LongInt;
+begin
+  t := TTest.Create;
+
+  c := gRefCount;
+  TestArrConstr(t);
+  if gRefCount <> c then
+    Halt(1);
+end;
+
+begin
+  Test;
+  if gRefCount <> 0 then
+    Halt(2);
+end.