coyocanid has asked for the wisdom of the Perl Monks concerning the following question:

Hello Honored Geschwistern,

I am working on a perl XS project and would like to use unpack in the XS/C portion of the code. (Using pack in the perl portion seems to do what I want).

I'm reading the API documents for unpackstring and have some questions questions

unpackstring

The engine implementing the unpack() Perl function.

Using the template pat..patend, this function unpacks the string s..strend into a number of mortal SVs, which it pushes onto the perl argument (@_) stack (so you will need to issue a "PUTBACK" before and "SPAGAIN" after the call to this function). It returns the number of pushed elements.

The strend and patend pointers should point to the byte following the last character of each string.

Although this function returns its values on the perl argument stack, it doesn't take any parameters from that stack (and thus in particular there's no need to do a PUSHMARK before calling it, unlike "call_pv" for example).

I32 unpackstring(const char *pat, const char *patend, const char *s, const char *strend, U32 flags)

Replies are listed 'Best First'.
Re: XS unpackstring, flags and useage
by BrowserUk (Patriarch) on May 25, 2018 at 02:00 UTC

    It does/can contain:

    /* flags (note that type modifiers can also be used as flags!) */ #define FLAG_WAS_UTF8 0x40 #define FLAG_PARSE_UTF8 0x20 /* Parse as utf8 */ #define FLAG_UNPACK_ONLY_ONE 0x10 #define FLAG_DO_UTF8 0x08 /* The underlying string is utf8 + */ #define FLAG_SLASH 0x04 #define FLAG_COMMA 0x02 #define FLAG_PACK 0x01

    See Perl_unpackstring in pp_Pack.c

    At a cursory glance, the only useful input value seems to be FLAG_DO_UTF8, all the others are set internally, and even that seems to be checked and set if need internally.

    Ie. set to 0 and let it work it out until you need to know more.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
    In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit