Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: xs modifying passed value

by bulk88 (Priest)
on Nov 18, 2012 at 02:03 UTC ( #1004366=note: print w/ replies, xml ) Need Help??


in reply to Re: xs modifying passed value
in thread xs modifying passed value

Considered having the return of MyLib::strToInt be the bool, and the param be the int? Usually subs/funcs return true false, and details of the operation are inplace updates/ pass by reference/ $_[0] = "hello";/*status = 1;/. Or the author of C++ method strToInt did it that way and thats the way you will remember it in Perl? You could also return 2 elements "($truefalse, $theint) = $instance->strToInt();", and have MyLib::strToInt method take only one param (THIS scalar). If the caller in perl doesn't want the int, they dont need to collect it in list context.

edit: With XS/C/Perl internals, the biggest XSUB debugging tool is looking at the .c code. Try posting that. For C code, you should learn how to create post C processor code, then run it through a code formatter. A 7 character named macro taking 1 param, barely or terribly documented, can expand to a screenful of code after 2-5 layers of macros are expanded. To understand why it failed, looking at the post preprocessor output it the only way. Also compile with optimize=debug and symbols, as you said already, you have a C debugger, so thats correct. Also instead of returning 1 bool, or a list, consider returning a hashref, a hashref is probably overkill for this function.


Comment on Re^2: xs modifying passed value
Re^3: xs modifying passed value
by bulk88 (Priest) on Nov 18, 2012 at 07:43 UTC
    Some people for param lists do,
    my %localdog; if(@_ == 2 && ref($_[1]) eq 'HASH') { #named params my $hvref = $_[1]; $localdog{name} = $hvref->{name}; $localdog{color} = $hvref->{color}; } else{ $localdog{name} = $_[1]; $localdog{color} = $_[2]; }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004366]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2015-07-04 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (59 votes), past polls