Add support for the -external-runtime argument and update all language modules to use it
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6993 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
8d7eaea667
commit
67b49825cb
18 changed files with 233 additions and 46 deletions
|
|
@ -1,6 +1,14 @@
|
|||
Version 1.3.25 (In progress)
|
||||
============================
|
||||
|
||||
02/23/2005: wuzzeb (John Lenz)
|
||||
Added -external-runtime argument. This argument is used to dump
|
||||
out all the code needed for external access to the runtime system,
|
||||
and it replaces including the files directly. This change adds
|
||||
two new virtual functions to the Language class, which are used
|
||||
to find the language specific runtime code. I also updated
|
||||
all languages that use the runtime to implement these two functions.
|
||||
|
||||
02/22/2005: mmatus
|
||||
Fix %template + private error SF#1099976.
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ needs to implement to take advantage of the run time type system. I assume you
|
|||
have read the run-time section of the Typemaps chapter in the SWIG
|
||||
documentation.
|
||||
|
||||
Last updated: January 23, 2005
|
||||
Last updated: February 23, 2005
|
||||
|
||||
The file we are concerned with here should be named langrun.swg. A good example
|
||||
of a simple file is the Lib/mzscheme/mzrun.swg file. First, a few requirements
|
||||
|
|
@ -31,6 +31,13 @@ these function names
|
|||
6) You need to call void SWIG_InitializeModule(void *clientdata) from your init
|
||||
function.
|
||||
|
||||
7) You need to implement the runtimeCode() and defaultExternalRuntimeFilename()
|
||||
functions inside module.cxx. runtimeCode should return all the language
|
||||
specific runtime code as a string, and defaultExternalRuntimeFilename should
|
||||
return a string for the default name of the external runtime header. This is
|
||||
usually "swigpyrun.h", where "py" is replaced by the language name. These
|
||||
two functions are used by the -external-runtime argument.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Required Functions
|
||||
-------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -75,44 +75,28 @@ languages provide. One solution is to load all modules before spawning any thre
|
|||
the functions <tt>SWIG_TypeQuery</tt>, <tt>SWIG_NewPointerObj</tt>, and others sometimes need
|
||||
to be called. Calling these functions from a typemap is supported, since the typemap code
|
||||
is embedded into the <tt>_wrap.c</tt> file, which has those declerations available. If you need
|
||||
to call the SWIG run-time functions from another C file, there are three headers you need
|
||||
to include. They are located in the Lib directory in the SWIG source, or wherever the
|
||||
SWIG Library was installed. You can see the current library path by running
|
||||
<tt>swig -swiglib</tt>.</p>
|
||||
to call the SWIG run-time functions from another C file, there is one header you need
|
||||
to include. To generate the header that needs to be included, run the following command:
|
||||
|
||||
<blockquote><pre>
|
||||
#include <swigrun.swg>
|
||||
#include <python/pyrun.swg> /* Or other header, see below */
|
||||
#include <runtime.swg>
|
||||
$ swig -python -external-runtime <filename>
|
||||
</pre></blockquote>
|
||||
|
||||
<p>After including these three headers, your code should be able to call <tt>SWIG_TypeQuery</tt>,
|
||||
<p>The filename argument is optional and if it is not passed, then the default filename will
|
||||
be something like <tt>swigpyrun.h</tt>, depending on the language. This header file should
|
||||
be treated like any of the other _wrap.c output files, and should be regenerated when the
|
||||
_wrap files are. After including this header, your code will be able to call <tt>SWIG_TypeQuery</tt>,
|
||||
<tt>SWIG_NewPointerObj</tt>, <tt>SWIG_ConvertPtr</tt> and others. The exact argument paramaters
|
||||
for these functions might differ between language modules; please check the language module chapters
|
||||
for more information.</p>
|
||||
|
||||
<p>Inside these headers the functions are declared static and are included inline into the file,
|
||||
<p>Inside this header the functions are declared static and are included inline into the file,
|
||||
and thus the file does not need to be linked against any SWIG libraries or code (you might still
|
||||
need to link against the language libraries like libpython-2.3). Data is shared between this
|
||||
file and the _wrap.c files through a global variable in the wrapping language. It is also
|
||||
possible to copy these three header files into your own package for distribution along with
|
||||
the generated wrapper files, so that you can distribute a package that can be compiled
|
||||
without SWIG installed (this works because the header files are self contained, and do not
|
||||
need to link with anything).</p>
|
||||
|
||||
<p>The headers that should be included in place of the #include <python/pyrun.swg>
|
||||
for the different language modules are:</p>
|
||||
<ul>
|
||||
<li>Chicken - <chicken/chickenrun.swg></li>
|
||||
<li>Guile (scm) - <guile/guile_scm_run.swg></li>
|
||||
<li>Guile (gh) - This does not work with the -gh API, use the -scm API</li>
|
||||
<li>MzScheme - <mzscheme/mzrun.swg></li>
|
||||
<li>Ocaml - <ocaml/ocaml.swg></li>
|
||||
<li>Python - <python/pyrun.swg></li>
|
||||
<li>Perl5 - <perl5/perlrun.swg></li>
|
||||
<li>Ruby - <ruby/rubydef.swg></li>
|
||||
<li>Tcl - <tcl/swigtcl8.swg></li>
|
||||
</ul>
|
||||
file and the _wrap.c files through a global variable in the scripting language. It is also
|
||||
possible to copy this header file along with the generated wrapper files into your own package,
|
||||
so that you can distribute a package that can be compiled without SWIG installed (this works
|
||||
because the header file is self contained, and does not need to link with anything).</p>
|
||||
|
||||
<H2><a name="Modules_nn4"></a>15.3 A word of caution about static libraries</H2>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,9 @@
|
|||
/* -----------------------------------------------------------------------------*
|
||||
Standard SWIG API for use inside user code.
|
||||
|
||||
You need to include in your code as follow:
|
||||
|
||||
#include <Python.h> // or using your favorite language
|
||||
#include <swigrun.swg>
|
||||
#include <python/pyrun.swg> // or using your favorite language
|
||||
#include <runtime.swg>
|
||||
|
||||
For perl, the following
|
||||
#include <swigrun.swg>
|
||||
#include <perl5/perlrun.swg>
|
||||
#include <runtime.swg>
|
||||
Don't include this file directly, run the command
|
||||
swig -python -external-runtime
|
||||
Also, read the Modules chapter of the SWIG Manual.
|
||||
|
||||
* -----------------------------------------------------------------------------*/
|
||||
|
||||
|
|
|
|||
|
|
@ -93,6 +93,9 @@ protected:
|
|||
|
||||
String *chickenNameMapping(String *, String_or_char *);
|
||||
String *chickenPrimitiveName(String *);
|
||||
|
||||
String *runtimeCode();
|
||||
String *defaultExternalRuntimeFilename();
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
|
|
@ -1329,3 +1332,15 @@ CHICKEN::validIdentifier(String *s)
|
|||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
String *CHICKEN::runtimeCode() {
|
||||
String *s = Swig_include_sys("chickenrun.swg");
|
||||
if (!s) {
|
||||
Printf(stderr, "*** Unable to open 'chickenrun.swg'\n");
|
||||
s = NewString("");
|
||||
}
|
||||
}
|
||||
|
||||
String *CHICKEN::defaultExternalRuntimeFilename() {
|
||||
return NewString("swigchickenrun.h");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1772,6 +1772,32 @@ public:
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
String *runtimeCode() {
|
||||
String *s;
|
||||
if (use_scm_interface) {
|
||||
s = Swig_include_sys("guile_scm_run.swg");
|
||||
if (!s) {
|
||||
Printf(stderr, "*** Unable to open 'guile_scm_run.swg");
|
||||
s = NewString("");
|
||||
}
|
||||
} else {
|
||||
s = Swig_include_sys("guile_gh_run.swg");
|
||||
if (!s) {
|
||||
Printf(stderr, "*** Unable to open 'guile_gh_run.swg");
|
||||
s = NewString("");
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
String *defaultExternalRuntimeFilename() {
|
||||
if (use_scm_interface) {
|
||||
return NewString("swigguilerun.h");
|
||||
} else {
|
||||
return NewString("swigguileghrun.h");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -2915,3 +2915,11 @@ int Language::is_assignable(Node *n)
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
String *Language::runtimeCode() {
|
||||
return NewString("");
|
||||
}
|
||||
|
||||
String *Language::defaultExternalRuntimeFilename() {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,6 +128,8 @@ static DOH *libfiles = 0;
|
|||
static DOH *cpps = 0 ;
|
||||
static String *dependencies_file = 0;
|
||||
static File *f_dependencies_file = 0;
|
||||
static int external_runtime = 0;
|
||||
static String *external_runtime_name = 0;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// check_suffix(char *name)
|
||||
|
|
@ -269,6 +271,56 @@ void SWIG_getfeatures(const char *c)
|
|||
Delete(name);
|
||||
}
|
||||
|
||||
/* This function handles the -external-runtime command option */
|
||||
static void SWIG_dump_runtime() {
|
||||
String *outfile;
|
||||
File *runtime;
|
||||
String *s;
|
||||
|
||||
outfile = external_runtime_name;
|
||||
if (!outfile) {
|
||||
outfile = lang->defaultExternalRuntimeFilename();
|
||||
if (!outfile) {
|
||||
Printf(stderr, "*** Please provide a filename for the external runtime\n");
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
runtime = NewFile(outfile, "w");
|
||||
if (!runtime) {
|
||||
Printf(stderr, "*** Unable to open '%s'\n", outfile);
|
||||
Close(runtime);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
Swig_banner(runtime);
|
||||
|
||||
s = Swig_include_sys("swigrun.swg");
|
||||
if (!s) {
|
||||
Printf(stderr, "*** Unable to open 'swigrun.swg'\n");
|
||||
Close(runtime);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
Printf(runtime, "%s", s);
|
||||
Delete(s);
|
||||
|
||||
s = lang->runtimeCode();
|
||||
Printf(runtime, "%s", s);
|
||||
Delete(s);
|
||||
|
||||
s = Swig_include_sys("runtime.swg");
|
||||
if (!s) {
|
||||
Printf(stderr, "*** Unable to open 'runtime.swg'\n");
|
||||
Close(runtime);
|
||||
SWIG_exit(EXIT_FAILURE);
|
||||
}
|
||||
Printf(runtime, "%s", s);
|
||||
Delete(s);
|
||||
|
||||
Close(runtime);
|
||||
SWIG_exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void SWIG_getoptions(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
|
@ -341,6 +393,14 @@ void SWIG_getoptions(int argc, char *argv[])
|
|||
Swig_mark_arg(i);
|
||||
Swig_warning(WARN_DEPRECATED_OPTC, "SWIG",1, "-c, -runtime, -noruntime command line options are deprecated.\n");
|
||||
SwigRuntime = 2;
|
||||
} else if (strcmp(argv[i], "-external-runtime") == 0) {
|
||||
external_runtime = 1;
|
||||
Swig_mark_arg(i);
|
||||
if (argv[i+1]) {
|
||||
external_runtime_name = NewString(argv[i+1]);
|
||||
Swig_mark_arg(i+1);
|
||||
i++;
|
||||
}
|
||||
} else if ((strcmp(argv[i],"-make_default") == 0) || (strcmp(argv[i],"-makedefault") == 0)) {
|
||||
GenerateDefault = 1;
|
||||
Swig_mark_arg(i);
|
||||
|
|
@ -645,7 +705,8 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
|||
}
|
||||
|
||||
// Check all of the options to make sure we're cool.
|
||||
Swig_check_options();
|
||||
// Don't check for an input file if -external-runtime is passed
|
||||
Swig_check_options(external_runtime ? 0 : 1);
|
||||
|
||||
install_opts(argc, argv);
|
||||
|
||||
|
|
@ -674,6 +735,10 @@ int SWIG_main(int argc, char *argv[], Language *l) {
|
|||
}
|
||||
}
|
||||
|
||||
// handle the -external-runtime argument
|
||||
if (external_runtime)
|
||||
SWIG_dump_runtime();
|
||||
|
||||
// If we made it this far, looks good. go for it....
|
||||
|
||||
input_file = argv[argc-1];
|
||||
|
|
|
|||
|
|
@ -798,6 +798,19 @@ public:
|
|||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
String *runtimeCode() {
|
||||
String *s = Swig_include_sys("mzrun.swg");
|
||||
if (!s) {
|
||||
Printf(stderr, "*** Unable to open 'mzrun.swg'\n");
|
||||
s = NewString("");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
String *defaultExternalRuntimeFilename() {
|
||||
return NewString("swigmzrun.h");
|
||||
}
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1931,6 +1931,19 @@ public:
|
|||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
String *runtimeCode() {
|
||||
String *s = Swig_include_sys("ocaml.swg");
|
||||
if (!s) {
|
||||
Printf(stderr, "*** Unable to open 'ocaml.swg'\n");
|
||||
s = NewString("");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
String *defaultExternalRuntimeFilename() {
|
||||
return NewString("swigocamlrun.h");
|
||||
}
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -1527,6 +1527,19 @@ public:
|
|||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
String *runtimeCode() {
|
||||
String *s = Swig_include_sys("perlrun.swg");
|
||||
if (!s) {
|
||||
Printf(stderr, "*** Unable to open 'perlrun.swg'\n");
|
||||
s = NewString("");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
String *defaultExternalRuntimeFilename() {
|
||||
return NewString("swigperlrun.h");
|
||||
}
|
||||
};
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -2470,6 +2470,20 @@ public:
|
|||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
virtual String *runtimeCode() {
|
||||
String *s = Swig_include_sys("pyrun.swg");
|
||||
if (!s) {
|
||||
Printf(stderr, "*** Unable to open 'pyrun.swg'\n");
|
||||
s = NewString("");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
virtual String *defaultExternalRuntimeFilename() {
|
||||
return NewString("swigpyrun.h");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/* ---------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -2470,6 +2470,19 @@ public:
|
|||
p = nextSibling(p);
|
||||
}
|
||||
}
|
||||
|
||||
String *runtimeCode() {
|
||||
String *s = Swig_include_sys("rubydef.swg");
|
||||
if (!s) {
|
||||
Printf(stderr, "*** Unable to open 'rubydef.swg'\n");
|
||||
s = NewString("");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
String *defaultExternalRuntimeFilename() {
|
||||
return NewString("swigrubyrun.h");
|
||||
}
|
||||
}; /* class RUBY */
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -224,6 +224,8 @@ public:
|
|||
virtual Node *enumLookup(SwigType *s); /* Enum lookup */
|
||||
virtual int abstractClassTest(Node *n); /* Is class really abstract? */
|
||||
virtual int is_assignable(Node *n); /* Is variable assignable? */
|
||||
virtual String *runtimeCode(); /* returns the language specific runtime code */
|
||||
virtual String *defaultExternalRuntimeFilename(); /* the default filename for the external runtime */
|
||||
|
||||
/* Allow director related code generation */
|
||||
void allow_directors(int val = 1);
|
||||
|
|
|
|||
|
|
@ -1219,6 +1219,19 @@ public:
|
|||
}
|
||||
return Char(temp);
|
||||
}
|
||||
|
||||
String *runtimeCode() {
|
||||
String *s = Swig_include_sys("swigtcl8.swg");
|
||||
if (!s) {
|
||||
Printf(stderr, "*** Unable to open 'swigtcl8.swg'\n");
|
||||
s = NewString("");
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
String *defaultExternalRuntimeFilename() {
|
||||
return NewString("swigtclrun.h");
|
||||
}
|
||||
};
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -79,11 +79,12 @@ Swig_check_marked(int n) {
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
Swig_check_options() {
|
||||
Swig_check_options(int check_input) {
|
||||
int error = 0;
|
||||
int i;
|
||||
int max = check_input ? numargs - 1 : numargs;
|
||||
assert(marked);
|
||||
for (i = 1; i < numargs-1; i++) {
|
||||
for (i = 1; i < max; i++) {
|
||||
if (!marked[i]) {
|
||||
Printf(stderr,"swig error : Unrecognized option %s\n", args[i]);
|
||||
error=1;
|
||||
|
|
@ -93,7 +94,7 @@ Swig_check_options() {
|
|||
Printf(stderr,"Use 'swig -help' for available options.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (marked[numargs-1]) {
|
||||
if (check_input && marked[numargs-1]) {
|
||||
Printf(stderr,"Must specify an input file. Use -help for available options.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ extern char *Swig_file_dirname(const String_or_char *filename);
|
|||
extern void Swig_init_args(int argc, char **argv);
|
||||
extern void Swig_mark_arg(int n);
|
||||
extern int Swig_check_marked(int n);
|
||||
extern void Swig_check_options();
|
||||
extern void Swig_check_options(int check_input);
|
||||
extern void Swig_arg_error();
|
||||
|
||||
/* --- Scanner Interface --- */
|
||||
|
|
|
|||
|
|
@ -723,7 +723,7 @@ extern DOH *Swig_include(DOH *name);
|
|||
|
||||
extern void Swig_init_args(int argc, char **argv);
|
||||
extern void Swig_mark_arg(int n);
|
||||
extern void Swig_check_options();
|
||||
extern void Swig_check_options(int check_input);
|
||||
extern void Swig_arg_error();
|
||||
|
||||
%section "Miscelaneous", after
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue