[fpc-pascal] SIGSEGV in SYSTEM_TOBJECT_$__CLEANUPINSTANCE when calling from C app

Sven Barth pascaldragon at googlemail.com
Tue Dec 14 10:12:38 CET 2010


Am 13.12.2010 22:43, schrieb Matthias Klumpp:
> On Mon, 13 Dec 2010 22:34:38 +0200, Juha Manninen
> <juha.manninen62 at gmail.com>  wrote:
>> Matthias Klumpp kirjoitti maanantai 13 joulukuu 2010 18:50:46:
>>>   if obj^ = nil then exit;
>>>   FreeAndNil(obj^);
>>
>> Shouldn't it be:
>>
>>   // if obj = nil then exit;<-- not really needed
>>   FreeAndNil(obj);
> Yes, right. The first line was only for testing. But removing the line, of
> course, does not affect the behavior in any way, which means the error is
> still present.

Did you notice that Juha removed the "^" after "obj" as well? How is 
PObject defined? Maybe you should just work with TObject directly, cause 
a class instance variable is already a pointer.

So:

function create_fpc_class_xy: TObject; cdecl;
begin
   Result := TClassXY.Create;
end;

procedure free_fpc_class(aObject: TObject); cdecl;
begin
   aObject.Free;
end;

In c:
void* create_fpc_class_xy();
void free_fpc_class(void* aObject);

Regards,
Sven



More information about the fpc-pascal mailing list