Octave changes by Karl Wette:

It's currently not possible to tell SWIG whether or not symbols should be
loaded into the global namespace by default. In fact, it's not even possible
to make the generated .oct module *not* load all symbols globally, due to a
bug in Lib/octave/octruntime.swg (line 37: "noglobal" should be "global").
It's also not possible to change the name of the symbol used to access
global variables/constants from the default "cvar".

This patch adds 3 Octave-specific command-line options:

* -global/-noglobal tell SWIG whether the generated .oct module should load
symbols into the global namespace by default. The default option is -global
to preserve existing behaviour.

* -globals <name> sets the name of the symbol used to access global
variables/constants. It is set to "cvar" by default.

These options are parsed in Source/Modules/octave.cxx, and written to the
wrapping code as the macros SWIG_global_load and SWIG_global_name.

In Lib/octave/octruntime.swg, the Octave entry point DEFUN_DLD function now
contains a expanded input argument parser, which uses the same command-line
arguments (-global/-noglobal, -globals) as can be passed to SWIG itself;
this allows the module user to change the default loading behaviour of the
module user at load time. The parser checks for non-string and unrecognised
arguments, and also checks that the argument to -globals is a valid Octave
identifier. A -help option prints a short usage message.




git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12670 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Xavier Delacour 2011-05-17 01:56:43 +00:00
commit 8848b16e01
2 changed files with 72 additions and 12 deletions

View file

@ -15,9 +15,14 @@ char cvsroot_octave_cxx[] = "$Id$";
#include "swigmod.h"
static bool global_load = true;
static String *global_name = 0;
static const char *usage = (char *) "\
Octave Options (available with -octave)\n\
[no additional options]\n\
-global - Load all symbols into the global namespace [default]\n\
-globals <name> - Set <name> used to access C global variables [default: 'cvar']\n\
-noglobal - Do not load all symbols into the global namespace\n\
\n";
@ -64,11 +69,29 @@ public:
for (int i = 1; i < argc; i++) {
if (argv[i]) {
if (strcmp(argv[i], "-help") == 0) {
fputs(usage, stdout);
}
fputs(usage, stderr);
} 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], "-globals") == 0) {
if (argv[i + 1]) {
global_name = NewString(argv[i + 1]);
Swig_mark_arg(i);
Swig_mark_arg(i + 1);
i++;
} else {
Swig_arg_error();
}
}
}
}
if (!global_name)
global_name = NewString("cvar");
SWIG_library_directory("octave");
Preprocessor_define("SWIGOCTAVE 1", 0);
SWIG_config_file("octave.swg");
@ -131,6 +154,10 @@ public:
Printf(f_runtime, "#define SWIG_name_d \"%s\"\n", module);
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);
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");
Swig_banner(f_directors_h);