From 7c475898c2b4a35ed6b2edd87b4fd798e1866dca Mon Sep 17 00:00:00 2001 From: Mark Gossage Date: Mon, 11 Sep 2006 06:49:47 +0000 Subject: [PATCH] added support for multiple modules & multiple interpreters git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9265 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Lib/swiginit.swg | 45 ++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/SWIG/Lib/swiginit.swg b/SWIG/Lib/swiginit.swg index e14ea7b7b..c196a8c01 100644 --- a/SWIG/Lib/swiginit.swg +++ b/SWIG/Lib/swiginit.swg @@ -53,29 +53,44 @@ extern "C" { SWIGRUNTIME void SWIG_InitializeModule(void *clientdata) { size_t i; - swig_module_info *module_head; - static int init_run = 0; + swig_module_info *module_head, *iter; + int found; clientdata = clientdata; - if (init_run) return; - init_run = 1; - - /* Initialize the swig_module */ - swig_module.type_initial = swig_type_initial; - swig_module.cast_initial = swig_cast_initial; - /* Try and load any already created modules */ module_head = SWIG_GetModule(clientdata); - if (module_head) { + if (!module_head) { + /* This is the first module loaded for this interpreter */ + /* so set the swig module into the interpreter */ + SWIG_SetModule(clientdata, &swig_module); + module_head = &swig_module; + /* check to see if the circular list has been setup, if not, set it up */ + if (swig_module.next==0) { + /* Initialize the swig_module */ + swig_module.type_initial = swig_type_initial; + swig_module.cast_initial = swig_cast_initial; + swig_module.next = &swig_module; + } + } else { + /* the interpreter has loaded a SWIG module, but has it loaded this one? */ + found=0; + iter=module_head; + do { + if (iter==&swig_module) { + found=1; + break; + } + iter=iter->next; + } while (iter!= module_head); + + /* if the is found in the list, then all is done and we may leave */ + if (found) return; + /* otherwise we must add out module into the list */ swig_module.next = module_head->next; module_head->next = &swig_module; - } else { - /* This is the first module loaded */ - swig_module.next = &swig_module; - SWIG_SetModule(clientdata, &swig_module); } - + /* Now work on filling in swig_module.types */ #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: size %d\n", swig_module.size);