Allow global operators to be SWIG-wrapped functions (by Karl Wette)

The Octave run-time allows global operators to be implemented,
e.g. op_scalar_add_X for adding a scalar and a wrapped struct X.
However it doesn't currently seem possible for these operators to
map to SWIG-wrapped functions. This is because dispatch_global_op()
looks for the operators to be installed as global variables, whereas
install_global() installs SWIG-wrapped functions as builtin functions;
the two appear to be separate symbol tables in Octave.

This patch modifies install_global() to install global operator functions
as both builtin functions and as global variables, where the value of the
global variable is a function handle to the operator function. It decides
if a function is a global operator if it begins with the prefix "op_"; this
prefix can be modified through a new command-line variable. It also always
installs the operators globally, regardless of whether the rest of the module
is being loaded globally. To accomplish this, install_global() is now always
called, but takes a bool argument specifying whether it should load symbols
globally. If a function is not a global operator, install_global() should
behave as before.

Tested that this compiles and works on Octave 3.2.4 and 3.4.0.



git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12675 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Xavier Delacour 2011-05-17 02:02:15 +00:00
commit 06221dacae
3 changed files with 30 additions and 13 deletions

View file

@ -17,12 +17,14 @@ char cvsroot_octave_cxx[] = "$Id$";
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\
-noglobal - Do not load all symbols into the global namespace\n\
-opprefix <str> - Prefix <str> for global operator functions [default: 'op_']\n\
\n";
@ -85,12 +87,23 @@ public:
} else {
Swig_arg_error();
}
} else if (strcmp(argv[i], "-opprefix") == 0) {
if (argv[i + 1]) {
op_prefix = 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");
if (!op_prefix)
op_prefix = NewString("op_");
SWIG_library_directory("octave");
Preprocessor_define("SWIGOCTAVE 1", 0);
@ -157,6 +170,7 @@ public:
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);
if (directorsEnabled()) {
Printf(f_runtime, "#define SWIG_DIRECTORS\n");