[fpc-pascal] dynamic arrays behaving funny

Marc Santhoff M.Santhoff at t-online.de
Wed Nov 12 21:53:22 CET 2008


I'm trying to assing dynamic array variables to a record type on the
heap and handing that record over to the caller:


TCompoundInfo = record
		Id: hid_t;
		Name: string;
		TotalSize: longword;
		ElementNames: array of PChar;
		ElementSizes: array of longword;
		ElementTypes: HidTArray;
		ElementOffsets: array of longword;

PTableInfo = ^TTableInfo;
TTableInfo = TCompoundInfo;

  TBaseCompoundDescriptor = class
    fItemName: string;
    fTotalTypeSize: longword;
    fFieldCount: integer;
    fFieldNames: array of PChar;
    fFieldSizes: array of longword;
    fFieldOffsets: array of longword;
    fFieldTypes: HidtArray;

  TTableDescriptor = class(TBaseCompoundDescriptor)

constructor TTableDescriptor.create;
  inherited create;
  GetMem(fInfo, sizeof(TTableInfo));

function TTableDescriptor.GetInfo: PTableInfo;
  with fInfo^ do begin
    Name := fItemName;
    TotalSize := fTotalTypeSize;
    ElementNames := fFieldNames;

the last line trying to assign a (already sized and holding information)
dynamic array to a similar variable fails:

Program received signal SIGSEGV, Segmentation fault.
0x8051eb5 in fpc_dynarray_decr_ref ()
(gdb) bt
#0  0x8051eb5 in fpc_dynarray_decr_ref ()
#1  0x80a2b26 in TTABLEDESCRIPTOR__GETINFO (this=0x283981e8) at CompoundTypes.pas:398
#2  0x80624e3 in TDS_HDF__INIT (C=0x80a8fc4, this=0x283c8028) at DS_HDF.pp:210
#3  0x8064fd1 in TDATACONVERTER__CONVERT (this=0x283b0248) at DataConverter.pp:191
#4  0x8049425 in main () at DC.pas:156

The ref guide says when assigning one dyn-array to another variable of
the same type, this is done by reference and those arrays are

Why does it fail?

I tried using SetLength on the target var first, same error.


More information about the fpc-pascal mailing list