Perl-Sensitive Sunglasses | |
PerlMonks |
Re^3: FFI::Platypus: Replace malloc with GC_MALLOC?by syphilis (Archbishop) |
on Dec 12, 2022 at 06:25 UTC ( [id://11148768]=note: print w/replies, xml ) | Need Help?? |
I guess I should probably do the obvious thing and just try it out That could be informative ;-) I've had a bit of a fiddle with it in Inline::C, and it seems that it probably almost works as you want. The print string_reverse("\nHello World"); works exactly as expected and does not call free(). And the 2nd line of perl code (string_reverse(undef);) definitely calls free(). The only problem is that having called free(), Inline::C/XS evaluates the condition input == NULL as FALSE - and it therefore allocates more memory, which in turn would require a third call to be cleared ... and so on. With Inline::C/XS, the argument to the second call needs to be something string_reverse() will evaluate as NULL - and undef does not fit that bill. Maybe, with FFI::Platypus, undef will be evaluated as NULL ... you could verify that it's being evaluated as desired, by using Devel::Peek and changing that second line to Dump(reverse_string(undef);. If that results in a Dump() that looks something like: then the undef was evaluated as NULL and all is probably good. But for me, with Inline::C, that Dump() produces: which indicates that more memory was allocated by that second call. I remember that this problem with undef not being equated with NULL has come up here before ... I haven't done the search for it :-( UPDATE: The thread I was thinking of is this one. I can't recall whether there exists a perl arg that will be equated to NULL, or whether you have to hack the perl typemap to achieve it. Anyway ... FAIRK, FFI::Platypus might handle undef differently. Cheers, Rob
In Section
Seekers of Perl Wisdom
|
|