diff --git a/Lib/perl5/noembed.h b/Lib/perl5/noembed.h index 92a51aa60..d4da7b6b1 100644 --- a/Lib/perl5/noembed.h +++ b/Lib/perl5/noembed.h @@ -70,4 +70,10 @@ #ifdef rewind #undef rewind #endif +#ifdef free + #undef free +#endif +#ifdef malloc + #undef malloc +#endif diff --git a/Lib/perl5/perl5.swg b/Lib/perl5/perl5.swg index b66446e02..50f2c98af 100644 --- a/Lib/perl5/perl5.swg +++ b/Lib/perl5/perl5.swg @@ -24,11 +24,6 @@ * ------------------------------------------------------------ */ %include -/* ------------------------------------------------------------ - * Look for user fragments file. - * ------------------------------------------------------------ */ -%include "perlfragments.swg" - /* ------------------------------------------------------------ * Typemap specializations * ------------------------------------------------------------ */ diff --git a/Lib/perl5/perlmacros.swg b/Lib/perl5/perlmacros.swg index 7d7ba440d..4917f6efc 100644 --- a/Lib/perl5/perlmacros.swg +++ b/Lib/perl5/perlmacros.swg @@ -1,17 +1,2 @@ -/* - in Perl we need to pass the CPerl value, sometimes, - so, we define decl/call macros as needed. -*/ - - -#define SWIG_ASPTR_DECL_ARGS SWIG_PERL_DECL_ARGS_2 -#define SWIG_ASPTR_CALL_ARGS SWIG_PERL_CALL_ARGS_2 - -#define SWIG_ASVAL_DECL_ARGS SWIG_PERL_DECL_ARGS_2 -#define SWIG_ASVAL_CALL_ARGS SWIG_PERL_CALL_ARGS_2 - -#define SWIG_FROM_DECL_ARGS SWIG_PERL_DECL_ARGS_1 -#define SWIG_FROM_CALL_ARGS SWIG_PERL_CALL_ARGS_1 - %include diff --git a/Lib/perl5/perlprimtypes.swg b/Lib/perl5/perlprimtypes.swg index 6735c0107..4a87c45a4 100644 --- a/Lib/perl5/perlprimtypes.swg +++ b/Lib/perl5/perlprimtypes.swg @@ -3,31 +3,6 @@ * ------------------------------------------------------------ */ -/* boolean */ - -%fragment(SWIG_From_frag(bool),"header") { -SWIGINTERN SV * -SWIG_From_dec(bool)(bool value) -{ - SV *obj = sv_newmortal(); - sv_setiv(obj, value ? 1 : 0); - return obj; -} -} - -%fragment(SWIG_AsVal_frag(bool),"header",fragment=SWIG_AsVal_frag(long)) { -SWIGINTERN int -SWIG_AsVal_dec(bool)(SV *obj, bool *val) -{ - long v; - if (SWIG_AsVal(long)(obj, val ? &v : 0) == SWIG_OK) { - if (val) *val = v ? true : false; - return SWIG_OK; - } - return SWIG_TypeError; -} -} - /* long */ %fragment(SWIG_From_frag(long),"header") { @@ -40,7 +15,6 @@ SWIG_From_dec(long)(long value) } } - %fragment(SWIG_AsVal_frag(long),"header") { SWIGINTERN int SWIG_AsVal_dec(long)(SV *obj, long* val) @@ -65,7 +39,6 @@ SWIG_From_dec(unsigned long)(unsigned long value) } } - %fragment(SWIG_AsVal_frag(unsigned long),"header") { SWIGINTERN int SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val) @@ -133,7 +106,6 @@ SWIG_AsVal_dec(long long)(SV *obj, long long *val) } } - /* unsigned long long */ %fragment(SWIG_From_frag(unsigned long long),"header", @@ -205,5 +177,3 @@ SWIG_AsVal_dec(double)(SV *obj, double *val) return SWIG_TypeError; } } - - diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index 8213a6796..f6ac26cb9 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -7,7 +7,7 @@ * ************************************************************************/ #ifdef PERL_OBJECT -#define SWIG_PERL_OBJECT_DECL CPerlObj *pPerl, +#define SWIG_PERL_OBJECT_DECL CPerlObj *pPerl SWIGUNUSED, #define SWIG_PERL_OBJECT_CALL pPerl, #else #define SWIG_PERL_OBJECT_DECL diff --git a/Lib/perl5/perlruntime.swg b/Lib/perl5/perlruntime.swg index 9291d49c2..691a9a67f 100644 --- a/Lib/perl5/perlruntime.swg +++ b/Lib/perl5/perlruntime.swg @@ -4,10 +4,6 @@ #include #include -/* Get rid of free and malloc defined by perl */ -#undef free -#undef malloc - #ifndef pTHX_ #define pTHX_ #endif @@ -44,7 +40,7 @@ typedef int (CPerlObj::*SwigMagicFuncHack)(SV *, MAGIC *); #define SWIGCLASS_STATIC #else #define MAGIC_PPERL -#define SWIGCLASS_STATIC static +#define SWIGCLASS_STATIC static SWIGUNUSED #ifndef MULTIPLICITY #define SWIG_MAGIC(a,b) (SV *a, MAGIC *b) typedef int (*SwigMagicFunc)(SV *, MAGIC *); diff --git a/Lib/perl5/perlstrings.swg b/Lib/perl5/perlstrings.swg index c1b29b5f4..07167b67f 100644 --- a/Lib/perl5/perlstrings.swg +++ b/Lib/perl5/perlstrings.swg @@ -42,7 +42,20 @@ SWIGINTERNINLINE SV * SWIG_FromCharPtrAndSize(const char* carray, size_t size) { SV *obj = sv_newmortal(); - sv_setpv(obj, carray); + if (size && carray) { + 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); + %delete(tmp); + } + } else { + sv_setpv(obj, 0); + } return obj; } } + diff --git a/Lib/perl5/perltypemaps.swg b/Lib/perl5/perltypemaps.swg index fb993a9ed..0c6abe39f 100644 --- a/Lib/perl5/perltypemaps.swg +++ b/Lib/perl5/perltypemaps.swg @@ -1,44 +1,85 @@ -/* ----------------------------------------------------------------------------- - * Typemap specializations - * ----------------------------------------------------------------------------- */ +/* ------------------------------------------------------------ + * Typemap specializations for Perl + * ------------------------------------------------------------ */ -/* no director supported in Perl */ +/* ------------------------------------------------------------ + * Fragment section + * ------------------------------------------------------------ */ + +/* + in Perl we need to pass the CPerlObj value, sometimes, so, we define + the decl/call macros as needed. +*/ + +#define SWIG_ASPTR_DECL_ARGS SWIG_PERL_DECL_ARGS_2 +#define SWIG_ASPTR_CALL_ARGS SWIG_PERL_CALL_ARGS_2 + +#define SWIG_ASVAL_DECL_ARGS SWIG_PERL_DECL_ARGS_2 +#define SWIG_ASVAL_CALL_ARGS SWIG_PERL_CALL_ARGS_2 + +#define SWIG_FROM_DECL_ARGS SWIG_PERL_DECL_ARGS_1 +#define SWIG_FROM_CALL_ARGS SWIG_PERL_CALL_ARGS_1 + + +/* Include fundamental fragemt definitions */ +%include + +/* Look for user fragments file. */ +%include "perlfragments.swg" + +/* Perl fragments for primitive types */ +%include + +/* Perl fragments for char* strings */ +%include + + +/* ------------------------------------------------------------ + * Unified typemap section + * ------------------------------------------------------------ */ + +/* No director supported in Perl */ #ifdef SWIG_DIRECTOR_TYPEMAPS #undef SWIG_DIRECTOR_TYPEMAPS #endif +/* Perl types */ +#define SWIG_Object SV * -/* ----------------------------------------------------------------------------- - * Basic definitions - * - * ----------------------------------------------------------------------------- */ - +/* Perl $shadow flag */ #define %newpointer_flags $shadow #define %newinstance_flags $shadow -#define SWIG_Object SV * -#define VOID_Object $result; argvi=0 -#define %set_output(obj) $result = obj; argvi++ -#define %append_output(obj) if (argvi >= items) EXTEND(sp,1); %set_output(obj) -#define %set_varoutput(obj) sv_setsv($result,obj); -#define %raise(obj, type, desc) sv_setsv(perl_get_sv("@", TRUE), obj); croak(Nullch) -%define %set_constant(name, obj) { +/* Complete overload of the output/constant/exception macros */ + +/* output */ +%define %set_output(obj) + $result = obj; + argvi++ %enddef + +/* append output */ +%define %append_output(obj) + if (argvi >= items) { + EXTEND(sp,1); + } + %set_output(obj) %enddef + +/* variable output */ +%define %set_varoutput(obj) sv_setsv($result,obj) %enddef + +/* constant */ +%define %set_constant(name, obj) %begin_block SV *sv = get_sv((char*) SWIG_prefix name, TRUE | 0x2); sv_setsv(sv, obj); SvREADONLY_on(sv); -} -%enddef +%end_block %enddef +/* raise exception */ +%define %raise(obj, type, desc) + sv_setsv(perl_get_sv("@", TRUE), obj); + croak(Nullch) %enddef -/* ----------------------------------------------------------------------------- - * All the typemaps - * ----------------------------------------------------------------------------- */ - - -%include -%include - +/* Include the unified typemap library */ %include - diff --git a/Lib/python/pyswigtype.swg b/Lib/python/pyswigtype.swg deleted file mode 100644 index fcecbdcb6..000000000 --- a/Lib/python/pyswigtype.swg +++ /dev/null @@ -1,9 +0,0 @@ -/* ------------------------------------------------------------ - * --- Consttab --- needed for callbacks, it should be removed later. - * ------------------------------------------------------------ */ - -%typemap(consttab) SWIGTYPE ((*)(ANY)) -{ SWIG_PY_POINTER, (char*)"$symname", 0, 0, (void *)($value), &$descriptor } - -%typemap(constcode) SWIGTYPE ((*)(ANY)) ""; - diff --git a/Lib/python/python.swg b/Lib/python/python.swg index 937bca393..3b22579f6 100644 --- a/Lib/python/python.swg +++ b/Lib/python/python.swg @@ -24,11 +24,6 @@ * ------------------------------------------------------------ */ %include -/* ------------------------------------------------------------ - * Look for user fragments file. - * ------------------------------------------------------------ */ -%include "pyfragments.swg" - /* ------------------------------------------------------------ * Typemap specializations * ------------------------------------------------------------ */ diff --git a/Lib/python/pytypemaps.swg b/Lib/python/pytypemaps.swg index 08d52b9ae..c32c87c67 100644 --- a/Lib/python/pytypemaps.swg +++ b/Lib/python/pytypemaps.swg @@ -1,45 +1,79 @@ -/* ----------------------------------------------------------------------------- - * Typemap specializations - * ----------------------------------------------------------------------------- */ +/* ------------------------------------------------------------ + * Typemap specializations for Python + * ------------------------------------------------------------ */ + +/* ------------------------------------------------------------ + * Fragment section + * ------------------------------------------------------------ */ +/* bool is dangerous in Python, change precedence */ +#undef SWIG_TYPECHECK_BOOL +%define SWIG_TYPECHECK_BOOL 10000 %enddef + +/* Include fundamental fragemt definitions */ +%include + +/* Look for user fragments file. */ +%include "pyfragments.swg" + +/* Python fragments for fundamental types */ +%include + +/* Python fragments for char* strings */ +%include + +/* Backward compatibility output helper */ +%fragment("t_output_helper","header") %{ +#define t_output_helper SWIG_Python_AppendOutput +%} + + +/* ------------------------------------------------------------ + * Unified typemap section + * ------------------------------------------------------------ */ /* directors are supported in Python */ #ifndef SWIG_DIRECTOR_TYPEMAPS #define SWIG_DIRECTOR_TYPEMAPS #endif -/* bool is dangerous in Python -> C++, change precedence */ -#undef SWIG_TYPECHECK_BOOL -%define SWIG_TYPECHECK_BOOL 10000 %enddef - - -/* ----------------------------------------------------------------------------- - * Basic definitions - * ----------------------------------------------------------------------------- */ +/* Python types */ #define SWIG_Object PyObject * #define VOID_Object (Py_INCREF(Py_None) ? Py_None : 0) +/* Overload of the output/constant/exception/dirout handling */ + +/* append output */ #define SWIG_AppendOutput(result,obj) SWIG_Python_AppendOutput(result, obj) -#define SWIG_SetConstant(name, obj) %block(PyObject *_obj = obj; PyDict_SetItemString(d, name, _obj); Py_DECREF(_obj)) -#define SWIG_Raise(obj, type, desc) PyObject *_obj = obj; PyErr_SetObject(SWIG_Python_ExceptionType(desc), _obj); Py_DECREF(_obj) -#define SWIG_DirOutFail(code, msg) Swig::DirectorTypeMismatchException::raise(SWIG_ErrorType(code), msg) + +/* set constant */ +%define %set_constant(name, obj) %begin_block + PyObject *_obj = obj; + PyDict_SetItemString(d, name, _obj); + Py_DECREF(_obj); +%end_block %enddef + +/* raise */ +%define %raise(obj, type, desc) + PyObject *_obj = obj; + PyErr_SetObject(SWIG_Python_ExceptionType(desc), _obj); + Py_DECREF(_obj) %enddef -/* ----------------------------------------------------------------------------- - * All the typemaps - * ----------------------------------------------------------------------------- */ - -%include -%include +/* Include the unified typemap library */ %include -/* fix for callbacks */ -%include -/* ----------------------------------------------------------------------------- - * Backward compatibility output helper - * ----------------------------------------------------------------------------- */ -%fragment("t_output_helper","header") %{ -#define t_output_helper SWIG_Python_AppendOutput -%} +/* ------------------------------------------------------------ + * Python extra typemaps + * ------------------------------------------------------------ */ + +/* Consttab, needed for callbacks, it should be removed later */ + +%typemap(consttab) SWIGTYPE ((*)(ANY)) +{ SWIG_PY_POINTER, (char*)"$symname", 0, 0, (void *)($value), &$descriptor } + +%typemap(constcode) SWIGTYPE ((*)(ANY)) ""; + + diff --git a/Lib/python/typemaps.i b/Lib/python/typemaps.i index b367ddcda..1f9b9c432 100644 --- a/Lib/python/typemaps.i +++ b/Lib/python/typemaps.i @@ -1,4 +1 @@ %include - - - diff --git a/Lib/ruby/ruby.swg b/Lib/ruby/ruby.swg index dcfaf49e4..d0194bd35 100644 --- a/Lib/ruby/ruby.swg +++ b/Lib/ruby/ruby.swg @@ -24,11 +24,6 @@ * ------------------------------------------------------------ */ %include -/* ------------------------------------------------------------ - * Look for user fragments file. - * ------------------------------------------------------------ */ -%include "rubyfragments.swg" - /* ------------------------------------------------------------ * Typemap specializations * ------------------------------------------------------------ */ diff --git a/Lib/ruby/rubyprimtypes.swg b/Lib/ruby/rubyprimtypes.swg index f1969cd1a..1cf59873a 100644 --- a/Lib/ruby/rubyprimtypes.swg +++ b/Lib/ruby/rubyprimtypes.swg @@ -30,7 +30,7 @@ SWIGINTERN VALUE SWIG_AUX_##Method##(VALUE *args) %fragment(SWIG_From_frag(bool),"header") { SWIGINTERNINLINE VALUE - SWIG_From_dec(bool)(bool value) +SWIG_From_dec(bool)(bool value) { return value ? Qtrue : Qfalse; } diff --git a/Lib/ruby/rubytypemaps.swg b/Lib/ruby/rubytypemaps.swg index 7110b80bb..7a6d03444 100644 --- a/Lib/ruby/rubytypemaps.swg +++ b/Lib/ruby/rubytypemaps.swg @@ -1,40 +1,51 @@ -/* ----------------------------------------------------------------------------- - * Typemap specializations - * ----------------------------------------------------------------------------- */ +/* ------------------------------------------------------------ + * Typemap specializations for Ruby + * ------------------------------------------------------------ */ +/* ------------------------------------------------------------ + * Fragment section + * ------------------------------------------------------------ */ -/* directors are supported in Ruby */ +/* Include fundamental fragemt definitions */ +%include + +/* Look for user fragments file. */ +%include "rubyfragments.swg" + +/* Ruby fragments for primitive types */ +%include + +/* Ruby fragments for char* strings */ +%include + +/* Backward compatibility output helper */ +%fragment("output_helper","header") %{ +#define output_helper SWIG_Ruby_AppendOutput +%} + +/* ------------------------------------------------------------ + * Unified typemap section + * ------------------------------------------------------------ */ + +/* Directors are supported in Ruby */ #ifndef SWIG_DIRECTOR_TYPEMAPS #define SWIG_DIRECTOR_TYPEMAPS #endif -/* ----------------------------------------------------------------------------- - * Basic definitions - * ----------------------------------------------------------------------------- */ +/* Ruby types */ +#define SWIG_Object VALUE +#define VOID_Object Qnil + +/* Ruby $track flag */ #define %convertptr_flags $track #define %newpointer_flags $track #define %newinstance_flags $track -#define SWIG_Object VALUE -#define VOID_Object Qnil - +/* Simple overload of the output/constant/exception handling */ #define SWIG_AppendOutput(result,obj) SWIG_Ruby_AppendOutput(result, obj) #define SWIG_SetConstant(name, obj) rb_define_const($module, name, obj) #define SWIG_Raise(obj, type, desc) rb_exc_raise(rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(obj))) -#define SWIG_DirOutFail(code, msg) Swig::DirectorTypeMismatchException::raise(SWIG_ErrorType(code), msg) - -/* ----------------------------------------------------------------------------- - * All the typemaps - * ----------------------------------------------------------------------------- */ - -%include -%include +/* Include the unified typemap library */ %include -/* ----------------------------------------------------------------------------- - * Backward compatibility output helper - * ----------------------------------------------------------------------------- */ -%fragment("output_helper","header") %{ -#define output_helper SWIG_Ruby_AppendOutput -%} diff --git a/Lib/tcl/tcl8.swg b/Lib/tcl/tcl8.swg index 271564383..bfb7afe81 100644 --- a/Lib/tcl/tcl8.swg +++ b/Lib/tcl/tcl8.swg @@ -24,11 +24,6 @@ * ------------------------------------------------------------ */ %include -/* ------------------------------------------------------------ - * Look for user fragments file. - * ------------------------------------------------------------ */ -%include "tclfragments.swg" - /* ------------------------------------------------------------ * Typemap specializations * ------------------------------------------------------------ */ diff --git a/Lib/tcl/tclmacros.swg b/Lib/tcl/tclmacros.swg index ffbf830ba..ab7bace5b 100644 --- a/Lib/tcl/tclmacros.swg +++ b/Lib/tcl/tclmacros.swg @@ -1,14 +1,3 @@ -/* - in Tcl we need to pass the interp value, so, we - define decl/call macros as needed. -*/ - -#define SWIG_ASPTR_DECL_ARGS SWIG_TCL_DECL_ARGS_2 -#define SWIG_ASPTR_CALL_ARGS SWIG_TCL_CALL_ARGS_2 - -#define SWIG_ASVAL_DECL_ARGS SWIG_TCL_DECL_ARGS_2 -#define SWIG_ASVAL_CALL_ARGS SWIG_TCL_CALL_ARGS_2 - %include diff --git a/Lib/tcl/tclrun.swg b/Lib/tcl/tclrun.swg index 9d215fa43..91f4f88f4 100644 --- a/Lib/tcl/tclrun.swg +++ b/Lib/tcl/tclrun.swg @@ -58,7 +58,7 @@ #define SWIG_ObjectDelete SWIG_Tcl_ObjectDelete -#define SWIG_TCL_DECL_ARGS_2(arg1, arg2) (Tcl_Interp *interp, arg1, arg2) +#define SWIG_TCL_DECL_ARGS_2(arg1, arg2) (Tcl_Interp *interp SWIGUNUSED, arg1, arg2) #define SWIG_TCL_CALL_ARGS_2(arg1, arg2) (interp, arg1, arg2) /* ----------------------------------------------------------------------------- * pointers/data manipulation @@ -167,7 +167,7 @@ SWIG_Tcl_PointerTypeFromString(char *c) { /* Convert a packed value value */ SWIGRUNTIME int -SWIG_Tcl_ConvertPacked(Tcl_Interp *interp, Tcl_Obj *obj, void *ptr, int sz, swig_type_info *ty) { +SWIG_Tcl_ConvertPacked(Tcl_Interp *interp SWIGUNUSED, Tcl_Obj *obj, void *ptr, int sz, swig_type_info *ty) { swig_cast_info *tc; const char *c; diff --git a/Lib/tcl/tclswigtype.swg b/Lib/tcl/tclswigtype.swg deleted file mode 100644 index a79bdfd1e..000000000 --- a/Lib/tcl/tclswigtype.swg +++ /dev/null @@ -1,11 +0,0 @@ -%typemap(out) SWIGTYPE = SWIGTYPE INSTANCE; -%typemap(out) SWIGTYPE * = SWIGTYPE *INSTANCE; -%typemap(out) SWIGTYPE & = SWIGTYPE &INSTANCE; -%typemap(out) SWIGTYPE [] = SWIGTYPE INSTANCE[]; -%typemap(varout) SWIGTYPE = SWIGTYPE INSTANCE; - -%typemap(throws,noblock=1) SWIGTYPE CLASS { - SWIG_set_result(SWIG_NewInstanceObj(SWIG_as_voidptr(SWIG_new_copy($1, $1_ltype)), $&1_descriptor, 1)); - SWIG_fail; -} - diff --git a/Lib/tcl/tcltypemaps.swg b/Lib/tcl/tcltypemaps.swg index b037c4cd2..94dac5b4b 100644 --- a/Lib/tcl/tcltypemaps.swg +++ b/Lib/tcl/tcltypemaps.swg @@ -1,31 +1,70 @@ -/* ----------------------------------------------------------------------------- - * Typemap specializations - * ----------------------------------------------------------------------------- */ +/* ------------------------------------------------------------ + * Typemap specializations for Tcl + * ------------------------------------------------------------ */ -/* no director supported in Tcl */ +/* ------------------------------------------------------------ + * Fragment section + * ------------------------------------------------------------ */ + +/* + in Tcl we need to pass the interp value, so, we define the decl/call + macros as needed. +*/ + +#define SWIG_ASPTR_DECL_ARGS SWIG_TCL_DECL_ARGS_2 +#define SWIG_ASPTR_CALL_ARGS SWIG_TCL_CALL_ARGS_2 + +#define SWIG_ASVAL_DECL_ARGS SWIG_TCL_DECL_ARGS_2 +#define SWIG_ASVAL_CALL_ARGS SWIG_TCL_CALL_ARGS_2 + + +/* Include fundamental fragemt definitions */ +%include + +/* Look for user fragments file. */ +%include "tclfragments.swg" + +/* Tcl fragments for primitve types */ +%include + +/* Tcl fragments for char* strings */ +%include + + +/* ------------------------------------------------------------ + * Unified typemap section + * ------------------------------------------------------------ */ + +/* No director supported in Tcl */ #ifdef SWIG_DIRECTOR_TYPEMAPS #undef SWIG_DIRECTOR_TYPEMAPS #endif -/* ----------------------------------------------------------------------------- - * Basic definitions - * ----------------------------------------------------------------------------- */ - +/* Tcl types */ #define SWIG_Object Tcl_Obj * -#define VOID_Object NULL +/* Simple overload of the output/constant/exception handling */ #define SWIG_AppendOutput(result,obj) (Tcl_ListObjAppendElement(NULL,result,obj) == TCL_OK) ? result : NULL #define SWIG_SetConstant(name, obj) SWIG_Tcl_SetConstantObj(interp, name, obj) #define SWIG_Raise(obj,type,desc) SWIG_Tcl_SetErrorObj(interp,type,obj) -/* ----------------------------------------------------------------------------- - * All the typemaps - * ----------------------------------------------------------------------------- */ -%include -%include +/* Include the unified typemap library */ %include -/* fix for instances */ -%include + +/* ------------------------------------------------------------ + * Tcl extra typemaps + * ------------------------------------------------------------ */ + +%typemap(out) SWIGTYPE = SWIGTYPE INSTANCE; +%typemap(out) SWIGTYPE * = SWIGTYPE *INSTANCE; +%typemap(out) SWIGTYPE & = SWIGTYPE &INSTANCE; +%typemap(out) SWIGTYPE [] = SWIGTYPE INSTANCE[]; +%typemap(varout) SWIGTYPE = SWIGTYPE INSTANCE; + +%typemap(throws,noblock=1) SWIGTYPE CLASS { + SWIG_set_result(SWIG_NewInstanceObj(SWIG_as_voidptr(SWIG_new_copy($1, $1_ltype)), $&1_descriptor, 1)); + SWIG_fail; +} diff --git a/Lib/typemaps/enumint.swg b/Lib/typemaps/enumint.swg index a76b664a8..c45593aee 100644 --- a/Lib/typemaps/enumint.swg +++ b/Lib/typemaps/enumint.swg @@ -26,39 +26,3 @@ } } -/* - typemaps needed due to unnamed enums -*/ -%define %enum_out_typemaps(from_meth,frag) - %typemap(out,noblock=1,fragment=frag) enum SWIGTYPE { - %set_output(from_meth(($1))); - } - %typemap(out,noblock=1,fragment=frag) const enum SWIGTYPE& { - %set_output(from_meth((*$1))); - } - %typemap(varout,noblock=1,fragment=frag) enum SWIGTYPE, const enum SWIGTYPE& { - %set_varoutput(from_meth($1)); - } - %typemap(constcode,noblock=1,fragment=frag) enum SWIGTYPE { - %set_constant("$symname", from_meth($value)); - } - %typemap(directorin,noblock=1,fragment=frag) enum SWIGTYPE *DIRECTORIN { - $input = from_meth(*$1_name); - } - %typemap(directorin,noblock=1,fragment=frag) enum SWIGTYPE, const enum SWIGTYPE& { - $input = from_meth($1_name); - } - %typemap(throws,noblock=1,fragment=frag) enum SWIGTYPE { - %raise(from_meth($1),"$type",0); - } -%enddef - -%enum_out_typemaps(SWIG_From(int),SWIG_From_frag(int)); - - - - - - - - diff --git a/Lib/typemaps/fragmacros.swg b/Lib/typemaps/fragmacros.swg deleted file mode 100644 index 98b27221a..000000000 --- a/Lib/typemaps/fragmacros.swg +++ /dev/null @@ -1,143 +0,0 @@ -/* - Special macros to define and use fragment names and declarations. - - These macros generate the names used in fragments, for example, a - typical use will be: - - %fragment(SWIG_From_frag(bool),"header") { - SWIGINTERNINLINE PyObject* - SWIG_From_dec(bool)(bool value) - { - PyObject *obj = value ? Py_True : Py_False; - Py_INCREF(obj); - return obj; - } - } - - and then you can call the method using - - %typemap(out,fragment=SWIG_From_frag(bool)) bool { - %set_output(SWIG_From(bool)($1)); - } - - when the typemap get generated, the proper fragment for the - SWIG_From(bool) method will be included. - - */ - - - -#define SWIG_Traits_frag(Type...) %string_type(Traits, Type) -#define SWIG_AsPtr_frag(Type...) %string_type(AsPtr, Type) -#define SWIG_AsVal_frag(Type...) %string_type(AsVal, Type) -#define SWIG_From_frag(Type...) %string_type(From, Type) - - -#ifndef SWIG_ASVAL_DECL_ARGS -#define SWIG_ASVAL_DECL_ARGS -#endif - -#ifndef SWIG_ASPTR_DECL_ARGS -#define SWIG_ASPTR_DECL_ARGS -#endif - -#ifndef SWIG_FROM_DECL_ARGS -#define SWIG_FROM_DECL_ARGS -#endif - -#ifndef SWIG_ASVAL_CALL_ARGS -#define SWIG_ASVAL_CALL_ARGS -#endif - -#ifndef SWIG_ASPTR_CALL_ARGS -#define SWIG_ASPTR_CALL_ARGS -#endif - -#ifndef SWIG_FROM_CALL_ARGS -#define SWIG_FROM_CALL_ARGS -#endif - - -#define SWIG_AsVal_dec(Type...) %name_type(AsVal, Type) SWIG_ASVAL_DECL_ARGS -#define SWIG_AsPtr_dec(Type...) %name_type(AsPtr, Type) SWIG_ASPTR_DECL_ARGS -#define SWIG_From_dec(Type...) %name_type(From, Type) SWIG_FROM_DECL_ARGS - -#define SWIG_AsVal(Type...) %name_type(AsVal, Type) SWIG_ASVAL_CALL_ARGS -#define SWIG_AsPtr(Type...) %name_type(AsPtr, Type) SWIG_ASPTR_CALL_ARGS -#define SWIG_From(Type...) %name_type(From, Type) SWIG_FROM_CALL_ARGS - - - - -/* ------------------------------------------------------------ - * common macro helpers - * ------------------------------------------------------------ */ - - -/* Macros for numeric types */ - -%define %numeric_type_from(Type, Base) -%fragment(SWIG_From_frag(Type),"header", - fragment=SWIG_From_frag(Base)) { -SWIGINTERNINLINE SWIG_Object -SWIG_From_dec(Type)(Type value) -{ - return SWIG_From(Base)(value); -} -} -%enddef - -%define %numeric_type_asval(Type, Base, Frag, OverflowCond) -%fragment(SWIG_AsVal_frag(Type),"header", - fragment=Frag, - fragment=SWIG_AsVal_frag(Base)) { -SWIGINTERN int -SWIG_AsVal_dec(Type)(SWIG_Object obj, Type *val) -{ - Base v; - int res = SWIG_AsVal(Base)(obj, &v); - if (res == SWIG_OK) { - if (OverflowCond) { - return SWIG_OverflowError; - } else { - if (val) *val = %numeric_cast(v, Type); - return SWIG_OK; - } - } - return res; -} -} -%enddef - -%define %numeric_signed_type_asval(Type, Base, Frag, Min, Max) -%numeric_type_asval(Type, Base, Frag, (v < Min || v > Max)) -%enddef - -%define %numeric_unsigned_type_asval(Type, Base, Frag, Max) -%numeric_type_asval(Type, Base, Frag, (v > Max)) -%enddef - - -/* Macro for 'signed long' derived types */ - -%define %numeric_slong(Type, Frag, Min, Max) -%numeric_type_from(Type, long) -%numeric_signed_type_asval(Type, long, Frag , Min, Max) -%enddef - -/* Macro for 'unsigned long' derived types */ - -%define %numeric_ulong(Type, Frag, Max) -%numeric_type_from(Type, unsigned long) -%numeric_unsigned_type_asval(Type, unsigned long, Frag, Max) -%enddef - - -/* Macro for 'double' derived types */ - -%define %numeric_double(Type, Frag, Min, Max) -%numeric_type_from(Type, double) -%numeric_signed_type_asval(Type, double, Frag , Min, Max) -%enddef - - diff --git a/Lib/typemaps/fragments.swg b/Lib/typemaps/fragments.swg index 1e42b5ceb..c9c5a5d72 100644 --- a/Lib/typemaps/fragments.swg +++ b/Lib/typemaps/fragments.swg @@ -269,11 +269,51 @@ */ +/* ----------------------------------------------------------------------------- + * Define the basic macros to 'normalize' the type fragments + * ----------------------------------------------------------------------------- */ + +#ifndef SWIG_ASVAL_DECL_ARGS +#define SWIG_ASVAL_DECL_ARGS +#endif + +#ifndef SWIG_ASPTR_DECL_ARGS +#define SWIG_ASPTR_DECL_ARGS +#endif + +#ifndef SWIG_FROM_DECL_ARGS +#define SWIG_FROM_DECL_ARGS +#endif + +#ifndef SWIG_ASVAL_CALL_ARGS +#define SWIG_ASVAL_CALL_ARGS +#endif + +#ifndef SWIG_ASPTR_CALL_ARGS +#define SWIG_ASPTR_CALL_ARGS +#endif + +#ifndef SWIG_FROM_CALL_ARGS +#define SWIG_FROM_CALL_ARGS +#endif + +#define SWIG_Traits_frag(Type...) %string_type(Traits, Type) +#define SWIG_AsPtr_frag(Type...) %string_type(AsPtr, Type) +#define SWIG_AsVal_frag(Type...) %string_type(AsVal, Type) +#define SWIG_From_frag(Type...) %string_type(From, Type) + +#define SWIG_AsVal_dec(Type...) %name_type(AsVal, Type) SWIG_ASVAL_DECL_ARGS +#define SWIG_AsPtr_dec(Type...) %name_type(AsPtr, Type) SWIG_ASPTR_DECL_ARGS +#define SWIG_From_dec(Type...) %name_type(From, Type) SWIG_FROM_DECL_ARGS + +#define SWIG_AsVal(Type...) %name_type(AsVal, Type) SWIG_ASVAL_CALL_ARGS +#define SWIG_AsPtr(Type...) %name_type(AsPtr, Type) SWIG_ASPTR_CALL_ARGS +#define SWIG_From(Type...) %name_type(From, Type) SWIG_FROM_CALL_ARGS + /* ------------------------------------------------------------ * common fragments * ------------------------------------------------------------ */ - %fragment("","header") %{ #include %} @@ -286,4 +326,90 @@ #include %} +/* ----------------------------------------------------------------------------- + * special macros for fragments + * ----------------------------------------------------------------------------- */ +/* Macros to derive numeric types */ + +%define %numeric_type_from(Type, Base) +%fragment(SWIG_From_frag(Type),"header", + fragment=SWIG_From_frag(Base)) { +SWIGINTERNINLINE SWIG_Object +SWIG_From_dec(Type)(Type value) +{ + return SWIG_From(Base)(value); +} +} +%enddef + +%define %numeric_type_asval(Type, Base, Frag, OverflowCond) +%fragment(SWIG_AsVal_frag(Type),"header", + fragment=Frag, + fragment=SWIG_AsVal_frag(Base)) { +SWIGINTERN int +SWIG_AsVal_dec(Type)(SWIG_Object obj, Type *val) +{ + Base v; + int res = SWIG_AsVal(Base)(obj, &v); + if (res == SWIG_OK) { + if (OverflowCond) { + return SWIG_OverflowError; + } else { + if (val) *val = %numeric_cast(v, Type); + return SWIG_OK; + } + } + return res; +} +} +%enddef + +%define %numeric_signed_type_asval(Type, Base, Frag, Min, Max) +%numeric_type_asval(Type, Base, Frag, (v < Min || v > Max)) +%enddef + +%define %numeric_unsigned_type_asval(Type, Base, Frag, Max) +%numeric_type_asval(Type, Base, Frag, (v > Max)) +%enddef + + +/* Macro for 'signed long' derived types */ + +%define %numeric_slong(Type, Frag, Min, Max) +%numeric_type_from(Type, long) +%numeric_signed_type_asval(Type, long, Frag , Min, Max) +%enddef + +/* Macro for 'unsigned long' derived types */ + +%define %numeric_ulong(Type, Frag, Max) +%numeric_type_from(Type, unsigned long) +%numeric_unsigned_type_asval(Type, unsigned long, Frag, Max) +%enddef + + +/* Macro for 'double' derived types */ + +%define %numeric_double(Type, Frag, Min, Max) +%numeric_type_from(Type, double) +%numeric_signed_type_asval(Type, double, Frag , Min, Max) +%enddef + + +/* Macros for missing fragments */ + +%define %ensure_fragment(Fragment) +%fragment(`Fragment`,"header") { +%#error "Swig language implementation must provide the Fragment fragment" +} +%enddef + +%define %ensure_type_fragments(Type) +%fragment(SWIG_From_frag(Type),"header") { +%#error "Swig language implementation must provide a SWIG_From_frag(Type) fragment" +} +%fragment(SWIG_AsVal_frag(Type),"header") { +%#error "Swig language implementation must provide a SWIG_AsVal_frag(Type) fragment" +} +%enddef diff --git a/Lib/typemaps/primtypes.swg b/Lib/typemaps/primtypes.swg index ee95a3fcb..7f062896d 100644 --- a/Lib/typemaps/primtypes.swg +++ b/Lib/typemaps/primtypes.swg @@ -1,7 +1,117 @@ /* ------------------------------------------------------------ - * Basic fragments derived from long and double types + * Primitive type fragments and macros * ------------------------------------------------------------ */ +/* + This file provide fragments and macros for the C/C++ primitive types. + + The file defines default fragments for the following types: + + bool + signed char + unsigned char + signed wchar_t // in C++ + unsigned wchar_t // in C++ + short + unsigned short + int + unsigned int + float + + which can always be redefined in the swig target languge if needed. + + The fragments for the following types, however, need to be defined + in the target language always: + + long + unsigned long + long long + unsigned long long + double + + If they are not provided, an #error directive will appear in the + wrapped code. + + -------------------------------------------------------------------- + + This file provides the macro + + %typemaps_primitive(CheckCode, Type) + + which generate the typemaps for a primitive type with a given + checkcode. It is assumed the the primitive type is 'normalized' and + the corresponding SWIG_AsVal(Type) and SWIG_From(Type) methods are + provided via fragments. + + + The following auxiliar macros (explained with bash pseudo code) are + also defined: + + %apply_ctypes(Macro) + for i in C Type + do + Macro($i) + done + + %apply_cpptypes(Macro) + for i in C++ Type + do + Macro($i) + done + + %apply_ctypes_2(Macro2) + for i in C Type + do + for j in C Type + do + Macro_2($i, $j) + done + done + + %apply_cpptypes_2(Macro2) + for i in C++ Type + do + for j in C++ Type + do + Macro_2($i, $j) + done + done + + %apply_checkctypes(Macro2) + for i in Check Type + do + Macro2(%checkcode($i), $i) + done + +*/ + + +/* ------------------------------------------------------------ + * Primitive type fragments + * ------------------------------------------------------------ */ +/* boolean */ + +%fragment(SWIG_From_frag(bool),"header",fragment=SWIG_From_frag(long)) { +SWIGINTERN SWIG_Object +SWIG_From_dec(bool)(bool value) +{ + return SWIG_From(long)(value ? 1 : 0); +} +} + +%fragment(SWIG_AsVal_frag(bool),"header",fragment=SWIG_AsVal_frag(long)) { +SWIGINTERN int +SWIG_AsVal_dec(bool)(SWIG_Object obj, bool *val) +{ + long v; + if (SWIG_AsVal(long)(obj, val ? &v : 0) == SWIG_OK) { + if (val) *val = v ? true : false; + return SWIG_OK; + } + return SWIG_TypeError; +} +} + /* signed/unsigned char */ %numeric_slong(signed char, "", SCHAR_MIN, SCHAR_MAX) @@ -28,9 +138,23 @@ %numeric_double(float, "", -FLT_MAX, FLT_MAX) +/* long/unsgined long */ + +%ensure_type_fragments(long) +%ensure_type_fragments(unsigned long) + +/* long long/unsigned long long */ + +%ensure_type_fragments(long long) +%ensure_type_fragments(unsigned long long) + +/* double */ + +%ensure_type_fragments(double) + /* ------------------------------------------------------------ - * typemap macro for primitive types with asval/from methods + * Generate the typemaps for primitive type * ------------------------------------------------------------ */ %define %typemaps_primitive(Code, Type) @@ -70,7 +194,12 @@ _apply_macro(Macro, char , __VA_ARGS__); _apply_macro(Macro, wchar_t , __VA_ARGS__); %enddef -/* apply the Macro(Type) to all the C++ types */ +/* apply the Macro2(Type1, Type2) to all C types */ +%define %apply_ctypes_2(Macro2) +%apply_ctypes(%apply_ctypes, Macro2) +%enddef + +/* apply the Macro(Type) to all C++ types */ %define %apply_cpptypes(Macro,...) %apply_ctypes(Macro, __VA_ARGS__) _apply_macro(Macro, std::string, __VA_ARGS__); @@ -78,32 +207,33 @@ _apply_macro(Macro, std::complex, __VA_ARGS__); _apply_macro(Macro, std::complex, __VA_ARGS__); %enddef -/* apply the Macro2(Type1, Type2) to all the C++ types */ +/* apply the Macro2(Type1, Type2) to all C++ types */ %define %apply_cpptypes_2(Macro2) %apply_cpptypes(%apply_cpptypes, Macro2) %enddef -%define %apply_checkctypes(Macro) -Macro(%checkcode(BOOL), bool); -Macro(%checkcode(INT8), signed char); -Macro(%checkcode(UINT8), unsigned char); -Macro(%checkcode(INT16), short); -Macro(%checkcode(UINT16), unsigned short); -Macro(%checkcode(INT32), int); -Macro(%checkcode(UINT32), unsigned int); -Macro(%checkcode(INT64), long); -Macro(%checkcode(UINT64), unsigned long); -Macro(%checkcode(INT128), long long); -Macro(%checkcode(UINT128), unsigned long long); -Macro(%checkcode(FLOAT), float); -Macro(%checkcode(DOUBLE), double); -Macro(%checkcode(CHAR), char); -Macro(%checkcode(UNICHAR), wchar_t); +/* apply the Macro2(CheckCode,Type) to all Checked Types */ +%define %apply_checkctypes(Macro2) +Macro2(%checkcode(BOOL), bool); +Macro2(%checkcode(INT8), signed char); +Macro2(%checkcode(UINT8), unsigned char); +Macro2(%checkcode(INT16), short); +Macro2(%checkcode(UINT16), unsigned short); +Macro2(%checkcode(INT32), int); +Macro2(%checkcode(UINT32), unsigned int); +Macro2(%checkcode(INT64), long); +Macro2(%checkcode(UINT64), unsigned long); +Macro2(%checkcode(INT128), long long); +Macro2(%checkcode(UINT128), unsigned long long); +Macro2(%checkcode(FLOAT), float); +Macro2(%checkcode(DOUBLE), double); +Macro2(%checkcode(CHAR), char); +Macro2(%checkcode(UNICHAR), wchar_t); %enddef /* ------------------------------------------------------------ - * Apply the primitive typemap for all the types with checkcode + * Generate the typemaps for all the primitive types with checkcode * ------------------------------------------------------------ */ %apply_checkctypes(%typemaps_primitive); diff --git a/Lib/typemaps/string.swg b/Lib/typemaps/string.swg index d03ef6e6e..3220d6805 100644 --- a/Lib/typemaps/string.swg +++ b/Lib/typemaps/string.swg @@ -1,3 +1,7 @@ + +%ensure_fragment(SWIG_AsCharPtrAndSize) +%ensure_fragment(SWIG_FromCharPtrAndSize) + %include %typemaps_string(char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, strlen, "", CHAR_MIN, CHAR_MAX) diff --git a/Lib/typemaps/swigmacros.swg b/Lib/typemaps/swigmacros.swg index 7405ab367..e16afa9e7 100644 --- a/Lib/typemaps/swigmacros.swg +++ b/Lib/typemaps/swigmacros.swg @@ -1,14 +1,97 @@ /* ----------------------------------------------------------------------------- * SWIG API. Portion only visible from SWIG * ----------------------------------------------------------------------------- */ +/* + This file implements the internal macros of the 'SWIG API', which + are useful to implement all the SWIG target languges. + Basic preprocessor macros: + -------------------------- + + %arg(Arg) Safe argument wrap + %str(Arg) Stringtify the argument + %begin_block Begin a execution block + %end_block End a execution block + %block(Block) Execute Block as a excecution block + %define_as(Def, Val) Define 'Def' as 'Val', expanding Def and Val first + %ifcplusplus(V1, V2) if C++ Mode; then V1; else V2; fi + + + Casting Operations: + ------------------- + + Swig provides the following casting macros, which implement the + corresponding C++ casting operations: + + %const_cast(a, Type) const_cast(a) + %static_cast(a, Type) static_cast(a) + %reinterpret_cast(a, Type) reinterpret_cast(a) + %numeric_cast(a, Type) static_cast(a) + %as_voidptr(a) const_cast(static_cast(a)) + %as_voidptrptr(a) reinterpret_cast(a) + + or their C unsafe versions. In C++ we use the safe version unless + SWIG_NO_CPLUSPLUS_CAST is defined (usually via the -nocppcast swig flag). + + + Memory allocation: + ------------------ + + These allocation/freeing macros are safe to use in C or C++ and + dispatch the proper new/delete/delete[] or free/malloc calls as + needed. + + %new_instance(Type) Allocate a new instance of given Type + %new_copy(value,Type) Allocate and initialize a new instance with 'value' + %new_array(size,Type) Allocate a new array with given size and Type + %new_copy_array(cptr,size,Type) Allocate and initialize a new array from 'cptr' + %delete(cptr) Delete an instance + %delete_array(cptr) Delete an array + + + Auxiliar loop macros: + --------------------- + + %formacro(Macro, Args...) or %formacro_1(Macro, Args...) + for i in Args + do + Macro($i) + done + + %formacro_2(Macro2, Args...) + for i,j in Args + do + Macro2($i, $j) + done + + + Swig flags: + ----------- + + %swig_mark_flag(flag) + flag := True + + %evalif(flag,expr) + if flag; then + expr + fi + + %evalif_2(flag1 flag2,expr) + if flag1 and flag2; then + expr + fi + + +*/ /* ----------------------------------------------------------------------------- * Basic preprocessor macros * ----------------------------------------------------------------------------- */ -#define %arg(Arg...) Arg -#define %str(Type...) #Type -#define %block(Block...) do { Block; } while(0) +#define %arg(Arg...) Arg +#define %str(Arg) `Arg` +#define %begin_block do { +#define %end_block } while(0) +#define %block(Block...) %begin_block Block; %end_block /* define a new macro */ %define %define_as(Def, Val...) @@ -41,7 +124,7 @@ nocppval # define %reinterpret_cast(a,Type...) reinterpret_cast(a) # define %numeric_cast(a,Type...) static_cast(a) # define %as_voidptr(a) const_cast(static_cast(a)) -# define %as_voidptrptr(a) reinterpret_cast(a) +# define %as_voidptrptr(a) reinterpret_cast(a) #else /* C case */ # define %const_cast(a,Type...) (Type)(a) # define %static_cast(a,Type...) (Type)(a) @@ -81,27 +164,8 @@ nocppval #define %checkcode(Code) %name_type(TYPECHECK, Code) - -/* - Macros to define language dependent object and the void object. - Use them, for example in Tcl, as - - %define_swig_object(Tcl_Obj *) - %define_void_object(NULL) -*/ - -/* VOID_Object */ -%define %define_void_object(Obj) -#define VOID_Object Obj -%enddef - -/* SWIG_Object */ -%define %define_swig_object(Obj) -#define SWIG_Object Obj -%enddef - /* ----------------------------------------------------------------------------- - * Auxiliar ugly macros used to write typemaps + * Auxiliar loop macros * ----------------------------------------------------------------------------- */ @@ -117,6 +181,9 @@ macro(arg1) %define %formacro_1(macro,...) %_formacro_1(macro,__VA_ARGS__,__fordone__) %enddef +%define %formacro(macro,...) +%_formacro_1(macro,__VA_ARGS__,__fordone__) +%enddef /* for loop for macro with two arguments */ %define %_formacro_2(macro, arg1, arg2, ...) @@ -131,30 +198,21 @@ macro(arg1, arg2) %_formacro_2(macro, __VA_ARGS__, __fordone__) %enddef +/* ----------------------------------------------------------------------------- + * Swig flags + * ----------------------------------------------------------------------------- */ /* mark a flag, ie, define a macro name but ignore it in the interface. - the flags latter can be used with %evalif + the flag can be later used with %evalif */ %define %swig_mark_flag(x) -%ignore x; -#define x 1 +%define x 1 %enddef %enddef -/* - %swig_equal_type and %swig_order_type flagged a type of having equal (==,!=) - and/or order methods (<=,>=,<,>). -*/ -#define SWIG_OrderType(Type...) %name_type(OrderType, Type) -#define SWIG_EqualType(Type...) %name_type(EqualType, Type) - -#define %swig_equal_type(...) %swig_mark_flag(SWIG_EqualType(__VA_ARGS__)) -#define %swig_order_type(...) \ - %swig_mark_flag(SWIG_EqualType(__VA_ARGS__)) \ - %swig_mark_flag(SWIG_OrderType(__VA_ARGS__)) /* %evalif and %evalif_2 are use to evaluate or process @@ -172,17 +230,11 @@ _expr #endif %enddef -%define %evalif(_x,...) - %_evalif(%arg(_x),%arg(__VA_ARGS__)) +%define %evalif(_x,_expr...) + %_evalif(%arg(_x),%arg(_expr)) %enddef -%define %evalif_2(_x,_y,...) - %_evalif_2(%arg(_x),%arg(_y),%arg(__VA_ARGS__)) +%define %evalif_2(_x,_y,_expr...) + %_evalif_2(%arg(_x),%arg(_y),%arg(_expr)) %enddef - -/* ----------------------------------------------------------------------------- - * Include special macros for fragments - * ----------------------------------------------------------------------------- */ - -%include diff --git a/Lib/typemaps/swigobject.swg b/Lib/typemaps/swigobject.swg index 23107cb3b..62afd4a09 100644 --- a/Lib/typemaps/swigobject.swg +++ b/Lib/typemaps/swigobject.swg @@ -2,10 +2,6 @@ * Language Object * - Just pass straight through unmodified * ------------------------------------------------------------ */ -#if !defined(SWIG_Object) -#error "SWIG_Object must be defined using %define_swig_object" -#endif - %typemap(in) SWIG_Object "$1 = $input;"; %typemap(out,noblock=1) SWIG_Object { diff --git a/Lib/typemaps/swigtypemaps.swg b/Lib/typemaps/swigtypemaps.swg index 2061e2ea3..ec9d60d14 100644 --- a/Lib/typemaps/swigtypemaps.swg +++ b/Lib/typemaps/swigtypemaps.swg @@ -1,68 +1,151 @@ /* ----------------------------------------------------------------------------- - * Typemap specializations + * Unified Typemap Library frontend * ----------------------------------------------------------------------------- */ -/* flags for new/convert methods */ +/* + This file provides the frontend to the Unified Typemap Library. + + When using this library in a SWIG target language, you need to + define a minimum set of fragments, specialized a couple of macros, + and then include this file. + + Typically you will create a 'mytypemaps.swg' file in each target + languge, where you will have the following sections: + + === mytypemaps.swg === + + // Fragment section + %include + + + // Unified typemap section + + %include + + // Local typemap section + + + === mytypemaps.swg === + + While we add more docs, please take a look at the following cases + to see how you specialized the unified typemap library for a new + target language: + + Lib/python/pytypemaps.swg + Lib/tcl/tcltypemaps.swg + Lib/ruby/rubytypemaps.swg + Lib/perl5/perl5typemaps.swg + +*/ + + +/* ----------------------------------------------------------------------------- + * Language specialization section. + * + * Tune these macros for each language as needed. + * ----------------------------------------------------------------------------- */ + +/* + The SWIG target language object must be provided. + For example in python you define: + + #define SWIG_Object PyObject * +*/ + +#if !defined(SWIG_Object) +#error "SWIG_Object must be defined as the SWIG target language object" +#endif + +/*==== flags for new/convert methods ====*/ #ifndef %convertptr_flags -%ignore %convertptr_flags; -#define %convertptr_flags 0 +%define %convertptr_flags 0 %enddef #endif #ifndef %newpointer_flags -%ignore %newpointer_flags; -#define %newpointer_flags 0 +%define %newpointer_flags 0 %enddef #endif #ifndef %newinstance_flags -%ignore %newinstance_flags; -#define %newinstance_flags 0 +%define %newinstance_flags 0 %enddef #endif -/* output and constant manipulation */ - -#ifndef %set_varoutput -#define %set_varoutput(obj) $result = obj -#endif +/*==== set output ====*/ #ifndef %set_output -#define %set_output(obj) $result = obj +/* simple set output operation */ +#define %set_output(obj) $result = obj #endif +/*==== set variable output ====*/ + +#ifndef %set_varoutput +/* simple set varoutput operation */ +#define %set_varoutput(obj) $result = obj +#endif + +/*==== append output ====*/ + #ifndef %append_output -#define %append_output(obj) $result = SWIG_AppendOutput($result,obj) +#if defined(SWIG_AppendOutput) +/* simple append operation */ +#define %append_output(obj) $result = SWIG_AppendOutput($result,obj) +#else +#error "Language must define SWIG_AppendOutput or %append_output" #endif +#endif + +/*==== set constant ====*/ #ifndef %set_constant -#define %set_constant(name,value) SWIG_SetConstant(name,value) +#if defined(SWIG_SetConstant) +/* simple set constant operation */ +#define %set_constant(name,value) SWIG_SetConstant(name,value) +#else +#error "Language must define SWIG_SetConstant or %set_constant" +#endif #endif -/* setting an error and exit */ +/*==== raise an exception ====*/ + +#ifndef %raise +#if defined(SWIG_Raise) +/* simple raise operation */ +#define %raise(obj, type, desc) %error_block(SWIG_Raise(obj, type, desc); SWIG_fail) +#else +#error "Language must define SWIG_Raise or %raise" +#endif +#endif + +/*==== director output exception ====*/ + +#ifdef SWIG_DIRECTOR_TYPEMAPS +#ifndef SWIG_DirOutFail +#define SWIG_DirOutFail(code, msg) Swig::DirectorTypeMismatchException::raise(SWIG_ErrorType(code), msg) +#endif +#endif + + +/* ----------------------------------------------------------------------------- + * Language independent definitions + * ----------------------------------------------------------------------------- */ + #define %error_block(Block...) %block(Block) #define %argument_fail(code, type, argn) %error_block(SWIG_Error(code, %argfail_fmt(type, argn)); SWIG_fail) #define %argument_nullref(type, argn) %error_block(SWIG_Error(SWIG_ValueError, %argnullref_fmt(type, argn)); SWIG_fail) #define %variable_fail(code, type, name) %error_block(SWIG_Error(code, %varfail_fmt(type, name)); SWIG_fail) #define %variable_nullref(type, name) %error_block(SWIG_Error(SWIG_ValueError, %varnullref_fmt(type, name)); SWIG_fail) - -#ifndef %raise -#define %raise(obj, type, desc) %error_block(SWIG_Raise(obj, type, desc); SWIG_fail) -#endif - #ifdef SWIG_DIRECTOR_TYPEMAPS #define %dirout_fail(code, type) SWIG_DirOutFail(code, %outfail_fmt(type)) #define %dirout_nullref(type) SWIG_DirOutFail(SWIG_ValueError, %outnullref_fmt(type)) #endif - - - - - /* ----------------------------------------------------------------------------- * All the typemaps * ----------------------------------------------------------------------------- */ + %include %include %include diff --git a/Lib/typemaps/valtypes.swg b/Lib/typemaps/valtypes.swg index 973a8723e..5b5251e95 100644 --- a/Lib/typemaps/valtypes.swg +++ b/Lib/typemaps/valtypes.swg @@ -76,7 +76,7 @@ %define %value_varout_typemap(from_meth,frag,Type...) %typemap(varout,noblock=1,fragment=frag) Type, const Type& { - %set_varoutput(from_meth(%static_cast($1,$basetype))); + %set_varoutput(from_meth(%static_cast($1,Type))); } %enddef diff --git a/Lib/typemaps/void.swg b/Lib/typemaps/void.swg index d0fd20516..697878158 100644 --- a/Lib/typemaps/void.swg +++ b/Lib/typemaps/void.swg @@ -2,10 +2,6 @@ * Void * - Accepts any kind of pointer * ------------------------------------------------------------ */ -#if !defined(VOID_Object) -#error "VOID_Object must be defined using %define_void_object" -#endif - /* in */ %typemap(in,noblock=1) void * { @@ -26,9 +22,11 @@ /* out */ -%typemap(out,noblock=1) void { - $result = VOID_Object; -} +#if defined(VOID_Object) +%typemap(out,noblock=1) void { $result = VOID_Object; } +#else +%typemap(out,noblock=1) void {} +#endif /* varin */ diff --git a/Lib/typemaps/wstring.swg b/Lib/typemaps/wstring.swg index ce91ac5e5..e842bc45d 100644 --- a/Lib/typemaps/wstring.swg +++ b/Lib/typemaps/wstring.swg @@ -1,3 +1,6 @@ +%ensure_fragment(SWIG_AsWCharPtrAndSize) +%ensure_fragment(SWIG_FromWCharPtrAndSize) + %include %typemaps_string(wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, wcslen, "", WCHAR_MIN, WCHAR_MAX)