added methods for size_t and more freearg typemaps around, just in case

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7743 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-27 11:30:14 +00:00
commit 6bb15233ce
8 changed files with 56 additions and 19 deletions

View file

@ -11,10 +11,10 @@
*/
%define %typemaps_cstring(Name, Char,
SWIG_AsCharPtr,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtr,
SWIG_FromCharPtrAndSize)
SWIG_AsCharPtr,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtr,
SWIG_FromCharPtrAndSize)
/* %cstring_input_binary(TYPEMAP, SIZE)
@ -181,16 +181,19 @@
*/
%define Name ## _output_maxsize(TYPEMAP, SIZE)
%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(unsigned long)) (TYPEMAP, SIZE) (unsigned long size) {
if (SWIG_AsVal(unsigned long)($input, &size) != SWIG_OK) {
%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(size_t)) (TYPEMAP, SIZE) (size_t size, Char *buff = 0) {
if (SWIG_AsVal(size_t)($input, &size) != SWIG_OK) {
%argument_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
}
buff= %new_array(size+1, Char);
$2 = %numeric_cast(size, $2_ltype);
$1 = %new_array(size+1, $*1_ltype);
}
$1 = %static_cast(buff,$1_ltype);
}
%typemap(freearg,noblock=1) (TYPEMAP,SIZE) {
if (buff$argnum) %delete_array(buff$argnum);
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) (TYPEMAP,SIZE) {
%append_output(SWIG_FromCharPtr($1));
%delete_array($1);
}
%enddef
@ -208,18 +211,20 @@
*/
%define Name ## _output_withsize(TYPEMAP, SIZE)
%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(unsigned long)) (TYPEMAP, SIZE) (unsigned long n) {
if (SWIG_AsVal(unsigned long)($input, &n) != SWIG_OK) {
%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(size_t)) (TYPEMAP, SIZE) (size_t n, Char *buff = 0, $*2_ltype size) {
if (SWIG_AsVal(size_t)($input, &n) != SWIG_OK) {
%argument_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
}
$1 = %new_array(n+1, $*1_ltype);
$2 = %new_instance($*2_ltype);
*$2 = %numeric_cast(n, $*2_ltype);
buff= %new_array(n+1, Char);
$1 = %static_cast(buff, $1_ltype);
size = %numeric_cast(n,$*2_ltype);
$2 = &size;
}
%typemap(freearg,noblock=1)(TYPEMAP,SIZE) {
if (buff$argnum) %delete_array(buff$argnum);
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtrAndSize) (TYPEMAP,SIZE) {
%append_output(SWIG_FromCharPtrAndSize($1,*$2));
%delete_array($1);
%delete($2);
}
%enddef
@ -240,7 +245,8 @@
%define Name ## _output_allocate(TYPEMAP, RELEASE)
%typemap(in,noblock=1,numinputs=0) TYPEMAP($*1_ltype temp = 0) {
$1 = &temp;
}
}
%typemap(freearg) TYPEMAP "";
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
if (*$1) {
%append_output(SWIG_FromCharPtr(*$1));
@ -268,6 +274,7 @@
%typemap(in,noblock=1,numinputs=0) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn) {
$1 = &temp; $2 = &tempn;
}
%typemap(freearg) (TYPEMAP,SIZE) "";
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtrAndSize)(TYPEMAP,SIZE) {
if (*$1) {
%append_output(SWIG_FromCharPtrAndSize(*$1,*$2));

View file

@ -14,6 +14,7 @@
$1 = &temp;
}
}
%typemap(freearg) const enum SWIGTYPE& "";
%typemap(varin,fragment=SWIG_AsVal_frag(int),noblock=1) enum SWIGTYPE {
if (sizeof(int) != sizeof($1)) {

View file

@ -152,6 +152,24 @@ SWIG_AsVal_dec(bool)(SWIG_Object obj, bool *val)
%ensure_type_fragments(double)
/* size_t */
%fragment(SWIG_From_frag(size_t),"header",fragment=SWIG_From_frag(unsigned long)) {
SWIGINTERNINLINE SWIG_Object
SWIG_From_dec(size_t)(size_t value)
{
return SWIG_From(unsigned long)(value);
}
}
%fragment(SWIG_AsVal_frag(size_t),"header",fragment=SWIG_AsVal_frag(unsigned long)) {
SWIGINTERNINLINE int
SWIG_AsVal_dec(size_t)(SWIG_Object obj, size_t *val)
{
return SWIG_AsVal(unsigned long)(obj, val);
}
}
/* ------------------------------------------------------------
* Generate the typemaps for primitive type

View file

@ -32,6 +32,7 @@
$1 = *ptr;
if (res == SWIG_NEWOBJ) %delete(ptr);
}
%typemap(freearg) Type "";
%typemap(in,fragment=frag) const Type & (int res = 0) {
Type *ptr = (Type *)0;
res = asptr_meth($input, &ptr);

View file

@ -233,6 +233,7 @@
}
$1 = temp;
}
%typemap(freearg) Char [ANY], const Char [ANY] "";
%typemap(in,noblock=1,fragment=#SWIG_AsCharArray) const Char (&)[ANY] (Char temp[$1_dim0])
{
@ -241,6 +242,7 @@
}
$1 = &temp;
}
%typemap(freearg) const Char (&)[ANY] "";
%typemap(out,fragment=#SWIG_FromCharPtrAndSize)
Char [ANY], const Char[ANY]

View file

@ -9,7 +9,6 @@
}
$1 = %reinterpret_cast(argp, $ltype);
}
%typemap(freearg) SWIGTYPE *, SWIGTYPE [] "";
%typemap(in, noblock=1) SWIGTYPE* const& (void *argp, $*ltype temp) {
@ -19,6 +18,7 @@
temp = %reinterpret_cast(argp, $*ltype);
$1 = &temp;
}
%typemap(freearg) SWIGTYPE* const& "";
/* Reference */
%typemap(in, noblock=1) SWIGTYPE & (void *argp) {
@ -28,6 +28,7 @@
if (!argp) { %argument_nullref("$type", $argnum); }
$1 = %reinterpret_cast(argp, $ltype);
}
%typemap(freearg) SWIGTYPE& "";
/* By value */
%typemap(in,noblock=1) SWIGTYPE (void *argp) {
@ -37,6 +38,7 @@
if (!argp) { %argument_nullref("$type", $argnum); }
$1 = *(%reinterpret_cast(argp, $&ltype));
}
%typemap(freearg) SWIGTYPE "";
/* -----------------------------------------------------------------------------
* --- Output arguments ---
@ -327,6 +329,7 @@
%argument_fail(SWIG_TypeError,"$type",$argnum);
}
}
%typemap(freearg) SWIGTYPE (CLASS::*) "";
%typemap(out,noblock=1) SWIGTYPE (CLASS::*) {
%set_output(SWIG_NewMemberObj(%as_voidptr(&$1), sizeof($type), $descriptor));
@ -361,6 +364,7 @@
%argument_fail(SWIG_TypeError,"$type",$argnum);
}
}
%typemap(freearg) SWIGTYPE ((*)(ANY)) "";
%typemap(out, noblock=1) SWIGTYPE ((*)(ANY)) {
%set_output(SWIG_NewFunctionPtrObj((void *)($1), $descriptor));
@ -378,6 +382,7 @@
/* VARARGS_SENTINEL typemap. Used by the %varargs directive. */
%typemap(in,numinputs=0) SWIGTYPE *VARARGS_SENTINEL, SWIGTYPE VARARGS_SENTINEL "";
%typemap(freearg) SWIGTYPE *VARARGS_SENTINEL, SWIGTYPE VARARGS_SENTINEL "";
/* DISOWN typemap */
@ -387,6 +392,7 @@
%argument_fail(SWIG_TypeError,"$type", $argnum);
}
}
%typemap(freearg) SWIGTYPE *DISOWN "";
%typemap(varin,noblock=1) SWIGTYPE *DISOWN {
void *temp = 0;

View file

@ -38,6 +38,7 @@
}
$1 = %static_cast(val,$ltype);
}
%typemap(freearg) Type "";
%typemap(in,noblock=1,fragment=frag) const Type & ($*ltype temp, Type val, int ecode = 0) {
ecode = asval_meth($input, &val);
if (ecode != SWIG_OK) {
@ -46,6 +47,7 @@
temp = %static_cast(val, $*ltype);
$1 = &temp;
}
%typemap(freearg) const Type& "";
%enddef
/* out */

View file

@ -9,7 +9,6 @@
%argument_fail(SWIG_TypeError, "$type", $argnum);
}
}
%typemap(freearg) void * "";
%typemap(in,noblock=1) void * const& ($*ltype temp) {
@ -18,6 +17,7 @@
}
$1 = &temp;
}
%typemap(freearg) void * const& "";
/* out */