P is for Practical | |
PerlMonks |
Problem on perl callbacks from XSby cosimo (Hermit) |
on May 24, 2008 at 21:44 UTC ( [id://688332]=perlquestion: print w/replies, xml ) | Need Help?? |
cosimo has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks,
I've been fighting with this problem for a while, and despite my best efforts, I'm still stuck. Maybe very near to the solution, but still stuck.
I believe that the following simple case is the root of the problem. Feel free to correct/direct me.
The codeThis code is partly taken from JSON::XS. I'm trying to write an XS function that takes an array or hashref in sv and, with some custom rules, serializes the content into a result scalar as one big string with everything. When an hashref is really a blessed object, I want its toString() method to be called to dump the hashref content to my result SV. Calling the object's toString() method is the task for the code I shown you. The problemI think the problem lies here: what happens when, eventually, an object's toString() method code, for whatever reason, happens to contain a call to my XS function? (that could, in turn, call other toString() methods for other kind of objects...). Does this break my stack manipulation? I think so, because I see segfaults and other bad things when toString() completes and the the code tries to return the resulting SV to the caller. I feel I'm missing something about the stack manipulation in this case, but I really don't know how to proceed. Thank you for any help you can provide. UPDATE: 2008-05-25 14:53 CETThe solutionI believe I have solved the problem. It was a real bitch of a hellish problem, trust me. Seems I've been bitten by old XS conventions about returning values to Perl code. As it turned out, the problem was not in the snippet I showed you, but rather in this one, that called the function above, and incorrectly returned the resulting scalar to the caller. Real names changed to protect the innocents :)
The fixed and working version follows:
Back to
Seekers of Perl Wisdom
|
|