#181 [perl] perlstrings.swg use sv_setpvn() to handle binary data



binary data cannot be used in perlstrings.swg
I believe the block

if (carray[size - 1] == 0) {
sv_setpv(obj, carray);
} else {
char *tmp = %new_array(size + 1, char);
memcpy(tmp, carray, size);
tmp[size] = 0;
sv_setpv(obj, tmp);

should be substituted by

sv_setpvn(obj, carray, size);

This works for me.
sv_setpv() uses strlen to compute the length of tmp.
The real size given by parameter is ignored.
sv_setpvn() has a third parameter for the size.

See also "Extending and Embedding Perl",
Tim Jennes & Simon Cozens, p. 121.

Regards Chris


  • cholland

    cholland - 2007-06-20
    • priority: 5 --> 8
  • Olly Betts

    Olly Betts - 2007-06-21

    Logged In: YES
    Originator: NO

    Please don't just bump up the priority arbitrarily.

    If you want to increase the chance that somebody with SWIG/Perl knowledge looks at your report sooner, I'd suggest attaching a patch for your proposed change rather than trying to describe it (generate a patch with "diff -ru ORIGINAL_SWIG_TREE PATCHED_SWIG_TREE > patchfile").

    Also, run the SWIG testsuite (make check-perl5-test-suite) with and without your patch - if all the tests which passed before still pass, say so in the report. Also say if it fixes any tests which failed before!

  • Olly Betts

    Olly Betts - 2007-06-21
    • priority: 8 --> 5
  • Olly Betts

    Olly Betts - 2007-09-17
    • status: open --> closed-duplicate
  • Olly Betts

    Olly Betts - 2007-09-17

    Logged In: YES
    Originator: NO

    #1744603 contains an actual patch, testcases, and reports of test results, so closing this bug in favour of that one.


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks