mirror of https://github.com/swig/swig
[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:
parent
c836c81acb
commit
e2d7f303b8
|
@ -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
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
%module li_cdata_carrays
|
||||
|
||||
%include <carrays.i>
|
||||
%array_class(int, intArray);
|
||||
|
||||
%include <cdata.i>
|
||||
|
||||
%cdata(int);
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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";
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue