Changes Octave module loading behavior, so that modules can be safely loaded inside functions without first being loaded at the base level. (Basically the module is now always loaded in the base context, and then a local link to the module is created in the current context.) Added an example, module_load, to Examples/octave to test this behaviour in different ways. Tested examples work for octave 3.0.5, 3.2.4, and 3.4.0. (thanks to Karl Wette)
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12793 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
b61ccd00ec
commit
3372c2ba62
12 changed files with 251 additions and 79 deletions
|
|
@ -9,6 +9,7 @@ funcptr
|
|||
funcptr2
|
||||
functor
|
||||
operator
|
||||
module_load
|
||||
pointer
|
||||
reference
|
||||
simple
|
||||
|
|
|
|||
26
Examples/octave/module_load/Makefile
Normal file
26
Examples/octave/module_load/Makefile
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../preinst-swig
|
||||
SRCS = example.c
|
||||
TARGET = example
|
||||
INTERFACE = example.i
|
||||
OCTSCRIPTS = \
|
||||
runme_args.m \
|
||||
runme_gl_func.m \
|
||||
runme_gl_func_base.m \
|
||||
runme_nogl_func.m \
|
||||
runme_nogl_func_base.m
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' octave
|
||||
|
||||
static::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
TARGET='myoctave' INTERFACE='$(INTERFACE)' octave_static
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile octave_clean
|
||||
rm -f $(TARGET).m
|
||||
|
||||
check: all
|
||||
$(MAKE) -f $(TOP)/Makefile OCTSCRIPT="$(OCTSCRIPTS)" octave_run
|
||||
9
Examples/octave/module_load/example.c
Normal file
9
Examples/octave/module_load/example.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* File : example.c */
|
||||
|
||||
#include "example.h"
|
||||
|
||||
int ivar = 47;
|
||||
|
||||
int ifunc() {
|
||||
return ivar;
|
||||
}
|
||||
5
Examples/octave/module_load/example.h
Normal file
5
Examples/octave/module_load/example.h
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/* File: example.h */
|
||||
|
||||
extern int ivar;
|
||||
|
||||
int ifunc();
|
||||
9
Examples/octave/module_load/example.i
Normal file
9
Examples/octave/module_load/example.i
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* File : example.i */
|
||||
%module example
|
||||
%{
|
||||
#include "example.h"
|
||||
%}
|
||||
|
||||
extern "C" int ivar;
|
||||
|
||||
int ifunc();
|
||||
12
Examples/octave/module_load/runme_args.m
Normal file
12
Examples/octave/module_load/runme_args.m
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# file: runme_args.m
|
||||
|
||||
# test module loading with arguments
|
||||
|
||||
# test help
|
||||
example -help
|
||||
assert(!isglobal("example"))
|
||||
|
||||
# load module with custom cvar
|
||||
example -globals mycvar
|
||||
assert(!isglobal("cvar"))
|
||||
assert(mycvar.ivar == example.ifunc())
|
||||
21
Examples/octave/module_load/runme_gl_func.m
Normal file
21
Examples/octave/module_load/runme_gl_func.m
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# file: runme_gl_func.m
|
||||
|
||||
# test whether module can be loaded
|
||||
# in a function (global cvar)
|
||||
|
||||
# test that everything works from the base context
|
||||
example
|
||||
global cvar
|
||||
assert(cvar.ivar == example.ifunc())
|
||||
|
||||
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
|
||||
23
Examples/octave/module_load/runme_gl_func_base.m
Normal file
23
Examples/octave/module_load/runme_gl_func_base.m
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# file: runme_gl_func_base.m
|
||||
|
||||
# test whether module can be loaded in a function
|
||||
# before the base context (global cvar)
|
||||
|
||||
1;
|
||||
|
||||
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())
|
||||
19
Examples/octave/module_load/runme_nogl_func.m
Normal file
19
Examples/octave/module_load/runme_nogl_func.m
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
# file: runme_nogl_func.m
|
||||
|
||||
# test whether module can be loaded
|
||||
# in a function (no global cvar)
|
||||
|
||||
# test that everything works from the base context
|
||||
example -noglobal
|
||||
assert(example.cvar.ivar == example.ifunc())
|
||||
|
||||
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
|
||||
21
Examples/octave/module_load/runme_nogl_func_base.m
Normal file
21
Examples/octave/module_load/runme_nogl_func_base.m
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# file: runme_nogl_func_base.m
|
||||
|
||||
# test whether module can be loaded in a function
|
||||
# before the base context (no global cvar)
|
||||
|
||||
1;
|
||||
|
||||
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())
|
||||
Loading…
Add table
Add a link
Reference in a new issue