Bugs item #3423119, was opened at 2011-10-13 14:51
Message generated for change (Comment added) made by dgbustos1
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: dgbustos (dgbustos1)
Date: 2011-10-14 14: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 12: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

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-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

Community

Help

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

I agree to receive quotes, newsletters and other information from sourceforge.net and its partners regarding IT services and products. I understand that I can withdraw my consent at any time. Please refer to our Privacy Policy or Contact Us for more details