finishing the first stage of the typemap unification scheme, fixing issues with gcc and valgrind

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7692 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-20 09:47:56 +00:00
commit ba3efb0917
44 changed files with 565 additions and 426 deletions

View file

@ -61,21 +61,22 @@ void NAME##_setitem(TYPE *ary, size_t index, TYPE value);
* void setitem(int index, TYPE value);
* TYPE * cast();
* static NAME *frompointer(TYPE *t);
* }
* }
*
* Use
*
* %array_class_wrap(TYPE,NAME,GET,SET)
*
* if you want different names for the get/set methods.
* ----------------------------------------------------------------------------- */
%define %array_class(TYPE,NAME)
%define %array_class_wrap(TYPE,NAME,getitem,setitem)
%{
typedef TYPE NAME;
%}
typedef struct NAME {
/* Put language specific enhancements here */
#if defined(SWIGPYTHON) || defined(SWIGRUBY)
%rename(__getitem__) getitem;
%rename(__setitem__) setitem;
#endif
typedef struct NAME {
} NAME;
%extend NAME {
@ -109,3 +110,9 @@ typedef struct NAME {
%enddef
#ifndef %array_class
%define %array_class(TYPE,NAME)
%array_class_wrap(TYPE,NAME,getitem,setitem)
%enddef
#endif

View file

@ -49,7 +49,7 @@
$input = from_meth($1_name);
}
%typemap(throws,noblock=1,fragment=frag) enum SWIGTYPE {
SWIG_exception_obj(0,"$type", from_meth($1));
SWIG_raise(from_meth($1),"$type",0);
}
%enddef

View file

@ -0,0 +1,9 @@
// This SWIG library file provides language independent exception handling
%include <typemaps/swigmacros.swg>
%insert("runtime") {
SWIG_define(SWIG_exception(code, msg), SWIG_block(SWIG_error(code, msg); SWIG_fail))
SWIG_define(SWIG_contract_assert(expr, msg), if (!(expr)) { SWIG_error(SWIG_RuntimeError, msg); SWIG_fail; } else)
}

View file

@ -184,7 +184,7 @@
/* throws */
%typemap(throws,noblock=1,fragment=#SWIG_FromCharPtr) Char * {
SWIG_exception_obj(0, "$type", SWIG_FromCharPtr($1));
SWIG_raise(SWIG_FromCharPtr($1), "$type", 0);
}
@ -327,7 +327,7 @@
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
while (size && ($1[size - 1] == '\0')) --size;
%#endif
SWIG_exception_obj(0, "$type", SWIG_FromCharPtrAndSize($1, size));
SWIG_raise(SWIG_FromCharPtrAndSize($1, size), "$type", 0);
}
/* -------------------------------------------------------------------
@ -357,9 +357,8 @@
#endif /* SWIG_DIRECTOR_TYPEMAPS */
%typemap(throws,noblock=1,fragment=#SWIG_FromCharPtrAndSize)
Char FIXSIZE[ANY], const Char FIXSIZE[ANY]
{
SWIG_exception_obj(0, "$type", SWIG_FromCharPtrAndSize($1, $1_dim0));
Char FIXSIZE[ANY], const Char FIXSIZE[ANY] {
SWIG_raise(SWIG_FromCharPtrAndSize($1, $1_dim0), "$type", 0);
}
/* ------------------------------------------------------------
@ -484,10 +483,11 @@ SWIG_As##CharName##Array(SWIG_Object obj, Char *val, size_t size)
if (val) {
if (csize) memcpy(val, cptr, csize*sizeof(Char));
if (csize < size) memset(val + csize, 0, (size - csize)*sizeof(Char));
if (alloc == SWIG_NEWOBJ) SWIG_delete_array(cptr);
}
if (alloc == SWIG_NEWOBJ) SWIG_delete_array(cptr);
return SWIG_OK;
}
if (alloc == SWIG_NEWOBJ) SWIG_delete_array(cptr);
}
return SWIG_TypeError;
}

View file

@ -85,29 +85,33 @@
/* macros for result manipulation */
#define SWIG_set_result(obj) SWIG_SetResultObj(obj)
#define SWIG_append_result(obj) SWIG_AppendResultObj(obj)
#define SWIG_set_constant(n, v) SWIG_SetConstantObj(n,v)
#define SWIG_set_result(obj) SWIG_SetResultObj(obj)
#define SWIG_append_result(obj) SWIG_AppendResultObj(obj)
#define SWIG_set_constant(name,value) SWIG_SetConstantObj(name,value)
/* macros for error manipulation */
#define SWIG_TypeErrorFmt(_type,_name) "expected '"_type"'"
#define SWIG_VarFailFmt(_type,_name) "in variable '"_name"' of type '"_type"'"
#define SWIG_ArgFailFmt(_type,_argn) "in argument " #_argn" of type '" _type"'"
#define SWIG_OutFailFmt(_type) "in output of type '"_type"'"
#define SWIG_ArgNullRefFmt(_type, _argn) "null reference " SWIG_ArgFailFmt(_type, _argn)
#define SWIG_VarNullRefFmt(_type, _name) "null reference " SWIG_VarFailFmt(_type, _name)
#define SWIG_OutNullRefFmt(_type) "null reference " SWIG_OutFailFmt(_type)
#define SWIG_NullRefFmt() "invalid null reference "
#define SWIG_VarFailFmt(_type,_name) "in variable '"_name"' of type '"_type"'"
#define SWIG_ArgFailFmt(_type,_argn) "in argument " #_argn" of type '" _type"'"
#define SWIG_OutFailFmt(_type) "in output value of type '"_type"'"
#define SWIG_ArgNullRefFmt(_type, _argn) SWIG_NullRefFmt() SWIG_ArgFailFmt(_type, _argn)
#define SWIG_VarNullRefFmt(_type, _name) SWIG_NullRefFmt() SWIG_VarFailFmt(_type, _name)
#define SWIG_OutNullRefFmt(_type) SWIG_NullRefFmt() SWIG_OutFailFmt(_type)
#define SWIG_ArgFail(code,type,argn) SWIG_SetErrorMsg(code,SWIG_ArgFailFmt(type, argn))
#define SWIG_VarFail(code,type,name) SWIG_SetErrorMsg(code,SWIG_VarFailFmt(type, name))
#define SWIG_ArgNullRef(type,argn) SWIG_SetErrorMsg(SWIG_ValueError, SWIG_ArgNullRefFmt(type, argn))
#define SWIG_VarNullRef(type,name) SWIG_SetErrorMsg(SWIG_ValueError, SWIG_VarNullRefFmt(type, name))
#define SWIG_OutNullRef(type) SWIG_SetErrorMsg(SWIG_ValueError, SWIG_OutNullRefFmt(type))
#define SWIG_ArgFail(code,type,argn) SWIG_Error(code, SWIG_ArgFailFmt(type, argn))
#define SWIG_VarFail(code,type,name) SWIG_Error(code, SWIG_VarFailFmt(type, name))
#define SWIG_ArgNullRef(type,argn) SWIG_Error(SWIG_ValueError, SWIG_ArgNullRefFmt(type, argn))
#define SWIG_VarNullRef(type,name) SWIG_Error(SWIG_ValueError, SWIG_VarNullRefFmt(type, name))
#define SWIG_OutNullRef(type) SWIG_Error(SWIG_ValueError, SWIG_OutNullRefFmt(type))
#define SWIG_set_errmsg(code,msg...) SWIG_SetErrorMsg(code,msg)
#define SWIG_set_errobj(code,obj) SWIG_SetErrorObj(code,obj)
#define SWIG_error_block(Block...) SWIG_block(Block)
/* setting an error */
#define SWIG_error(code,msg...) SWIG_Error(code, msg)
#define SWIG_type_error(msg...) SWIG_Error(SWIG_TypeError, msg)
/* setting an error and exit */
#define SWIG_error_block(Block...) SWIG_block(Block)
#define SWIG_arg_fail(code, type, arg) SWIG_error_block(SWIG_ArgFail(code, type, arg); SWIG_fail)
#define SWIG_arg_nullref(type, arg) SWIG_error_block(SWIG_ArgNullRef(type, arg); SWIG_fail)
@ -118,14 +122,13 @@
#define SWIG_global_fail(code, type, name) SWIG_error_block(SWIG_VarFail(code, type, name); SWIG_fail)
#define SWIG_global_nullref(type, name) SWIG_error_block(SWIG_VarNullRef(type, name); SWIG_fail)
#define SWIG_var_fail(code, type, name) SWIG_error_block(SWIG_VarFail(code, type, name); SWIG_var_fail)
#define SWIG_var_nullref(type, name) SWIG_error_block(SWIG_VarNullRef(type, name); SWIG_var_fail)
#define SWIG_var_fail(code, type, name) SWIG_error_block(SWIG_VarFail(code, type, name); SWIG_fail)
#define SWIG_var_nullref(type, name) SWIG_error_block(SWIG_VarNullRef(type, name); SWIG_fail)
#define SWIG_dout_fail(code, type) SWIG_DirOutFail(code, SWIG_OutFailFmt(type))
#define SWIG_dout_nullref(type) SWIG_DirOutFail(SWIG_ValueError, SWIG_OutNullRefFmt(type))
#define SWIG_exception_obj(desc, type, obj) SWIG_error_block(SWIG_ExceptionObj(desc, type, obj); SWIG_fail)
#define SWIG_raise(obj, type, desc) SWIG_error_block(SWIG_Raise(obj, type, desc); SWIG_fail)
/*
@ -133,7 +136,7 @@
Use it, for example in Tcl, as
%define_swig_object(Tcl_Obj)
%define_swig_object(Tcl_Obj *)
*/
#define SWIG_Object __NULL__
@ -153,7 +156,7 @@
* ----------------------------------------------------------------------------- */
/* define a new macro */
%define SWIG_define(Def, Val)
%define SWIG_define(Def, Val...)
%#define Def Val
%enddef

View file

@ -13,7 +13,7 @@
%typecheck(SWIG_TYPECHECK_POINTER) SWIG_Object "$1 = ($input != 0);";
%typemap(throws,noblock=1) SWIG_Object {
SWIG_exception_obj(0, "$type", $1);
SWIG_raise($1, "$type", 0);
}
%typemap(constcode,noblock=1) SWIG_Object {

View file

@ -357,19 +357,19 @@
* ------------------------------------------------------------ */
%typemap(throws,noblock=1) SWIGTYPE {
SWIG_exception_obj($&descriptor, "$type", SWIG_NewPointerObj(SWIG_new_copy($1, $ltype),$&descriptor,SWIG_POINTER_OWN));
SWIG_raise(SWIG_NewPointerObj(SWIG_new_copy($1, $ltype),$&descriptor,SWIG_POINTER_OWN), "$type", $&descriptor);
}
%typemap(throws,noblock=1) SWIGTYPE * {
SWIG_exception_obj($descriptor, "$type", SWIG_NewPointerObj(SWIG_as_voidptr($1),$descriptor,0));
SWIG_raise(SWIG_NewPointerObj(SWIG_as_voidptr($1),$descriptor,0), "$type", $descriptor);
}
%typemap(throws,noblock=1) SWIGTYPE [ANY] {
SWIG_exception_obj($descriptor, "$type", SWIG_NewPointerObj(SWIG_as_voidptr($1),$descriptor,0));
SWIG_raise(SWIG_NewPointerObj(SWIG_as_voidptr($1),$descriptor,0), "$type", $descriptor);
}
%typemap(throws,noblock=1) SWIGTYPE & {
SWIG_exception_obj($descriptor, "$type", SWIG_NewPointerObj(SWIG_as_voidptr(&$1),$descriptor,0));
SWIG_raise(SWIG_NewPointerObj(SWIG_as_voidptr(&$1),$descriptor,0), "$type", $descriptor);
}
/* ------------------------------------------------------------

View file

@ -124,7 +124,7 @@
%define SWIG_VALUE_THROWS_TYPEMAP(from_meth,frag,Type...)
%typemap(throws,noblock=1,fragment=frag) Type {
SWIG_exception_obj(0, "Type", from_meth(SWIG_static_cast($1,$basetype)));
SWIG_raise(from_meth(SWIG_static_cast($1,Type)), "$type", 0);
}
%enddef

View file

@ -10,7 +10,7 @@
}
}
%typemap(freearg,noblock=1) void * "";
%typemap(freearg) void * "";
%typemap(in,noblock=1) void * const& ($*ltype temp) {
if (SWIG_ConvertPtr($input, SWIG_as_voidptrptr(&temp), 0, $disown) != SWIG_OK) {
@ -23,7 +23,7 @@
/* out */
%typemap(out,noblock=1) void {
SWIG_set_result(SWIG_NoneObject());
SWIG_set_result(SWIG_VoidObject());
}
/* varin */