[perl5] Use sv_setpvn() to set a scalar from a pointer and length

- patch from SF#174460 by "matsubaray".


git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9937 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Olly Betts 2007-09-17 23:24:11 +00:00
parent c836c81acb
commit e2d7f303b8
6 changed files with 28 additions and 13 deletions

View File

@ -1,6 +1,10 @@
Version 1.3.32 (in progress)
============================
09/17/2007: olly
[perl5] Use sv_setpvn() to set a scalar from a pointer and length
- patch from SF#174460 by "matsubaray".
09/17/2007: olly
When wrapping C++ code, generate code which uses
std::string::assign(PTR, LEN) rather than assigning

View File

@ -0,0 +1,8 @@
%module li_cdata_carrays
%include <carrays.i>
%array_class(int, intArray);
%include <cdata.i>
%cdata(int);

View File

@ -16,11 +16,12 @@ CPP_TEST_CASES += \
primitive_types \
li_cdata \
li_cstring \
li_cdata_carrays \
C_TEST_CASES += \
li_cdata \
li_cstring \
li_cdata_carrays \
include $(srcdir)/../common.mk

View File

@ -0,0 +1,11 @@
use li_cdata_carrays;
$a = li_cdata_carrays::intArray->new(5);
for (0..4) {
$a->setitem($_, $_**2);
}
$x = pack q{I5}, map $_**2, (0..4);
$y = li_cdata_carrays::cdata_int($a->cast, 5);
if ( $x ne $y ) {
die "$x vs $y";
}

View File

@ -28,10 +28,9 @@ SWIG_From_dec(jstring)(jstring val)
if (!len) {
sv_setsv(obj, &PL_sv_undef);
} else {
char *tmp = %new_array(len + 1, char);
char *tmp = %new_array(len, char);
JvGetStringUTFRegion(val, 0, len, tmp);
tmp[len] = 0;
sv_setpv(obj, tmp);
sv_setpvn(obj, tmp, len);
SvUTF8_on(obj);
%delete_array(tmp);
}

View File

@ -44,15 +44,7 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
SV *obj = sv_newmortal();
if (carray) {
if (size && (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);
%delete_array(tmp);
}
sv_setpvn(obj, carray, size);
} else {
sv_setsv(obj, &PL_sv_undef);
}