add -nortti option in python, to avoid using RTTI, mainly with directors
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6999 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
192e00615d
commit
02a61719bd
3 changed files with 41 additions and 9 deletions
|
|
@ -13,15 +13,33 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
extern "C" {
|
/*
|
||||||
struct swig_type_info;
|
Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the
|
||||||
}
|
'Swig' namespace. This could be usefull for multi-modules projects.
|
||||||
|
*/
|
||||||
#ifdef SWIG_DIRECTOR_STATIC
|
#ifdef SWIG_DIRECTOR_STATIC
|
||||||
/* Force anonymous (static) namespace */
|
/* Force anonymous (static) namespace */
|
||||||
#define Swig
|
#define Swig
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Use -DSWIG_DIRECTOR_NORTTI if you prefer to avoid the use of RTTI
|
||||||
|
and dynamic_cast<>. But be aware that directors could stop working
|
||||||
|
when using this option.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(SWIG_DIRECTOR_NORTTI)
|
||||||
|
# define SWIG_DIRECTOR_CAST(arg) (Swig::Director*)(arg)
|
||||||
|
#else
|
||||||
|
# define SWIG_DIRECTOR_CAST(arg) dynamic_cast<Swig::Director*>(arg)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
struct swig_type_info;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Swig {
|
namespace Swig {
|
||||||
/* base class for director exceptions */
|
/* base class for director exceptions */
|
||||||
class DirectorException {
|
class DirectorException {
|
||||||
|
|
|
||||||
|
|
@ -122,3 +122,12 @@ These methods "may be called" if needed.
|
||||||
#endif
|
#endif
|
||||||
#define %nocallback %nopythoncallback; %feature("callback","")
|
#define %nocallback %nopythoncallback; %feature("callback","")
|
||||||
|
|
||||||
|
|
||||||
|
/* When using -nortti, tell directors to avoid RTTI */
|
||||||
|
#ifdef SWIG_NORTTI
|
||||||
|
%insert("runtime") %{
|
||||||
|
#ifndef SWIG_DIRECTOR_NORTTI
|
||||||
|
#define SWIG_DIRECTOR_NORTTI
|
||||||
|
#endif
|
||||||
|
%}
|
||||||
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,8 @@ Python Options (available with -python)\n\
|
||||||
-interface <lib>- Set the lib name to <lib>\n\
|
-interface <lib>- Set the lib name to <lib>\n\
|
||||||
-keyword - Use keyword arguments\n\
|
-keyword - Use keyword arguments\n\
|
||||||
-classic - Use classic classes only\n\
|
-classic - Use classic classes only\n\
|
||||||
-cpluscast - Enable new C++ casting operators, useful for debugging\n\
|
-cppcast - Enable new C++ casting operators, useful for debugging\n\
|
||||||
|
-nortti - Disable the use of RTTI, useful (sometimes) with directors\n\
|
||||||
-modern - Use modern python features only, without compatibility code\n\
|
-modern - Use modern python features only, without compatibility code\n\
|
||||||
-apply - Use apply() in proxy classes\n\
|
-apply - Use apply() in proxy classes\n\
|
||||||
-new_vwm - New value wrapper mode, use only when everything else fails \n\
|
-new_vwm - New value wrapper mode, use only when everything else fails \n\
|
||||||
|
|
@ -155,10 +156,14 @@ public:
|
||||||
classic = 1;
|
classic = 1;
|
||||||
apply = 1;
|
apply = 1;
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i],"-cpluscast") == 0) {
|
} else if (strcmp(argv[i],"-cppcast") == 0) {
|
||||||
/* Turn on new value wrapper mpde */
|
/* Turn on new value wrapper mpde */
|
||||||
Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0);
|
Preprocessor_define((DOH *) "SWIG_CPLUSPLUS_CAST", 0);
|
||||||
Swig_mark_arg(i);
|
Swig_mark_arg(i);
|
||||||
|
} else if (strcmp(argv[i],"-nortti") == 0) {
|
||||||
|
/* Turn on no RTTI mode */
|
||||||
|
Preprocessor_define((DOH *) "SWIG_NORTTI", 0);
|
||||||
|
Swig_mark_arg(i);
|
||||||
} else if (strcmp(argv[i],"-modern") == 0) {
|
} else if (strcmp(argv[i],"-modern") == 0) {
|
||||||
apply = 0;
|
apply = 0;
|
||||||
classic = 0;
|
classic = 0;
|
||||||
|
|
@ -1375,7 +1380,7 @@ public:
|
||||||
if (/*directorbase &&*/ !constructor && !destructor
|
if (/*directorbase &&*/ !constructor && !destructor
|
||||||
&& isVirtual && !Getattr(n,"feature:nodirector")) {
|
&& isVirtual && !Getattr(n,"feature:nodirector")) {
|
||||||
Wrapper_add_local(f, "director", "Swig::Director *director = 0");
|
Wrapper_add_local(f, "director", "Swig::Director *director = 0");
|
||||||
Printf(f->code, "director = dynamic_cast<Swig::Director *>(arg1);\n");
|
Printf(f->code, "director = SWIG_DIRECTOR_CAST(arg1);\n");
|
||||||
if (dirprot_mode() && !is_public(n)) {
|
if (dirprot_mode() && !is_public(n)) {
|
||||||
Printf(f->code, "if (!director || !(director->swig_get_inner(\"%s\"))) {\n", name);
|
Printf(f->code, "if (!director || !(director->swig_get_inner(\"%s\"))) {\n", name);
|
||||||
Printf(f->code, "PyErr_SetString(PyExc_RuntimeError,\"accessing protected member %s\");\n", name);
|
Printf(f->code, "PyErr_SetString(PyExc_RuntimeError,\"accessing protected member %s\");\n", name);
|
||||||
|
|
@ -1434,7 +1439,7 @@ public:
|
||||||
}
|
}
|
||||||
if (unwrap) {
|
if (unwrap) {
|
||||||
Wrapper_add_local(f, "resultdirector", "Swig::Director *resultdirector = 0");
|
Wrapper_add_local(f, "resultdirector", "Swig::Director *resultdirector = 0");
|
||||||
Printf(f->code, "resultdirector = dynamic_cast<Swig::Director *>(result);\n");
|
Printf(f->code, "resultdirector = SWIG_DIRECTOR_CAST(result);\n");
|
||||||
Printf(f->code, "if (resultdirector) {\n");
|
Printf(f->code, "if (resultdirector) {\n");
|
||||||
Printf(f->code, " resultobj = resultdirector->swig_get_self();\n");
|
Printf(f->code, " resultobj = resultdirector->swig_get_self();\n");
|
||||||
Printf(f->code, " Py_INCREF(resultobj);\n");
|
Printf(f->code, " Py_INCREF(resultobj);\n");
|
||||||
|
|
@ -2691,7 +2696,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
||||||
String *director = NewStringf("director_%s", mangle);
|
String *director = NewStringf("director_%s", mangle);
|
||||||
Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
|
Wrapper_add_localv(w, director, "Swig::Director *", director, "= 0", NIL);
|
||||||
Wrapper_add_localv(w, source, "PyObject *", source, "= 0", NIL);
|
Wrapper_add_localv(w, source, "PyObject *", source, "= 0", NIL);
|
||||||
Printf(wrap_args, "%s = dynamic_cast<Swig::Director *>(%s);\n", director, nonconst);
|
Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst);
|
||||||
Printf(wrap_args, "if (!%s) {\n", director);
|
Printf(wrap_args, "if (!%s) {\n", director);
|
||||||
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
|
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
|
||||||
Printf(wrap_args, "} else {\n");
|
Printf(wrap_args, "} else {\n");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue