Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
In response to XS on 64-bit: Warning from sv_vsetpvf call almut posted some code that led me to the following Inline::C script:
use warnings; use Inline C => <<'EOC'; void vatest__(char* format, va_list* args) { char buf[1024]; vsprintf(buf, format, *args); errno = 0; // "Success" perror(buf); } void vatest_(char* format, va_list* args) { vatest__(format, args); } void vatest(char* format, ...) { va_list args; va_start (args, format); vatest_(format, &args); va_end (args); } SV * foo () { char* msg0 = "vatest"; char* msg1 = "foo"; char* msg2 = "bar"; double d = 12.345; unsigned long l = 1234567890; vatest("%s %s", msg0, msg1); vatest("%s %s %s %u %f", msg0, msg1, msg2, l, d); return newSViv(0); } EOC foo();
which outputs (on Win32):
vatest foo: No error vatest foo bar 1234567890 12.345000: No error
which is correct and as expected.

But then I got to wondering whether vatest() could be called directly from perl - ie, instead of having the perl section of the above script do foo(); have it do something like vatest('%s %s', 'foo', 'bar'); which would output foo bar: No error.
But, of course, that doesn't work - and I'm unable to find a way of making it work.

So, is there a way of accessing the XSub vatest() directly from perl (with either XS or Inline::C) ? I'm pretty sure there isn't ... but I'm so often wrong. Faik, there could well be some clever typemapping (or other technique) that makes it possible.


In reply to XS/Inline::C and ellipsis syntax by syphilis

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

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

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (10)
    As of 2015-12-01 16:04 GMT
    Find Nodes?
      Voting Booth?

      My keyboard shows this many letters:

      Results (18 votes), past polls