New Octave module loading behaviour

- Use call syntax instead of cmdline to choose global/noglobal load:
  global: 'example;', noglobal: 'example = example;'
- All functions loaded with Octave 'autoload' command; correctly
  loads .oct module and prevents segfault in Octave 3.0.5
- Functions no longer installed as global variables as well,
  so global operator dispatch now only looks for functions
- Octave at-exit function created from string, not function,
  so no dependence on loaded .oct files at cleanup time
- C at-exit function now immediately exits Octave (with correct
  status) to prevent seg-fault due to dodgy memory cleanup
  in some Octave versions
- Documentation string for module loading function

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13088 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Karl Wette 2012-05-14 09:24:15 +00:00
commit bc2a78fbab
3 changed files with 146 additions and 174 deletions

View file

@ -15,16 +15,13 @@ char cvsroot_octave_cxx[] = "$Id$";
#include "swigmod.h"
static bool global_load = true;
static String *global_name = 0;
static String *op_prefix = 0;
static const char *usage = (char *) "\
Octave Options (available with -octave)\n\
-global - Load all symbols into the global namespace [default]\n\
-globals <name> - Set <name> used to access C global variables [default: 'cvar']\n\
- Use '.' to load C global variables into module namespace\n\
-noglobal - Do not load all symbols into the global namespace\n\
Use '.' to load C global variables into module namespace\n\
-opprefix <str> - Prefix <str> for global operator functions [default: 'op_']\n\
\n";
@ -83,12 +80,13 @@ public:
if (argv[i]) {
if (strcmp(argv[i], "-help") == 0) {
fputs(usage, stdout);
} else if (strcmp(argv[i], "-global") == 0) {
global_load = true;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-noglobal") == 0) {
global_load = false;
Swig_mark_arg(i);
} else if (strcmp(argv[i], "-global") == 0 ||
strcmp(argv[i], "-noglobal") == 0) {
Printv(stderr,
"*** -global/-noglobal are no longer supported\n"
"*** global load behaviour is now determined at module load\n"
"*** see the Perl section in the manual for details.\n", NIL);
SWIG_exit(EXIT_FAILURE);
} else if (strcmp(argv[i], "-globals") == 0) {
if (argv[i + 1]) {
global_name = NewString(argv[i + 1]);
@ -179,10 +177,8 @@ public:
Printf(f_runtime, "#define SWIG_name %s\n", module);
Printf(f_runtime, "\n");
Printf(f_runtime, "#define SWIG_global_load %s\n", global_load ? "true" : "false");
Printf(f_runtime, "#define SWIG_global_name \"%s\"\n", global_name);
Printf(f_runtime, "#define SWIG_op_prefix \"%s\"\n", op_prefix);
Printf(f_runtime, "#define SWIG_atexit_func swig_atexit_%s\n", module);
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");
@ -383,7 +379,7 @@ public:
virtual int importDirective(Node *n) {
String *modname = Getattr(n, "module");
if (modname)
Printf(f_init, "feval(\"%s\",octave_value_list(),0);\n", modname);
Printf(f_init, "feval(\"%s\",octave_value_list(),1);\n", modname);
return Language::importDirective(n);
}