- 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
This commit is contained in:
John Lenz 2004-10-21 21:53:54 +00:00
commit 0c57969c61
14 changed files with 140 additions and 41 deletions

View file

@ -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),

View file

@ -30,6 +30,9 @@ Foo *makeFoo() {
int fooCount() {
return g_fooCount;
}
void do_stuff(Foo *f) {
}
%}
%extend Foo {

View file

@ -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));
}

View file

@ -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;

View file

@ -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;
}

View file

@ -11,6 +11,16 @@
#include <string.h>
#include <stdlib.h>
#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);

View file

@ -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))) {

24
Lib/linkruntime.c Normal file
View file

@ -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;
}

View file

@ -2,7 +2,7 @@
* -----------------------------------------------------------------------
* swig_lib/mzscheme/mzrun.swg
*
* Author: John Lenz <jelenz@students.wisc.edu>
* Author: John Lenz <lenz@cs.wisc.edu>
* ----------------------------------------------------------------------- */
#include <stdio.h>
@ -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]))

View file

@ -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);

View file

@ -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]);
}

View file

@ -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);
}
}
}

View file

@ -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);

View file

@ -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];