瀏覽代碼

* fixed variant array creation and copying on non win32 system

git-svn-id: trunk@170 -
fpc 20 年之前
父節點
當前提交
c5b90ed37c
共有 2 個文件被更改,包括 12 次插入6 次删除
  1. 6 4
      rtl/inc/varianth.inc
  2. 6 2
      rtl/objpas/varutils.inc

+ 6 - 4
rtl/inc/varianth.inc

@@ -57,15 +57,17 @@ type
      elementcount,lowbound  : SizeInt;
    end;
 
+   tvararrayboundarray = array[0..0] of tvararraybound;
+   tvararraycoorarray = array[0..0] of SizeInt;
+
    tvararray = packed record
       dimcount,flags : word;
-      elementsize,lockcount : longint;
+      elementsize : ptrint;
+      lockcount : longint;
       data : pointer;
-      bounds : array[0..255] of tvararraybound;
+      bounds : tvararrayboundarray;
    end;
 
-   tvararrayboundarray = array[0..0] of tvararraybound;
-   tvararraycoorarray = array[0..0] of SizeInt;
 
    tvarop = (opadd,opsubtract,opmultiply,opdivide,opintdivide,opmodulus,
              opshiftleft,opshiftright,opand,opor,opxor,opcompare,opnegate,

+ 6 - 2
rtl/objpas/varutils.inc

@@ -379,7 +379,8 @@ Function SafeArrayCreate(VarType, Dim: SizeInt; const Bounds: TVarArrayBoundArra
 Function SafeArrayAllocDescriptor(DimCount: SizeInt; var psa: PVarArray): HRESULT;stdcall;
 begin
   try
-    psa:=GetMem(SizeOf(TVarArray) + SizeOf(TVarArrayBound) * (DimCount - 1));
+    { one bound item is included in TVarArray }
+    psa:=GetMem(SizeOf(TVarArray) + SizeOf(TVarArrayBound)*(DimCount-1));
     Result:=VAR_OK;
   except
     On E : Exception do
@@ -391,7 +392,10 @@ Function SafeArrayAllocData(psa: PVarArray): HRESULT;stdcall;
 begin
   try
     With psa^ do
-      Data:=GetMem(SafeArrayElementTotal(psa)*ElementSize);
+      begin 
+        Data:=GetMem(SafeArrayElementTotal(psa)*ElementSize);
+        fillchar(Data^,SafeArrayElementTotal(psa)*ElementSize,0);
+      end;
     Result:=VAR_OK;
   except
     On E : Exception do