Hi!
I created a C application which calls methods from a library developed in Pascal.
I can create objects by using
void *test;
test = br_object_new ();
and access the object too, but when I try to free an object after it has been used, I get a segfault in SYSTEM_TOBJECT_$__CLEANUPINSTANCE. The code to free an object looks like to following: procedure br_object_free(obj: PObject);cdecl;
begin
if obj^ = nil then exit;
FreeAndNil(obj^);
end;
I can access all properties of obj^, as well as calling methods. I only cannot free the object.
Does someone have an idea why the application behaves like this? I use FPC 2.4.0.
Kind regards
Matthias Klumpp
Mailing lists / fpc-pascal / 2010-12
SIGSEGV in SYSTEM_TOBJECT_$__CLEANUPINSTANCE when calling from C app
4 messages · 3 people · –
- MMatthias Klumpp 2
- JJuha Manninen 1
- SSven Barth 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
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);Juha
Juha Manninen wrote 8 lines
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.
Regards
Matthias
Matthias Klumpp wrote 13 lines
On Mon, 13 Dec 2010 22:34:38 +0200, Juha Manninen
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
