From: SourceForge.net <no...@so...> - 2011-10-24 23:42:17
|
Bugs item #3423119, was opened at 2011-10-13 18:51 Message generated for change (Comment added) made by talby You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=3423119&group_id=1645 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: perl Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: dgbustos (dgbustos1) Assigned to: Robert Stone (talby) Summary: Overload wrapper receives wrong number of arguments Initial Comment: My function had three parameters, the last of which had a default value. SWIG 1.3.40 generated a three-argument wrapper, a two-argument wrapper, and a dispatch wrapper which calls one of them. When I tried to call the function with three arguments, the three-argument wrapper croaked with a "Usage" RuntimeError, as though it had received the wrong number of arguments. Wrapping the arguments in scalar() prevented this. I think the problem is that SWIG's Perl module dispatches to the overloaded wrappers with ++PL_markstack_ptr; SWIG_CALLXS(function); return Incrementing PL_markstack_ptr essentially pushes the value above the top of the stack. Since the called function pops the mark off the mark stack and sets ax to the next index (via dXSARGS), it needs the top of the mark stack to be the stack index of the first argument minus one, so I presume this usually works because that's what Perl pushes before calling the dispatch wrapper. But sometimes the dispatch wrapper's code can modify that value (not sure why). And in that case the called function pops the wrong mark and thinks it has the wrong number of arguments. I think a more robust way to do this is to push the mark explicitly with PUSHMARK(MARK). And I suspect this should be done in SWIG_CALLXS() rather than hard-coded in PERL5::functionWrapper(). ---------------------------------------------------------------------- >Comment By: Robert Stone (talby) Date: 2011-10-24 23:42 Message: Quick fix was added in r12828. I intend to follow this up later with a more robust solution. I believe this code is currently reaching beneath the documented perl api, and so is likely to have problems again later. ---------------------------------------------------------------------- Comment By: dgbustos (dgbustos1) Date: 2011-10-22 12:24 Message: Since the dispatcher is trying to invoke the function with its argument stack rather than repushing all of the arguments into a new frame, this seems like a tail call to me. So yes, if SWIG_CALLXS() is used anywhere where a new frame is set up, then PUSHMARK(MARK) should not be added to it. ---------------------------------------------------------------------- Comment By: Robert Stone (talby) Date: 2011-10-22 01:36 Message: That's a great sample, the issue persists in SWIG trunk. It looks like that dispatch function is attempting to implement a kind of goto. The proposed update is clearly an improvement, so switching from ++PL_markstack_ptr to PUSHMARK(MARK) looks like an advantage, However I hesitate to modify SWIG_CALLXS() until I understand the problem more completely. I've actually tried to implement jump routines in XS for other projects and found unusual complications like this. I've been meaning to sort out what was going on, looks like I have the excuse now. ---------------------------------------------------------------------- Comment By: dgbustos (dgbustos1) Date: 2011-10-14 18:31 Message: It seems a structure and a loop are necessary. With swig-3423119-example.tgz and swig -c++ -perl mod.swg perl Makefile.PL make perl -I blib/arch/auto/mod script.pl I get "RuntimeError Usage: func(a,b);" This is with SWIG 1.3.40 and perl 5.10.1. ---------------------------------------------------------------------- Comment By: Robert Stone (talby) Date: 2011-10-14 16:12 Message: I haven't dug into this deeply yet, but I can't reproduce the problem with simple attempts. Do you have an example caller from Perl which exposes exposes this argument count mismatch? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=101645&aid=3423119&group_id=1645 |