diff --git a/Examples/perl5/multimap/example.i b/Examples/perl5/multimap/example.i index 6ccf8c838..982c117ab 100644 --- a/Examples/perl5/multimap/example.i +++ b/Examples/perl5/multimap/example.i @@ -31,7 +31,7 @@ extern int gcd(int x, int y); tempav = (AV*)SvRV($input); len = av_len(tempav); $1 = (int) len+1; - $2 = (char **) malloc($1*sizeof(char *)); + $2 = (char **) malloc(($1+1)*sizeof(char *)); for (i = 0; i < $1; i++) { tv = av_fetch(tempav, i, 0); $2[i] = (char *) SvPV(*tv,PL_na); diff --git a/Examples/python/exceptshadow/example.i b/Examples/python/exceptshadow/example.i index 0098257a7..8727f1565 100644 --- a/Examples/python/exceptshadow/example.i +++ b/Examples/python/exceptshadow/example.i @@ -47,10 +47,10 @@ try { $action } catch(FullError& e) { - FullError *ecopy = new FullError(e); - PyObject *err = SWIG_NewPointerObj(ecopy, SWIGTYPE_p_FullError, 1); - PyErr_SetObject((PyObject *) SWIGTYPE_p_FullError->clientdata, err); - return NULL; + FullError *ecopy = new FullError(e); + PyObject *err = SWIG_NewPointerObj(ecopy, SWIGTYPE_p_FullError, 1); + PyErr_SetObject(SWIG_Python_ExceptionType(SWIGTYPE_p_FullError), err); + SWIG_fail; } } @@ -87,6 +87,7 @@ */ %exceptionclass EmptyError; +%exceptionclass FullError; %exception *::dequeue { try { @@ -94,8 +95,8 @@ } catch(EmptyError& e) { EmptyError *ecopy = new EmptyError(e); PyObject *err = SWIG_NewPointerObj(ecopy, SWIGTYPE_p_EmptyError, 1); - PyErr_SetObject((PyObject *) SWIGTYPE_p_EmptyError->clientdata, err); - return NULL; + PyErr_SetObject(SWIG_Python_ExceptionType(SWIGTYPE_p_EmptyError), err); + SWIG_fail; } } diff --git a/Examples/test-suite/typemap_variables.i b/Examples/test-suite/typemap_variables.i index 94a008024..0bb67211e 100644 --- a/Examples/test-suite/typemap_variables.i +++ b/Examples/test-suite/typemap_variables.i @@ -23,7 +23,11 @@ %typemap(in) int Space::nspace "/*int nspace in */ $1=0;" %typemap(out) int Space::nspace "/*int nspace out*/ $result=0;" %typemap(in) int member "/*int member in */ $1=0;" +#ifdef SWIGTCL +%typemap(out) int member "/*int member out*/" +#else %typemap(out) int member "/*int member out*/ $result=0;" +#endif %typemap(in) int Space::Struct::smember "/*int smember in */ $1=0;" %typemap(out) int Space::Struct::smember "/*int smember out*/ $result=0;" diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index ccac7e968..46b3ddbd0 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -532,7 +532,7 @@ namespace swig typedef Reference reference; typedef T value_type; typedef T* pointer; - typedef int difference_type; + typedef ptrdiff_t difference_type; PySequence_InputIterator() { diff --git a/Lib/python/pythreads.swg b/Lib/python/pythreads.swg index a7552f1fe..01522544f 100644 --- a/Lib/python/pythreads.swg +++ b/Lib/python/pythreads.swg @@ -30,10 +30,18 @@ SWIG_Python_Thread_Allow() : status(true), save(PyEval_SaveThread()) {} ~SWIG_Python_Thread_Allow() { end(); } }; -# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block -# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() -# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow -# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end() +# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK) +# define SWIG_PYTHON_THREAD_BEGIN_BLOCK SWIG_Python_Thread_Block _swig_thread_block +# endif +# if !defined(SWIG_PYTHON_THREAD_END_BLOCK) +# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end() +# endif +# if !defined(SWIG_PYTHON_THREAD_BEGIN_ALLOW) +# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow +# endif +# if !defined(SWIG_PYTHON_THREAD_END_ALLOW) +# define SWIG_PYTHON_THREAD_END_ALLOW +# endif # else /* C code */ # define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure() # define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block) diff --git a/Lib/tcl/tcltypemaps.swg b/Lib/tcl/tcltypemaps.swg index 8db4cbe3e..97613653a 100644 --- a/Lib/tcl/tcltypemaps.swg +++ b/Lib/tcl/tcltypemaps.swg @@ -45,7 +45,9 @@ #define SWIG_Object Tcl_Obj * /* Simple overload of the output/constant/exception handling */ -#define SWIG_AppendOutput(result,obj) (Tcl_ListObjAppendElement(NULL,result,obj) == TCL_OK) ? result : NULL +/* output */ +#define %set_output(obj) Tcl_SetObjResult(interp,obj) +#define %append_output(obj) Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),obj) #define SWIG_SetConstant(name, obj) SWIG_Tcl_SetConstantObj(interp, name, obj) #define SWIG_Raise(obj,type,desc) SWIG_Tcl_SetErrorObj(interp,type,obj) diff --git a/Lib/typemaps/swigobject.swg b/Lib/typemaps/swigobject.swg index b5003d2e2..a5ff9461f 100644 --- a/Lib/typemaps/swigobject.swg +++ b/Lib/typemaps/swigobject.swg @@ -15,11 +15,11 @@ %typemap(out,noblock=1) SWIG_Object { - $result = $1; + %set_output($1); } %typemap(out,noblock=1) SWIG_Object const & { - $result = *$1; + %set_output(*$1); } %typecheck(SWIG_TYPECHECK_POINTER) SWIG_Object "$1 = ($input != 0);"; diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index ed13a33ce..29766835e 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -299,7 +299,10 @@ public: f = NewWrapper(); +#ifdef SWIG_USE_RESULTOBJ Wrapper_add_local(f,"resultobj", "Tcl_Obj *resultobj = NULL"); +#endif + String *wname = Swig_name_wrapper(iname); if (overname) { @@ -436,8 +439,13 @@ public: for (i=0,p = parms; p;i++) { if ((tm = Getattr(p,"tmap:argout"))) { Replaceall(tm,"$source",Getattr(p,"lname")); +#ifdef SWIG_USE_RESULTOBJ Replaceall(tm,"$target","resultobj"); Replaceall(tm,"$result","resultobj"); +#else + Replaceall(tm,"$target","(Tcl_GetObjResult(interp))"); + Replaceall(tm,"$result","(Tcl_GetObjResult(interp))"); +#endif Replaceall(tm,"$arg",Getattr(p,"emit:input")); Replaceall(tm,"$input",Getattr(p,"emit:input")); Printv(outarg,tm,"\n",NIL); @@ -455,8 +463,13 @@ public: /* Return value if necessary */ if ((tm = Swig_typemap_lookup_new("out",n,"result",0))) { Replaceall(tm,"$source", "result"); - Replaceall(tm,"$target", "resultobj"); - Replaceall(tm,"$result", "resultobj"); +#ifdef SWIG_USE_RESULTOBJ + Replaceall(tm,"$target","resultobj"); + Replaceall(tm,"$result","resultobj"); +#else + Replaceall(tm,"$target","(Tcl_GetObjResult(interp))"); + Replaceall(tm,"$result","(Tcl_GetObjResult(interp))"); +#endif if(GetFlag(n,"feature:new")) { Replaceall(tm,"$owner","SWIG_POINTER_OWN"); } else { @@ -486,7 +499,9 @@ public: Replaceall(tm,"$source","result"); Printf(f->code,"%s\n", tm); } +#ifdef SWIG_USE_RESULTOBJ Printv(f->code, "if (resultobj) Tcl_SetObjResult(interp, resultobj);\n", NIL); +#endif Printv(f->code, "return TCL_OK;\n", NIL); Printv(f->code, "fail:\n", cleanup, "return TCL_ERROR;\n", NIL); Printv(f->code,"}\n", NIL);