Allow Octave modules to be re-loaded after a "clear all" (thanks to Karl Wette; SF 3418908)
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12824 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
690185fe85
commit
f8774be92d
8 changed files with 196 additions and 17 deletions
|
|
@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 2.0.5 (in progress)
|
Version 2.0.5 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2011-09-13: xavier98
|
||||||
|
[octave] Allow Octave modules to be re-loaded after a "clear all".
|
||||||
|
|
||||||
2011-09-19: wsfulton
|
2011-09-19: wsfulton
|
||||||
Fix regression introduced in swig-2.0.1 reported by Teemu Ikonone leading to uncompilable code
|
Fix regression introduced in swig-2.0.1 reported by Teemu Ikonone leading to uncompilable code
|
||||||
when using typedef and function pointer references, for example:
|
when using typedef and function pointer references, for example:
|
||||||
|
|
|
||||||
|
|
@ -333,7 +333,7 @@ python_clean:
|
||||||
# Make sure these locate your Octave installation
|
# Make sure these locate your Octave installation
|
||||||
OCTAVE_INCLUDE= $(DEFS) @OCTAVEEXT@
|
OCTAVE_INCLUDE= $(DEFS) @OCTAVEEXT@
|
||||||
OCTAVE_LIB =
|
OCTAVE_LIB =
|
||||||
OCTAVE = @OCTAVE@
|
OCTAVE = @OCTAVE@ -qf
|
||||||
|
|
||||||
# Extra Octave specific dynamic linking options
|
# Extra Octave specific dynamic linking options
|
||||||
OCTAVE_DLNK = @OCTAVEDYNAMICLINKING@
|
OCTAVE_DLNK = @OCTAVEDYNAMICLINKING@
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
# test module loading with arguments
|
# test module loading with arguments
|
||||||
|
|
||||||
|
##### BEGIN TEST #####
|
||||||
# test help
|
# test help
|
||||||
example -help
|
example -help
|
||||||
assert(!isglobal("example"))
|
assert(!isglobal("example"))
|
||||||
|
|
@ -10,3 +11,30 @@ assert(!isglobal("example"))
|
||||||
example -globals mycvar
|
example -globals mycvar
|
||||||
assert(!isglobal("cvar"))
|
assert(!isglobal("cvar"))
|
||||||
assert(mycvar.ivar == example.ifunc())
|
assert(mycvar.ivar == example.ifunc())
|
||||||
|
##### END TEST #####
|
||||||
|
|
||||||
|
# clearing a module results in a segfault for Octave <= 3.0.*
|
||||||
|
# (tested on Octave 3.0.5), so skip the following test
|
||||||
|
try
|
||||||
|
vers = cellfun("str2num", strsplit(OCTAVE_VERSION, "."));
|
||||||
|
catch
|
||||||
|
vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, ".")));
|
||||||
|
end_try_catch
|
||||||
|
assert(length(vers) >= 2);
|
||||||
|
if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0)
|
||||||
|
disp("skipping 'clear all' test");
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
clear all;
|
||||||
|
|
||||||
|
##### BEGIN TEST #####
|
||||||
|
# test help
|
||||||
|
example -help
|
||||||
|
assert(!isglobal("example"))
|
||||||
|
|
||||||
|
# load module with custom cvar
|
||||||
|
example -globals mycvar
|
||||||
|
assert(!isglobal("cvar"))
|
||||||
|
assert(mycvar.ivar == example.ifunc())
|
||||||
|
##### END TEST #####
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,57 @@
|
||||||
# test whether module can be loaded
|
# test whether module can be loaded
|
||||||
# in a function (global cvar)
|
# in a function (global cvar)
|
||||||
|
|
||||||
# test that everything works from the base context
|
1;
|
||||||
example
|
|
||||||
global cvar
|
|
||||||
assert(cvar.ivar == example.ifunc())
|
|
||||||
|
|
||||||
|
##### BEGIN TEST #####
|
||||||
function func
|
function func
|
||||||
example
|
example
|
||||||
global cvar
|
global cvar
|
||||||
assert(cvar.ivar == example.ifunc())
|
assert(cvar.ivar == example.ifunc())
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
# test that everything works from the base context
|
||||||
|
example
|
||||||
|
global cvar
|
||||||
|
assert(cvar.ivar == example.ifunc())
|
||||||
|
|
||||||
# test loading in a function
|
# test loading in a function
|
||||||
func
|
func
|
||||||
|
|
||||||
# test a second time to check everything works
|
# test a second time to check everything works
|
||||||
func
|
func
|
||||||
|
##### END TEST #####
|
||||||
|
|
||||||
|
# clearing a module results in a segfault for Octave <= 3.0.*
|
||||||
|
# (tested on Octave 3.0.5), so skip the following test
|
||||||
|
try
|
||||||
|
vers = cellfun("str2num", strsplit(OCTAVE_VERSION, "."));
|
||||||
|
catch
|
||||||
|
vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, ".")));
|
||||||
|
end_try_catch
|
||||||
|
assert(length(vers) >= 2);
|
||||||
|
if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0)
|
||||||
|
disp("skipping 'clear all' test");
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
clear all;
|
||||||
|
|
||||||
|
##### BEGIN TEST #####
|
||||||
|
function func
|
||||||
|
example
|
||||||
|
global cvar
|
||||||
|
assert(cvar.ivar == example.ifunc())
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
# test that everything works from the base context
|
||||||
|
example
|
||||||
|
global cvar
|
||||||
|
assert(cvar.ivar == example.ifunc())
|
||||||
|
|
||||||
|
# test loading in a function
|
||||||
|
func
|
||||||
|
|
||||||
|
# test a second time to check everything works
|
||||||
|
func
|
||||||
|
##### END TEST #####
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
##### BEGIN TEST #####
|
||||||
function func
|
function func
|
||||||
example
|
example
|
||||||
global cvar
|
global cvar
|
||||||
|
|
@ -21,3 +22,38 @@ func
|
||||||
example
|
example
|
||||||
global cvar
|
global cvar
|
||||||
assert(cvar.ivar == example.ifunc())
|
assert(cvar.ivar == example.ifunc())
|
||||||
|
##### END TEST #####
|
||||||
|
|
||||||
|
# clearing a module results in a segfault for Octave <= 3.0.*
|
||||||
|
# (tested on Octave 3.0.5), so skip the following test
|
||||||
|
try
|
||||||
|
vers = cellfun("str2num", strsplit(OCTAVE_VERSION, "."));
|
||||||
|
catch
|
||||||
|
vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, ".")));
|
||||||
|
end_try_catch
|
||||||
|
assert(length(vers) >= 2);
|
||||||
|
if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0)
|
||||||
|
disp("skipping 'clear all' test");
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
clear all;
|
||||||
|
|
||||||
|
##### BEGIN TEST #####
|
||||||
|
function func
|
||||||
|
example
|
||||||
|
global cvar
|
||||||
|
assert(cvar.ivar == example.ifunc())
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
# test loading in a function
|
||||||
|
func
|
||||||
|
|
||||||
|
# test a second time to check everything works
|
||||||
|
func
|
||||||
|
|
||||||
|
# test that everything works from the base context
|
||||||
|
example
|
||||||
|
global cvar
|
||||||
|
assert(cvar.ivar == example.ifunc())
|
||||||
|
##### END TEST #####
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,53 @@
|
||||||
# test whether module can be loaded
|
# test whether module can be loaded
|
||||||
# in a function (no global cvar)
|
# in a function (no global cvar)
|
||||||
|
|
||||||
# test that everything works from the base context
|
1;
|
||||||
example -noglobal
|
|
||||||
assert(example.cvar.ivar == example.ifunc())
|
|
||||||
|
|
||||||
|
##### BEGIN TEST #####
|
||||||
function func
|
function func
|
||||||
example -noglobal
|
example -noglobal
|
||||||
assert(example.cvar.ivar == example.ifunc())
|
assert(example.cvar.ivar == example.ifunc())
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
# test that everything works from the base context
|
||||||
|
example -noglobal
|
||||||
|
assert(example.cvar.ivar == example.ifunc())
|
||||||
|
|
||||||
# test loading in a function
|
# test loading in a function
|
||||||
func
|
func
|
||||||
|
|
||||||
# test a second time to check everything works
|
# test a second time to check everything works
|
||||||
func
|
func
|
||||||
|
##### END TEST #####
|
||||||
|
|
||||||
|
# clearing a module results in a segfault for Octave <= 3.0.*
|
||||||
|
# (tested on Octave 3.0.5), so skip the following test
|
||||||
|
try
|
||||||
|
vers = cellfun("str2num", strsplit(OCTAVE_VERSION, "."));
|
||||||
|
catch
|
||||||
|
vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, ".")));
|
||||||
|
end_try_catch
|
||||||
|
assert(length(vers) >= 2);
|
||||||
|
if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0)
|
||||||
|
disp("skipping 'clear all' test");
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
clear all;
|
||||||
|
|
||||||
|
##### BEGIN TEST #####
|
||||||
|
function func
|
||||||
|
example -noglobal
|
||||||
|
assert(example.cvar.ivar == example.ifunc())
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
# test that everything works from the base context
|
||||||
|
example -noglobal
|
||||||
|
assert(example.cvar.ivar == example.ifunc())
|
||||||
|
|
||||||
|
# test loading in a function
|
||||||
|
func
|
||||||
|
|
||||||
|
# test a second time to check everything works
|
||||||
|
func
|
||||||
|
##### END TEST #####
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
##### BEGIN TEST #####
|
||||||
function func
|
function func
|
||||||
example -noglobal
|
example -noglobal
|
||||||
assert(example.cvar.ivar == example.ifunc())
|
assert(example.cvar.ivar == example.ifunc())
|
||||||
|
|
@ -19,3 +20,36 @@ func
|
||||||
# test that everything works from the base context
|
# test that everything works from the base context
|
||||||
example -noglobal
|
example -noglobal
|
||||||
assert(example.cvar.ivar == example.ifunc())
|
assert(example.cvar.ivar == example.ifunc())
|
||||||
|
##### END TEST #####
|
||||||
|
|
||||||
|
# clearing a module results in a segfault for Octave <= 3.0.*
|
||||||
|
# (tested on Octave 3.0.5), so skip the following test
|
||||||
|
try
|
||||||
|
vers = cellfun("str2num", strsplit(OCTAVE_VERSION, "."));
|
||||||
|
catch
|
||||||
|
vers = cellfun("str2num", cellstr(split(OCTAVE_VERSION, ".")));
|
||||||
|
end_try_catch
|
||||||
|
assert(length(vers) >= 2);
|
||||||
|
if vers(1) < 3 || (vers(1) == 3 && vers(2) == 0)
|
||||||
|
disp("skipping 'clear all' test");
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
clear all;
|
||||||
|
|
||||||
|
##### BEGIN TEST #####
|
||||||
|
function func
|
||||||
|
example -noglobal
|
||||||
|
assert(example.cvar.ivar == example.ifunc())
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
# test loading in a function
|
||||||
|
func
|
||||||
|
|
||||||
|
# test a second time to check everything works
|
||||||
|
func
|
||||||
|
|
||||||
|
# test that everything works from the base context
|
||||||
|
example -noglobal
|
||||||
|
assert(example.cvar.ivar == example.ifunc())
|
||||||
|
##### END TEST #####
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,17 @@ static void SWIG_init_user(octave_swig_type* module_ns);
|
||||||
|
|
||||||
DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
|
DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
|
||||||
|
|
||||||
static bool already_init=false;
|
// determine if module is already loaded
|
||||||
static octave_swig_type* module_ns=0;
|
bool already_load;
|
||||||
|
#if OCTAVE_API_VERSION_NUMBER<37
|
||||||
// if module not already loaded
|
{
|
||||||
if (!already_init) {
|
symbol_record *rec = curr_sym_tab->lookup(SWIG_name_d);
|
||||||
|
already_load = (rec && rec->is_linked_to_global());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
already_load = symbol_table::is_global(SWIG_name_d);
|
||||||
|
#endif
|
||||||
|
if (!already_load) {
|
||||||
|
|
||||||
// parse command line
|
// parse command line
|
||||||
const char* usage="usage: " SWIG_name_d " [-global|-noglobal] [-globals <name>]";
|
const char* usage="usage: " SWIG_name_d " [-global|-noglobal] [-globals <name>]";
|
||||||
|
|
@ -64,8 +70,6 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
|
||||||
return octave_value_list();
|
return octave_value_list();
|
||||||
}
|
}
|
||||||
|
|
||||||
already_init=true;
|
|
||||||
|
|
||||||
// load module in base frame
|
// load module in base frame
|
||||||
#if OCTAVE_API_VERSION_NUMBER<37
|
#if OCTAVE_API_VERSION_NUMBER<37
|
||||||
symbol_table *prev_sym_tab = curr_sym_tab;
|
symbol_table *prev_sym_tab = curr_sym_tab;
|
||||||
|
|
@ -89,7 +93,7 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
|
||||||
if (swig_globals[j].get_method)
|
if (swig_globals[j].get_method)
|
||||||
cvar_ns->assign(swig_globals[j].name,&swig_globals[j]);
|
cvar_ns->assign(swig_globals[j].name,&swig_globals[j]);
|
||||||
|
|
||||||
module_ns=new octave_swig_type(0, 0, 0, true);
|
octave_swig_type* module_ns=new octave_swig_type(0, 0, 0, true);
|
||||||
module_ns->assign(global_name,Swig::swig_value_ref(cvar_ns));
|
module_ns->assign(global_name,Swig::swig_value_ref(cvar_ns));
|
||||||
for (int j=0;swig_globals[j].name;++j)
|
for (int j=0;swig_globals[j].name;++j)
|
||||||
if (swig_globals[j].method)
|
if (swig_globals[j].method)
|
||||||
|
|
@ -130,7 +134,7 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
|
||||||
mlock();
|
mlock();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // !already_init
|
} // !already_load
|
||||||
|
|
||||||
// link variable to module in current context
|
// link variable to module in current context
|
||||||
#if OCTAVE_API_VERSION_NUMBER<37
|
#if OCTAVE_API_VERSION_NUMBER<37
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue