Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Platform: Perl >= 5.14.x, AMD64, linux, ubuntu 12.04

I have some embedded perl code which has worked for years using a persistent interpreter with template code from the perlembed docs.

I call a perl function from C which returns a list of assorted perl types:

sub TestSimpleScalars { my $r1 = 40 + 2; my $r2 = 3.14159; my $r3 = "Humpty Dumpty"; my $r4 = [10, 20, 30]; my $r5 = { name => 'Fred', dateOfBirth => '13-Jan-1969' }; return($r1, $r2, undef, $r3, $r4, $r5, 'end list'); }

The C code uses Perl_call_pv(, , G_ARRAY) to ensure the perl code is evaluated in an array context. It then tests the type of each returned item in the list using SvTYPE(). The arrayref and hashref items used to correctly return a type of SVt_PVAV/SVt_PVHV, but now all references simply return the integer type SVt_IV.

Thus whereas I used to get types:

[SvIV, SvNV, SVt_PV, SVt_NULL, SVt_PVAV, SVt_PVHV, SVt_PV]
I now get:
[SvIV, SvNV, SVt_PV, SVt_NULL, SVt_IV, SVt_IV, SVt_PV]

It is as if the perl refs are being interpreted in a scalar context (the value that comes back is the internal ref integer value). This means it is impossible to return complex data structure from perl back to C.

This worked up to 5.10.1 This no longer works on v5.12 upwards (I tested 5.12.4, 5.14.2, 5.16.1)

If anyone has some example code showing call of a perl function that returns a complex data object with arrayref/hashref I would appreciate an example. Maybe I have just missed some magic flag somewhere?


In reply to Perl_call_pv(, , G_ARRAY) returns references as integer type SVt_IV by rogue_tache

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (8)
    As of 2014-08-22 13:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (157 votes), past polls