diff --git a/Lib/common.swg b/Lib/common.swg index ccafa0079..bb02516cc 100644 --- a/Lib/common.swg +++ b/Lib/common.swg @@ -70,6 +70,8 @@ SWIGIMPORT(swig_type_info *) SWIG_TypeDynamicCast(swig_type_info *, void **); SWIGIMPORT(const char *) SWIG_TypeName(const swig_type_info *); SWIGIMPORT(swig_type_info *) SWIG_TypeQuery(const char *); SWIGIMPORT(void) SWIG_TypeClientData(swig_type_info *, void *); +SWIGIMPORT(char *) SWIG_PackData(char *, void *, int); +SWIGIMPORT(char *) SWIG_UnpackData(char *, void *, int); #else @@ -196,6 +198,45 @@ SWIG_TypeClientData(swig_type_info *ti, void *clientdata) { equiv = equiv->next; } } + +/* Pack binary data into a string */ +SWIGRUNTIME(char *) +SWIG_PackData(char *c, void *ptr, int sz) { + static char hex[17] = "0123456789abcdef"; + int i; + unsigned char *u = (unsigned char *) ptr; + register unsigned char uu; + for (i = 0; i < sz; i++,u++) { + uu = *u; + *(c++) = hex[(uu & 0xf0) >> 4]; + *(c++) = hex[uu & 0xf]; + } + return c; +} + +/* Unpack binary data from a string */ +SWIGRUNTIME(char *) +SWIG_UnpackData(char *c, void *ptr, int sz) { + register unsigned char uu = 0; + register int d; + unsigned char *u = (unsigned char *) ptr; + int i; + for (i = 0; i < sz; i++, u++) { + d = *(c++); + if ((d >= '0') && (d <= '9')) + uu = ((d - '0') << 4); + else if ((d >= 'a') && (d <= 'f')) + uu = ((d - ('a'-10)) << 4); + d = *(c++); + if ((d >= '0') && (d <= '9')) + uu |= (d - '0'); + else if ((d >= 'a') && (d <= 'f')) + uu |= (d - ('a'-10)); + *u = uu; + } + return c; +} + #endif #ifdef __cplusplus diff --git a/Lib/perl5/perl5.swg b/Lib/perl5/perl5.swg index 248afa01c..fcb1d3d7e 100644 --- a/Lib/perl5/perl5.swg +++ b/Lib/perl5/perl5.swg @@ -54,6 +54,12 @@ $1 = *argp; } +/* Pointer to a class member */ +%typemap(in) SWIGTYPE (CLASS::*) { + if ((SWIG_ConvertPacked($input, (void *) &$1, sizeof($1_type), $1_descriptor,0)) < 0) { + SWIG_croak("Type error in argument $argnum of $symname. Expected $&1_mangle"); + } +} /* Const primitive references. Passed by value */ @@ -160,6 +166,13 @@ SWIG_MakePtr(ST(argvi++), (void *) $1, ty, $shadow|$owner); } +/* Member pointer */ +%typemap(out) SWIGTYPE (CLASS::*) { + ST(argvi) = sv_newmortal(); + SWIG_MakePackedObj(ST(argvi), (void *) &$1, sizeof($1_type), $1_descriptor); + argvi++; +} + %typemap(out) void ""; /* Typemap for character array returns */ @@ -266,6 +279,15 @@ $1 = *argp; } +/* Member pointer */ +%typemap(varin) SWIGTYPE (CLASS::*) { + char temp[sizeof($1_type)]; + if (SWIG_ConvertPacked($input, (void *) temp, sizeof($1_type), $1_descriptor, 0) < 0) { + croak("Type error in argument $argnum of $symname. Expected $&1_mangle"); + } + memmove((void *) &$1, temp, sizeof($1_type)); +} + /* Const primitive references. Passed by value */ %typemap(varin) const int & (int temp), @@ -390,6 +412,10 @@ %typemap(varout,type="$&1_descriptor") SWIGTYPE "sv_setiv(SvRV($result), (IV) &$1);"; +%typemap(varout,type="$1_descriptor") SWIGTYPE (CLASS::*) { + SWIG_MakePackedObj($result, (void *) &$1, sizeof($1_type), $1_descriptor); +} + /* --- Typemaps for constants --- * /* --- Constants --- */ @@ -585,7 +611,7 @@ XS(SWIG_init) { SWIG_MakePtr(sv, swig_constants[i].pvalue, *(swig_constants[i].ptype),0); break; case SWIG_BINARY: - /* obj = SWIG_NewPackedObj(swig_constants[i].pvalue, swig_constants[i].lvalue, *(swig_constants[i].ptype)); */ + SWIG_MakePackedObj(sv, swig_constants[i].pvalue, swig_constants[i].lvalue, *(swig_constants[i].ptype)); break; default: break; diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index 8d6e09981..9275d1feb 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -126,11 +126,20 @@ extern "C" { SWIG_Perl_ConvertPtr(pPerl, obj, pp, type, flags) # define SWIG_NewPointerObj(p, type, flags) \ SWIG_Perl_NewPointerObj(pPerl, p, type, flags) +# define SWIG_MakePackedObj(sv, p, s, type) \ + SWIG_Perl_MakePackedObj(pPerl, sv, p, s, type) +# define SWIG_ConvertPacked(obj, p, s, type, flags) \ + SWIG_Perl_ConvertPacked(pPerl, obj, p, s, type, flags) + #else # define SWIG_ConvertPtr(obj, pp, type, flags) \ SWIG_Perl_ConvertPtr(obj, pp, type, flags) # define SWIG_NewPointerObj(p, type, flags) \ SWIG_Perl_NewPointerObj(p, type, flags) +# define SWIG_MakePackedObj(sv, p, s, type) \ + SWIG_Perl_MakePackedObj(sv, p, s, type ) +# define SWIG_ConvertPacked(obj, p, s, type, flags) \ + SWIG_Perl_ConvertPacked(obj, p, s, type, flags) #endif /* Perl-specific API */ @@ -166,6 +175,8 @@ extern "C" { SWIGIMPORT(int) SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *, void **, swig_type_info *, int flags); SWIGIMPORT(void) SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *, void *, swig_type_info *, int flags); SWIGIMPORT(SV *) SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *, swig_type_info *, int flags); +SWIGIMPORT(void) SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *, void *, int, swig_type_info *); +SWIGIMPORT(int) SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *, void *, int, swig_type_info *, int flags); SWIGIMPORT(swig_type_info *) SWIG_Perl_TypeCheckRV(SWIG_MAYBE_PERL_OBJECT SV *rv, swig_type_info *ty); SWIGIMPORT(SV *) SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT char *); @@ -295,6 +306,36 @@ SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *ptr, swig_type_info *t, int return result; } +SWIGRUNTIME(void) + SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, int sz, swig_type_info *type) { + char result[1024]; + char *r = result; + if ((2*sz + 1 + strlen(type->name)) > 1000) return; + *(r++) = '_'; + r = SWIG_PackData(r,ptr,sz); + strcpy(r,type->name); + sv_setpv(sv, result); +} + +/* Convert a packed value value */ +SWIGRUNTIME(int) +SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *obj, void *ptr, int sz, swig_type_info *ty, int flags) { + swig_type_info *tc; + char *c = 0; + + if ((!obj) || (!SvOK(obj))) return -1; + c = SvPV(obj, PL_na); + /* Pointer values must start with leading underscore */ + if (*c != '_') return -1; + c++; + c = SWIG_UnpackData(c,ptr,sz); + if (ty) { + tc = SWIG_TypeCheck(c,ty); + if (!tc) return -1; + } + return 0; +} + SWIGRUNTIME(void) SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT const char *error) { if (error) sv_setpv(get_sv("@", TRUE), error); diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index c75a2e2bf..c9548ed45 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -53,10 +53,6 @@ typedef struct swig_const_info { SWIG_Python_addvarlink(p, name, get_attr, set_attr) #define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) \ SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags) -#define SWIG_PackData(c, ptr, sz) \ - SWIG_Python_PackData(c, ptr, sz) -#define SWIG_UnpackData(c, ptr, sz) \ - SWIG_Python_UnpackData(c, ptr, sz) #define SWIG_NewPackedObj(ptr, sz, type) \ SWIG_Python_NewPackedObj(ptr, sz, type) #define SWIG_InstallConstants(d, constants) \ @@ -70,8 +66,6 @@ SWIGIMPORT(void *) SWIG_Python_MustGetPtr(PyObject *, swig_type_info SWIGIMPORT(PyObject *) SWIG_Python_newvarlink(void); SWIGIMPORT(void) SWIG_Python_addvarlink(PyObject *, char *, PyObject *(*)(void), int (*)(PyObject *)); SWIGIMPORT(int) SWIG_Python_ConvertPacked(PyObject *, void *, int sz, swig_type_info *, int); -SWIGIMPORT(char *) SWIG_Python_PackData(char *c, void *, int); -SWIGIMPORT(char *) SWIG_Python_UnpackData(char *c, void *, int); SWIGIMPORT(PyObject *) SWIG_Python_NewPackedObj(void *, int sz, swig_type_info *); SWIGIMPORT(void) SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]); @@ -182,44 +176,6 @@ SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int v->vars = gv; } -/* Pack binary data into a string */ -SWIGRUNTIME(char *) -SWIG_Python_PackData(char *c, void *ptr, int sz) { - static char hex[17] = "0123456789abcdef"; - int i; - unsigned char *u = (unsigned char *) ptr; - register unsigned char uu; - for (i = 0; i < sz; i++,u++) { - uu = *u; - *(c++) = hex[(uu & 0xf0) >> 4]; - *(c++) = hex[uu & 0xf]; - } - return c; -} - -/* Unpack binary data from a string */ -SWIGRUNTIME(char *) -SWIG_Python_UnpackData(char *c, void *ptr, int sz) { - register unsigned char uu = 0; - register int d; - unsigned char *u = (unsigned char *) ptr; - int i; - for (i = 0; i < sz; i++, u++) { - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu = ((d - '0') << 4); - else if ((d >= 'a') && (d <= 'f')) - uu = ((d - ('a'-10)) << 4); - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu |= (d - '0'); - else if ((d >= 'a') && (d <= 'f')) - uu |= (d - ('a'-10)); - *u = uu; - } - return c; -} - /* Convert a pointer value */ SWIGRUNTIME(int) SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) { diff --git a/Lib/python/python.swg b/Lib/python/python.swg index b49a74433..e993e6ddb 100644 --- a/Lib/python/python.swg +++ b/Lib/python/python.swg @@ -10,6 +10,8 @@ #include "Python.h" %} + + %insert(runtime) "precommon.swg"; %insert(runtime) "common.swg"; // Common type-checking code %insert(runtime) "pyrun.swg"; // Python run-time code diff --git a/Lib/ruby/rubydec.swg b/Lib/ruby/rubydec.swg index d51edfb69..5789b9621 100644 --- a/Lib/ruby/rubydec.swg +++ b/Lib/ruby/rubydec.swg @@ -11,8 +11,6 @@ SWIGIMPORT(char *) SWIG_Ruby_MangleStr(VALUE); SWIGIMPORT(int) SWIG_Ruby_ConvertPtr(VALUE, void**, swig_type_info *, int); SWIGIMPORT(void *) SWIG_Ruby_MustGetPtr(VALUE, swig_type_info *, int, int); SWIGIMPORT(int) SWIG_Ruby_CheckConvert(VALUE, swig_type_info *); -SWIGIMPORT(char *) SWIG_Ruby_PackData(char *c, void *ptr, int sz); -SWIGIMPORT(char *) SWIG_Ruby_UnpackData(char *c, void *ptr, int sz); SWIGIMPORT(VALUE) SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type); SWIGIMPORT(void) SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty, int flags); diff --git a/Lib/ruby/rubydef.swg b/Lib/ruby/rubydef.swg index a0ffa8368..068efc7f9 100644 --- a/Lib/ruby/rubydef.swg +++ b/Lib/ruby/rubydef.swg @@ -136,44 +136,6 @@ SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty) return SWIG_TypeCheck(c,ty) != 0; } -/* Pack binary data into a string */ -SWIGRUNTIME(char *) -SWIG_Ruby_PackData(char *c, void *ptr, int sz) { - static char hex[17] = "0123456789abcdef"; - int i; - unsigned char *u = (unsigned char *) ptr; - register unsigned char uu; - for (i = 0; i < sz; i++,u++) { - uu = *u; - *(c++) = hex[(uu & 0xf0) >> 4]; - *(c++) = hex[uu & 0xf]; - } - return c; -} - -/* Unpack binary data from a string */ -SWIGRUNTIME(char *) -SWIG_Ruby_UnpackData(char *c, void *ptr, int sz) { - register unsigned char uu = 0; - register int d; - unsigned char *u = (unsigned char *) ptr; - int i; - for (i = 0; i < sz; i++, u++) { - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu = ((d - '0') << 4); - else if ((d >= 'a') && (d <= 'f')) - uu = ((d - ('a'-10)) << 4); - d = *(c++); - if ((d >= '0') && (d <= '9')) - uu |= (d - '0'); - else if ((d >= 'a') && (d <= 'f')) - uu |= (d - ('a'-10)); - *u = uu; - } - return c; -} - SWIGRUNTIME(VALUE) SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) { char result[1024];