From 0c57969c61e37911bcf6145d04cdcf2b5e3a96e6 Mon Sep 17 00:00:00 2001 From: John Lenz Date: Thu, 21 Oct 2004 21:53:54 +0000 Subject: [PATCH] - Add SWIG_RUNTIME_VERSION to new type sharing code. This is for future-proof, if the format of swig_type_info ever changes, this number should be incremented - Add SWIG_LINK_RUNTIME and SWIG_STATIC_RUNTIME symbols to python - Convert inline into SWIGINLINE git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6475 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- CHANGES.current | 16 ++++++++++++++++ Examples/test-suite/newobject2.i | 3 +++ Lib/chicken/chicken.swg | 9 +++++---- Lib/chicken/chickenrun.swg | 4 ++-- Lib/common.swg | 23 +++++++++++++++++++++-- Lib/guile/guile_gh_run.swg | 14 ++++++++++++-- Lib/guile/guile_scm_run.swg | 10 +++++----- Lib/linkruntime.c | 24 ++++++++++++++++++++++++ Lib/mzscheme/mzrun.swg | 10 +++++----- Lib/perl5/perlrun.swg | 12 ++++++------ Lib/python/pyinit.swg | 26 ++++++++++++++++++++++++++ Lib/python/pyrun.swg | 10 +++++----- Lib/ruby/rubydef.swg | 10 +++++----- Lib/tcl/swigtcl8.swg | 10 +++++----- 14 files changed, 140 insertions(+), 41 deletions(-) create mode 100644 Lib/linkruntime.c diff --git a/CHANGES.current b/CHANGES.current index 848b2fc93..19eeaa2bb 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,22 @@ Version 1.3.23 (in progress) ============================ +10/21/2004: wuzzeb (John Lenz) + - If you define SWIG_TYPE_TABLE when compiling a wrapper file, + the runtime types will be stored in the given type table name. + Using this, you can seperate different modules to share their + own type systems. -DSWIG_TYPE_TABLE=Mytable + + - [Python] If you define SWIG_STATIC_RUNTIME then the type information + will be static to this wrapper. Nothing will be shared with any + other modules + + - [Python] If you define SWIG_LINK_RUNTIME, then instead of using + the new way of sharing type information, the wrapper will expect + to be linked against the Lib/linkruntime.c file. Any modules compiled + with SWIG_LINK_RUNTIME and linked against linkruntime.c will all + share type information. + 10/20/2004: mmatus - [Python] Initial fix for python/import example. Please update the Makefile (autoconf, configure, etc, expert), diff --git a/Examples/test-suite/newobject2.i b/Examples/test-suite/newobject2.i index 99f03d14a..f0c43edeb 100644 --- a/Examples/test-suite/newobject2.i +++ b/Examples/test-suite/newobject2.i @@ -30,6 +30,9 @@ Foo *makeFoo() { int fooCount() { return g_fooCount; } + +void do_stuff(Foo *f) { +} %} %extend Foo { diff --git a/Lib/chicken/chicken.swg b/Lib/chicken/chicken.swg index 7537a2da4..022380cc5 100644 --- a/Lib/chicken/chicken.swg +++ b/Lib/chicken/chicken.swg @@ -592,6 +592,7 @@ SWIGEXPORT(void) SWIG_init(int, C_word, C_word) C_noret; %insert(init) %{ /* CHICKEN initialization function */ +static char[] swig_type_ptr_name = "type_pointer" SWIG_TYPE_TABLE_NAME; SWIGEXPORT(void) SWIG_init(int argc, C_word closure, C_word continuation) { static int typeinit = 0; @@ -603,15 +604,15 @@ SWIG_init(int argc, C_word closure, C_word continuation) { if (!typeinit) { /* lookup the type pointer... it is stored in it's own symbol table */ - C_SYMBOL_TABLE *stable = C_find_symbol_table("swig_runtime_data"); + C_SYMBOL_TABLE *stable = C_find_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION); if (stable != NULL) { - sym = SWIG_Chicken_LookupSymbol("type_pointer", stable); + sym = SWIG_Chicken_LookupSymbol(swig_type_ptr_name, stable); if (C_truep(sym) && C_swig_is_ptr(sym)) { swig_type_list_handle = (swig_type_info **) C_block_item(sym, 0); } } else { - stable = C_new_symbol_table("swig_runtime_data", 16); - sym = C_intern_in(C_heaptop, C_strlen("type_pointer"), "type_pointer", stable); + stable = C_new_symbol_table("swig_runtime_data" SWIG_RUNTIME_VERSION, 16); + sym = C_intern_in(C_heaptop, C_strlen(swig_type_ptr_name), swig_type_ptr_name, stable); C_mutate(&C_block_item(sym, 0), C_mpointer(C_heaptop, (void *) swig_type_list_handle)); } diff --git a/Lib/chicken/chickenrun.swg b/Lib/chicken/chickenrun.swg index f2d071d67..6706a02f3 100644 --- a/Lib/chicken/chickenrun.swg +++ b/Lib/chicken/chickenrun.swg @@ -161,7 +161,7 @@ SWIG_Chicken_Barf(int code, C_char *msg, ...) } } -static inline C_word +static SWIGINLINE C_word SWIG_Chicken_NewPointerObj(void *ptr, swig_type_info *type, int owner, C_word **data) { if (ptr == NULL) @@ -199,7 +199,7 @@ SWIG_Chicken_ConvertPtr(C_word s, void **result, swig_type_info *type, int flags return 1; } -static inline void * +static SWIGINLINE void * SWIG_Chicken_MustGetPtr (C_word s, swig_type_info *type, int argnum, int flags) { void *result; diff --git a/Lib/common.swg b/Lib/common.swg index f92789f05..00fd49ec6 100644 --- a/Lib/common.swg +++ b/Lib/common.swg @@ -27,6 +27,25 @@ #define SWIGRUNTIME(x) static x +#if defined(__cplusplus) || defined(__GNUC__) +# define SWIGINLINE inline +#else +# define SWIGINLINE +#endif + +/* This should only be incremented when either the layout of swig_type_info changes, + or for whatever reason, the runtime changes incompatibly */ +#define SWIG_RUNTIME_VERSION "1" + +/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ +#ifdef SWIG_TYPE_TABLE +#define SWIG_QUOTE_STRING(x) #x +#define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) +#define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) +#else +#define SWIG_TYPE_TABLE_NAME +#endif + #ifdef __cplusplus extern "C" { #endif @@ -114,7 +133,7 @@ SWIG_TypeCheck(char *c, swig_type_info *ty) { } /* Cast a pointer up an inheritance hierarchy */ -static inline void * +static SWIGINLINE void * SWIG_TypeCast(swig_type_info *ty, void *ptr) { if ((!ty) || (!ty->converter)) return ptr; return (*ty->converter)(ptr); @@ -133,7 +152,7 @@ SWIG_TypeDynamicCast(swig_type_info *ty, void **ptr) { } /* Return the name associated with this type */ -static inline const char * +static SWIGINLINE const char * SWIG_TypeName(const swig_type_info *ty) { return ty->name; } diff --git a/Lib/guile/guile_gh_run.swg b/Lib/guile/guile_gh_run.swg index 248093a41..fa5a2c19d 100644 --- a/Lib/guile/guile_gh_run.swg +++ b/Lib/guile/guile_gh_run.swg @@ -11,6 +11,16 @@ #include #include +#define SWIG_RUNTIME_VERSION "1" +/* define SWIG_TYPE_TABLE_NAME as "SWIG_TYPE_TABLE" */ +#ifdef SWIG_TYPE_TABLE +#define SWIG_QUOTE_STRING(x) #x +#define SWIG_EXPAND_AND_QUOTE_STRING(x) SWIG_QUOTE_STRING(x) +#define SWIG_TYPE_TABLE_NAME SWIG_EXPAND_AND_QUOTE_STRING(SWIG_TYPE_TABLE) +#else +#define SWIG_TYPE_TABLE_NAME +#endif + #ifdef __cplusplus extern "C" { #endif @@ -426,10 +436,10 @@ SWIG_Guile_Init (void) { SCM pointer; - pointer = gh_lookup("swig_runtime_data_type_pointer"); + pointer = gh_lookup("swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); if (pointer == SCM_UNDEFINED) { pointer = gh_ulong2scm((unsigned long)SwigModule); - gh_define("swig_runtime_data_type_pointer", pointer); + gh_define("swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, pointer); if (SwigModule->swig_tag == 0) { SwigModule->swig_tag = scm_make_smob_type_mfpe((char *) "swig", 0, NULL, NULL, print_swig, equalp_swig); diff --git a/Lib/guile/guile_scm_run.swg b/Lib/guile/guile_scm_run.swg index bd6ba1148..d1dddcdc0 100644 --- a/Lib/guile/guile_scm_run.swg +++ b/Lib/guile/guile_scm_run.swg @@ -165,7 +165,7 @@ SWIG_Guile_ConvertPtr(SCM s, void **result, swig_type_info *type, int flags) return 1; } -static inline void * +static SWIGINLINE void * SWIG_Guile_MustGetPtr (SCM s, swig_type_info *type, int argnum, int flags, const char *func_name) { @@ -177,7 +177,7 @@ SWIG_Guile_MustGetPtr (SCM s, swig_type_info *type, return result; } -static inline int +static SWIGINLINE int SWIG_Guile_IsPointerOfType (SCM s, swig_type_info *type) { void *result; @@ -187,8 +187,8 @@ SWIG_Guile_IsPointerOfType (SCM s, swig_type_info *type) } else return 1; } - -static inline int + +static SWIGINLINE int SWIG_Guile_IsPointer (SCM s) { return SWIG_Guile_IsPointerOfType (s, NULL); @@ -330,7 +330,7 @@ SWIG_Guile_Init () scm_set_smob_equalp(swig_destroyed_tag, equalp_swig); } { - SCM variable = scm_sym2var(scm_str2symbol("swig-type-list-address"), + SCM variable = scm_sym2var(scm_str2symbol("swig-type-list-address" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME), scm_module_lookup_closure(swig_module), SCM_BOOL_T); if (SCM_UNBNDP(SCM_VARIABLE_REF(variable))) { diff --git a/Lib/linkruntime.c b/Lib/linkruntime.c new file mode 100644 index 000000000..89021fd2c --- /dev/null +++ b/Lib/linkruntime.c @@ -0,0 +1,24 @@ +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# if defined(_MSC_VER) || defined(__GNUC__) +# if defined(STATIC_LINKED) +# define SWIGEXPORT(a) a +# else +# define SWIGEXPORT(a) __declspec(dllexport) a +# endif +# else +# if defined(__BORLANDC__) +# define SWIGEXPORT(a) a _export +# else +# define SWIGEXPORT(a) a +# endif +# endif +#else +# define SWIGEXPORT(a) a +#endif + +static void *ptr = 0; +SWIGEXPORT(void *) +SWIG_ReturnGlobalTypeList(void *t) { + if (!ptr) ptr = t; + return ptr; +} diff --git a/Lib/mzscheme/mzrun.swg b/Lib/mzscheme/mzrun.swg index 4a629f349..609384d16 100644 --- a/Lib/mzscheme/mzrun.swg +++ b/Lib/mzscheme/mzrun.swg @@ -2,7 +2,7 @@ * ----------------------------------------------------------------------- * swig_lib/mzscheme/mzrun.swg * - * Author: John Lenz + * Author: John Lenz * ----------------------------------------------------------------------- */ #include @@ -56,7 +56,7 @@ SWIG_MzScheme_LookupTypePointer(Scheme_Env *env) { struct swig_mzscheme_runtime_data *data; /* first check if pointer already created */ - symbol = scheme_intern_symbol("swig-runtime-data-type-pointer"); + symbol = scheme_intern_symbol("swig-runtime-data-type-pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); pointer = scheme_lookup_global(symbol, env); if (pointer && SCHEME_CPTRP(pointer)) { data = (struct swig_mzscheme_runtime_data *) SCHEME_CPTR_VAL(pointer); @@ -125,7 +125,7 @@ SWIG_MzScheme_ConvertPtr(Scheme_Object *s, void **result, swig_type_info *type, return 1; } -static inline void * +static SWIGINLINE void * SWIG_MzScheme_MustGetPtr(Scheme_Object *s, swig_type_info *type, int argnum, int flags, const char *func_name, int argc, Scheme_Object **argv) { @@ -136,7 +136,7 @@ SWIG_MzScheme_MustGetPtr(Scheme_Object *s, swig_type_info *type, return result; } -static inline void * +static SWIGINLINE void * SWIG_MzScheme_Malloc(size_t size, const char *func_name) { void *p = malloc(size); if (p == NULL) { @@ -144,7 +144,7 @@ SWIG_MzScheme_Malloc(size_t size, const char *func_name) { } else return p; } -static inline Scheme_Object * +static Scheme_Object * SWIG_MzScheme_PackageValues(int num, Scheme_Object **values) { /* ignore first value if void */ if (num > 0 && SCHEME_VOIDP(values[0])) diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index 4c8c35898..1ef5dde5b 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -175,12 +175,12 @@ static void SWIG_Perl_LookupTypePointer() { SV *pointer; /* first check if pointer already created */ - pointer = get_sv("swig_runtime_data::type_pointer", FALSE); + pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, FALSE); if (pointer && SvOK(pointer)) { swig_type_list_handle = INT2PTR(swig_type_info **, SvIV(pointer)); } else { /* create a new pointer */ - pointer = get_sv("swig_runtime_data::type_pointer", TRUE); + pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TRUE); sv_setiv(pointer, PTR2IV(swig_type_list_handle)); } } @@ -302,7 +302,7 @@ SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, i } } -static inline SV * +static SWIGINLINE SV * SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *ptr, swig_type_info *t, int flags) { SV *result = sv_newmortal(); SWIG_MakePtr(result, ptr, t, flags); @@ -339,17 +339,17 @@ SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *obj, void *ptr, int sz, swig_ return 0; } -static inline void +static SWIGINLINE void SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT const char *error) { if (error) sv_setpv(perl_get_sv("@", TRUE), error); } -static inline void +static SWIGINLINE void SWIG_Perl_SetErrorSV(SWIG_MAYBE_PERL_OBJECT SV *error) { if (error) sv_setsv(perl_get_sv("@", TRUE), error); } -static inline void +static void SWIG_Perl_SetErrorf(const char *fmt, ...) { va_list args; va_start(args, fmt); diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 6095af663..6f7349df4 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -4,6 +4,25 @@ %init %{ +#ifdef SWIG_LINK_RUNTIME +#if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) +# if defined(_MSC_VER) || defined(__GNUC__) +# define SWIGIMPORT(a) extern a +# else +# if defined(__BORLANDC__) +# define SWIGIMPORT(a) a _export +# else +# define SWIGIMPORT(a) a +# endif +# endif +#else +# define SWIGIMPORT(a) a +#endif +#ifdef __cplusplus +extern "C" +#endif +SWIGEXPORT(void *) SWIG_ReturnGlobalTypeList(void *); +#endif #ifdef __cplusplus extern "C" @@ -22,7 +41,14 @@ SWIGEXPORT(void) SWIG_init(void) { d = PyModule_GetDict(m); if (!typeinit) { +#ifdef SWIG_LINK_RUNTIME + swig_type_list_handle = (swig_type_info **) SWIG_ReturnGlobalTypeList(swig_type_list_handle); +#else +# ifndef SWIG_STATIC_RUNTIME SWIG_Python_LookupTypePointer(&swig_type_list_handle); +# endif +#endif + printf("%08x\n", swig_type_list_handle); for (i = 0; swig_types_initial[i]; i++) { swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]); } diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index d9f978110..ddc72ddf8 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -181,7 +181,7 @@ SWIG_Python_TypeError(const char *type, PyObject *obj) } } -static inline void +static SWIGINLINE void SWIG_Python_NullRef(const char *type) { if (type) { @@ -346,7 +346,7 @@ type_error: } /* Convert a pointer value, signal an exception on a type mismatch */ -static inline void * +static void * SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) { void *result; if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) { @@ -539,16 +539,16 @@ SWIG_Python_LookupTypePointer(swig_type_info ***type_list_handle) { void *type_pointer; /* first check if module already created */ - type_pointer = PyCObject_Import("swig_runtime_data", "type_pointer"); + type_pointer = PyCObject_Import("swig_runtime_data" SWIG_RUNTIME_VERSION, "type_pointer" SWIG_TYPE_TABLE_NAME); if (type_pointer) { *type_list_handle = (swig_type_info **) type_pointer; } else { PyErr_Clear(); /* create a new module and variable */ - module = Py_InitModule("swig_runtime_data", NULL); + module = Py_InitModule("swig_runtime_data" SWIG_RUNTIME_VERSION, NULL); pointer = PyCObject_FromVoidPtr((void *) (*type_list_handle), NULL); if (pointer && module) { - PyModule_AddObject(module, "type_pointer", pointer); + PyModule_AddObject(module, "type_pointer" SWIG_TYPE_TABLE_NAME, pointer); } } } diff --git a/Lib/ruby/rubydef.swg b/Lib/ruby/rubydef.swg index e8ac42dd9..32b0099e9 100644 --- a/Lib/ruby/rubydef.swg +++ b/Lib/ruby/rubydef.swg @@ -43,7 +43,7 @@ SWIG_Ruby_InitRuntime(void) } /* first check if pointer already created */ - pointer = rb_gv_get("$swig_runtime_data_type_pointer"); + pointer = rb_gv_get("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME); if (pointer != Qnil) { Data_Get_Struct(pointer, swig_type_info *, swig_type_list_handle); } else { @@ -51,7 +51,7 @@ SWIG_Ruby_InitRuntime(void) VALUE cl = rb_define_class("swig_runtime_data", rb_cObject); /* create and store the structure pointer to a global variable */ swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, swig_type_list_handle); - rb_define_readonly_variable("$swig_runtime_data_type_pointer", &swig_runtime_data_type_pointer); + rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer); } } @@ -108,7 +108,7 @@ SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type) } /* Get type mangle from class name */ -static char * +static SWIGINLINE char * SWIG_Ruby_MangleStr(VALUE obj) { VALUE stype = rb_iv_get(obj, "__swigtype__"); @@ -158,7 +158,7 @@ SWIG_Ruby_ConvertPtr(VALUE obj, void **ptr, swig_type_info *ty, int flags) } /* Convert a pointer value, signal an exception on a type mismatch */ -static inline void * +static SWIGINLINE void * SWIG_Ruby_MustGetPtr(VALUE obj, swig_type_info *ty, int argnum, int flags) { void *result; @@ -167,7 +167,7 @@ SWIG_Ruby_MustGetPtr(VALUE obj, swig_type_info *ty, int argnum, int flags) } /* Check convert */ -static inline int +static SWIGINLINE int SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty) { char *c = SWIG_MangleStr(obj); diff --git a/Lib/tcl/swigtcl8.swg b/Lib/tcl/swigtcl8.swg index 6a7b7ef8e..c8b2294d1 100644 --- a/Lib/tcl/swigtcl8.swg +++ b/Lib/tcl/swigtcl8.swg @@ -111,14 +111,14 @@ SWIG_Tcl_LookupTypePointer(Tcl_Interp *interp) { char *data; /* first check if pointer already created */ - data = (char *) Tcl_GetVar(interp, "swig_runtime_data_type_pointer", TCL_GLOBAL_ONLY); + data = (char *) Tcl_GetVar(interp, "swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TCL_GLOBAL_ONLY); if (data) { SWIG_UnpackData(data, &swig_type_list_handle, sizeof(swig_type_info **)); } else { /* create a new pointer */ data = SWIG_PackData(buf, &swig_type_list_handle, sizeof(swig_type_info **)); *data = 0; - Tcl_SetVar(interp, "swig_runtime_data_type_pointer", buf, 0); + Tcl_SetVar(interp, "swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, buf, 0); } } @@ -151,7 +151,7 @@ SWIG_Tcl_Disown(void *ptr) { return 0; } -static inline int +static int SWIG_Tcl_Thisown(void *ptr) { if (!swigobjectTableinit) return 0; if (Tcl_FindHashEntry(&swigobjectTable, (char *) ptr)) { @@ -200,7 +200,7 @@ SWIG_Tcl_ConvertPtrFromString(Tcl_Interp *interp, char *c, void **ptr, swig_type } /* Convert a pointer value */ -static inline int +static SWIGINLINE int SWIG_Tcl_ConvertPtr(Tcl_Interp *interp, Tcl_Obj *oc, void **ptr, swig_type_info *ty, int flags) { return SWIG_Tcl_ConvertPtrFromString(interp, Tcl_GetStringFromObj(oc,NULL), ptr, ty, flags); } @@ -270,7 +270,7 @@ SWIG_Tcl_MakePtr(char *c, void *ptr, swig_type_info *ty, int flags) { } /* Create a new pointer object */ -static Tcl_Obj * +static SWIGINLINE Tcl_Obj * SWIG_Tcl_NewPointerObj(void *ptr, swig_type_info *type, int flags) { Tcl_Obj *robj; char result[512];