And now to your belated and unannounced update.

you haven't ruled out doing something like $pascal_bytes = chr(length($bytes)) . $bytes;. For long enough strings, it upgrades without calling upgrade and without Perl assigning any meaning to the string.

That is wrong in so many ways.

First, I conclude that you are referring to this:

C:\test>p1 use Devel::Peek;; sub toPascal{ return chr( length $_[0] ) . $_[0] };; Dump toPascal( 'x' x $_ ) for 255, 256;; SV = PV(0x28d280) at 0x3c599e0 REFCNT = 1 FLAGS = (TEMP,POK,pPOK) PV = 0x3cb28f8 "\377xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxx CUR = 256 LEN = 264 SV = PV(0x3c3aa30) at 0x3c599c8 REFCNT = 1 FLAGS = (TEMP,POK,pPOK,UTF8) PV = 0x3cb2a28 "\304\200xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +xxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"] CUR = 258 LEN = 264

Meaning has been assigned. Note the UTF8 flag is set in the second example.

But then, it makes no sense to try and create Pascal strings longer than 255 bytes, because P-strings are defined as being prefixed with a length byte.

But even if that where not the case--if length could be of any size--using SvPVbytes() wouldn't help any. Because unless the XS routine was specifically designed to work with this non-native encoding, its never going to do the right thing:

SV *func( SV *first, SV *second ) { return sv_catsv( first, second ); }

Just another red-herring.


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".
In the absence of evidence, opinion is indistinguishable from prejudice.
"I'd rather go naked than blow up my ass"

In reply to Re^25: Interleaving bytes in a string quickly by BrowserUk
in thread Interleaving bytes in a string quickly by BrowserUk

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!
  • 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, details, 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, summary, 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.