Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Inline::C : passing parameters to functions, modifying by reference

by syphilis (Archbishop)
on Jul 23, 2021 at 10:19 UTC ( [id://11135341]=note: print w/replies, xml ) Need Help??


in reply to Inline::C : passing parameters to functions, modifying by reference

Hi bliako,

I sense that there's a bit you could do to simplify the task.
When I run your script I get:
C:\_32\pscrpt\inline>perl bliako.pl Case1: @out ok 1 - Case1: called success. ok 2 - Case1: rows are 5 not ok 3 - Case1 : item 0 is ARRAYref. # Failed test 'Case1 : item 0 is ARRAYref.' # at bliako.pl line 72. Bizarre copy of ARRAY in list assignment at C:/perl-5.34.0/lib/Test/Bu +ilder.pm line 802. # Tests were run but no plan was declared and done_testing() was not s +een. # Looks like your test exited with 255 just after 3.
I therefore wonder "why present us with all of the extra stuff that we don't even get to" ?
Much better, IMO, to consider just the part that's not working. (And then, if needed, proceed to the next part that fails to work when we've fixed the first failure.)

Doing a Devel::Peek::Dump of $out[$i] reveals that it is an array (and not a reference to an array). At least, that's how it looks to me:
ok 1 - Case1: called success. ok 2 - Case1: rows are 5 SV = PVAV(0x7ae098) at 0x33cab0 REFCNT = 1 FLAGS = () ARRAY = 0x2f0d7d8 FILL = 2 MAX = 3 FLAGS = (REAL) Elt No. 0 SV = IV(0x33cad0) at 0x33cae0 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 42 Elt No. 1 SV = IV(0x33cab8) at 0x33cac8 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 42 Elt No. 2 SV = IV(0x33cb30) at 0x33cb40 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 42 not ok 3 - Case1 : item 0 is ARRAYref. # Failed test 'Case1 : item 0 is ARRAYref.'
So the test is reporting correctly.

I'm also a bit puzzled about the involvement of Test/Builder.pm. Do you know what it is it that pulls that module in ?

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Inline::C : passing parameters to functions, modifying by reference
by bliako (Monsignor) on Jul 23, 2021 at 11:13 UTC

    syphilis, I was expecting your call. Thanks.

    You saw that correctly. And the culprit, as per advice from LeoNerd at https://kiwiirc.com/nextclient/#irc://irc.perl.org/#perl (23/07/2021 @ 10:50 server time) is in the filling part: av_push(av, (SV *)av2); should become av_push(av, newRV_noinc((SV *)av2)); . And sv_setsv() should be sv_setrv()

    Which is non-existent but LeoNerd posted this:

    /************************************************************/ /* Monkeypath by LeoNerd to set an arrayref into a scalarref As posted on https://kiwiirc.com/nextclient/#irc://irc.perl.org/#pe +rl at 10:50 23/07/2021 A BIG THANK YOU LeoNerd */ #define HAVE_PERL_VERSION(R, V, S) \ (PERL_REVISION > (R) || (PERL_REVISION == (R) && (PERL_VERSION > ( +V) || (PERL_VERSION == (V) && (PERL_SUBVERSION >= (S)))))) #define sv_setrv(s, r) S_sv_setrv(aTHX_ s, r) static void S_sv_setrv(pTHX_ SV *sv, SV *rv) { sv_setiv(sv, (IV)rv); #if !HAVE_PERL_VERSION(5, 24, 0) SvIOK_off(sv); #endif SvROK_on(sv); } /************************************************************/

    I am posting the full working script as a comment to my question.

    bw, bliako

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-19 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found