diff --git a/Lib/perl5/perl5.swg b/Lib/perl5/perl5.swg index 24d6b1b59..17c903c7c 100644 --- a/Lib/perl5/perl5.swg +++ b/Lib/perl5/perl5.swg @@ -565,84 +565,4 @@ SWIG_croak($1); } -/* Export the SWIG initialization function */ -%header %{ -#ifdef __cplusplus -extern "C" -#endif -#ifndef PERL_OBJECT -#ifndef MULTIPLICITY -SWIGEXPORT(void) SWIG_init (CV* cv); -#else -SWIGEXPORT(void) SWIG_init (pTHXo_ CV* cv); -#endif -#else -SWIGEXPORT(void) SWIG_init (CV *cv, CPerlObj *); -#endif -%} - -/* Module initialization function */ - -%init %{ -#ifdef __cplusplus -extern "C" -#endif - -XS(SWIG_init) { - dXSARGS; - int i; - static int _init = 0; - if (!_init) { - SWIG_Perl_LookupTypePointer(); - for (i = 0; swig_types_initial[i]; i++) { - swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]); - } - _init = 1; - } - - /* Install commands */ - for (i = 0; swig_commands[i].name; i++) { - newXS((char*) swig_commands[i].name,swig_commands[i].wrapper, (char*)__FILE__); - } - - /* Install variables */ - for (i = 0; swig_variables[i].name; i++) { - SV *sv; - sv = perl_get_sv((char*) swig_variables[i].name, TRUE | 0x2); - if (swig_variables[i].type) { - SWIG_MakePtr(sv,(void *)1, *swig_variables[i].type,0); - } else { - sv_setiv(sv,(IV) 0); - } - swig_create_magic(sv, (char *) swig_variables[i].name, swig_variables[i].set, swig_variables[i].get); - } - - /* Install constant */ - for (i = 0; swig_constants[i].type; i++) { - SV *sv; - sv = perl_get_sv((char*)swig_constants[i].name, TRUE | 0x2); - switch(swig_constants[i].type) { - case SWIG_INT: - sv_setiv(sv, (IV) swig_constants[i].lvalue); - break; - case SWIG_FLOAT: - sv_setnv(sv, (double) swig_constants[i].dvalue); - break; - case SWIG_STRING: - sv_setpv(sv, (char *) swig_constants[i].pvalue); - break; - case SWIG_POINTER: - SWIG_MakePtr(sv, swig_constants[i].pvalue, *(swig_constants[i].ptype),0); - break; - case SWIG_BINARY: - SWIG_MakePackedObj(sv, swig_constants[i].pvalue, swig_constants[i].lvalue, *(swig_constants[i].ptype)); - break; - default: - break; - } - SvREADONLY_on(sv); - } -%} - - - +%include "perlinit.swg" diff --git a/Lib/perl5/perlinit.swg b/Lib/perl5/perlinit.swg new file mode 100644 index 000000000..00164b4e5 --- /dev/null +++ b/Lib/perl5/perlinit.swg @@ -0,0 +1,104 @@ + +/* Export the SWIG initialization function */ +%header %{ +#ifdef __cplusplus +extern "C" +#endif +#ifndef PERL_OBJECT +#ifndef MULTIPLICITY +SWIGEXPORT(void) SWIG_init (CV* cv); +#else +SWIGEXPORT(void) SWIG_init (pTHXo_ CV* cv); +#endif +#else +SWIGEXPORT(void) SWIG_init (CV *cv, CPerlObj *); +#endif +%} + +/* Module initialization function */ + +%init %{ + +static void SWIG_Perl_SetTypeListHandle(swig_type_info **handle) { + SV *pointer; + + /* create a new pointer */ + pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TRUE); + sv_setiv(pointer, PTR2IV(swig_type_list_handle)); +} + +static swig_type_info ** +SWIG_Perl_LookupTypePointer(swig_type_info **type_list_handle) { + swig_type_info **type_pointer; + + /* first check if module already created */ + type_pointer = SWIG_Perl_GetTypeListHandle(); + if (type_pointer) { + return type_pointer; + } else { + /* create a new module and variable */ + SWIG_Perl_SetTypeListHandle(type_list_handle); + return type_list_handle; + } +} + + +#ifdef __cplusplus +extern "C" +#endif + +XS(SWIG_init) { + dXSARGS; + int i; + static int _init = 0; + if (!_init) { + swig_type_list_handle = SWIG_Perl_LookupTypePointer(swig_type_list_handle); + for (i = 0; swig_types_initial[i]; i++) { + swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]); + } + _init = 1; + } + + /* Install commands */ + for (i = 0; swig_commands[i].name; i++) { + newXS((char*) swig_commands[i].name,swig_commands[i].wrapper, (char*)__FILE__); + } + + /* Install variables */ + for (i = 0; swig_variables[i].name; i++) { + SV *sv; + sv = perl_get_sv((char*) swig_variables[i].name, TRUE | 0x2); + if (swig_variables[i].type) { + SWIG_MakePtr(sv,(void *)1, *swig_variables[i].type,0); + } else { + sv_setiv(sv,(IV) 0); + } + swig_create_magic(sv, (char *) swig_variables[i].name, swig_variables[i].set, swig_variables[i].get); + } + + /* Install constant */ + for (i = 0; swig_constants[i].type; i++) { + SV *sv; + sv = perl_get_sv((char*)swig_constants[i].name, TRUE | 0x2); + switch(swig_constants[i].type) { + case SWIG_INT: + sv_setiv(sv, (IV) swig_constants[i].lvalue); + break; + case SWIG_FLOAT: + sv_setnv(sv, (double) swig_constants[i].dvalue); + break; + case SWIG_STRING: + sv_setpv(sv, (char *) swig_constants[i].pvalue); + break; + case SWIG_POINTER: + SWIG_MakePtr(sv, swig_constants[i].pvalue, *(swig_constants[i].ptype),0); + break; + case SWIG_BINARY: + SWIG_MakePackedObj(sv, swig_constants[i].pvalue, swig_constants[i].lvalue, *(swig_constants[i].ptype)); + break; + default: + break; + } + SvREADONLY_on(sv); + } +%} diff --git a/Lib/perl5/perlrun.swg b/Lib/perl5/perlrun.swg index 6aa118bd5..3ce21ee61 100644 --- a/Lib/perl5/perlrun.swg +++ b/Lib/perl5/perlrun.swg @@ -166,21 +166,33 @@ extern "C" { # define SWIG_MAYBE_PERL_OBJECT #endif -/* load the swig_runtime_list_handle variable from the interpreter */ -static void SWIG_Perl_LookupTypePointer() { +static swig_type_info ** +SWIG_Perl_GetTypeListHandle() { + static void *type_pointer = (void *)0; SV *pointer; /* first check if pointer already created */ - 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" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TRUE); - sv_setiv(pointer, PTR2IV(swig_type_list_handle)); + if (!type_pointer) { + pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, FALSE); + if (pointer && SvOK(pointer)) { + type_pointer = INT2PTR(swig_type_info **, SvIV(pointer)); + } } + + return (swig_type_info **) type_pointer; } +/* + Search for a swig_type_info structure + */ +SWIGRUNTIMEINLINE swig_type_info * +SWIG_Perl_GetTypeList() { + swig_type_info **tlh = SWIG_Perl_GetTypeListHandle(); + return tlh ? *tlh : (swig_type_info*)0; +} + +#define SWIG_Runtime_GetTypeList SWIG_Perl_GetTypeList + static swig_type_info * SWIG_Perl_TypeCheckRV(SWIG_MAYBE_PERL_OBJECT SV *rv, swig_type_info *ty) { swig_type_info *s; diff --git a/Lib/runtime.swg b/Lib/runtime.swg index 32315c848..1d7cc63f0 100644 --- a/Lib/runtime.swg +++ b/Lib/runtime.swg @@ -6,6 +6,11 @@ #include // or using your favorite language #include #include // or using your favorite language +#include + + For perl, the following +#include +#include #include * -----------------------------------------------------------------------------*/