Merge branch 'master' into doxygen
Merge with ~3.0.1 sources from master.
This commit is contained in:
commit
1ebd2334b8
1593 changed files with 51732 additions and 28076 deletions
|
|
@ -11,8 +11,6 @@
|
|||
* Python language module for SWIG.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
char cvsroot_python_cxx[] = "$Id$";
|
||||
|
||||
#include "swigmod.h"
|
||||
#include "cparse.h"
|
||||
|
||||
|
|
@ -46,6 +44,7 @@ static File *f_directors_h = 0;
|
|||
static File *f_init = 0;
|
||||
static File *f_shadow_py = 0;
|
||||
static String *f_shadow = 0;
|
||||
static String *f_shadow_begin = 0;
|
||||
static Hash *f_shadow_imports = 0;
|
||||
static String *f_shadow_builtin_imports = 0;
|
||||
static String *f_shadow_stubs = 0;
|
||||
|
|
@ -98,6 +97,7 @@ static int castmode = 0;
|
|||
static int extranative = 0;
|
||||
static int outputtuple = 0;
|
||||
static int nortti = 0;
|
||||
static int relativeimport = 0;
|
||||
|
||||
/* flags for the make_autodoc function */
|
||||
enum autodoc_t {
|
||||
|
|
@ -110,7 +110,7 @@ enum autodoc_t {
|
|||
};
|
||||
|
||||
|
||||
static const char *usage1 = (char *) "\
|
||||
static const char *usage1 = "\
|
||||
Python Options (available with -python)\n\
|
||||
-aliasobj0 - Alias obj0 when using fastunpack, needed for some old typemaps \n\
|
||||
-buildnone - Use Py_BuildValue(" ") to obtain Py_None (default in Windows)\n\
|
||||
|
|
@ -133,7 +133,7 @@ Python Options (available with -python)\n\
|
|||
-keyword - Use keyword arguments\n\
|
||||
-modern - Use modern python features only, without compatibility code\n\
|
||||
-modernargs - Use \"modern\" args mechanism to pack/unpack the function arguments\n";
|
||||
static const char *usage2 = (char *) "\
|
||||
static const char *usage2 = "\
|
||||
-newrepr - Use more informative version of __repr__ in proxy classes (default) \n\
|
||||
-newvwm - New value wrapper mode, use only when everything else fails \n\
|
||||
-noaliasobj0 - Don't generate an obj0 alias when using fastunpack (default) \n\
|
||||
|
|
@ -150,7 +150,7 @@ static const char *usage2 = (char *) "\
|
|||
-noh - Don't generate the output header file\n\
|
||||
-nomodern - Don't use modern python features which are not backwards compatible \n\
|
||||
-nomodernargs - Use classic ParseTuple/CallFunction methods to pack/unpack the function arguments (default) \n";
|
||||
static const char *usage3 = (char *) "\
|
||||
static const char *usage3 = "\
|
||||
-noolddefs - Don't emit the old method definitions even when using fastproxy (default) \n\
|
||||
-nooutputtuple - Use a PyList for appending output values (default) \n\
|
||||
-noproxy - Don't generate proxy classes \n\
|
||||
|
|
@ -163,6 +163,7 @@ static const char *usage3 = (char *) "\
|
|||
-oldrepr - Use shorter and old version of __repr__ in proxy classes\n\
|
||||
-outputtuple - Use a PyTuple for outputs instead of a PyList (use carefully with legacy interfaces) \n\
|
||||
-proxydel - Generate a __del__ method even though it is now redundant (default) \n\
|
||||
-relativeimport - Use relative python imports \n\
|
||||
-safecstrings - Use safer (but slower) C string mapping, generating copies from Python -> C/C++\n\
|
||||
-threads - Add thread support for all the interface\n\
|
||||
-O - Enable the following optimization options: \n\
|
||||
|
|
@ -540,6 +541,9 @@ public:
|
|||
builtin = 1;
|
||||
Preprocessor_define("SWIGPYTHON_BUILTIN", 0);
|
||||
Swig_mark_arg(i);
|
||||
} else if (strcmp(argv[i], "-relativeimport") == 0) {
|
||||
relativeimport = 1;
|
||||
Swig_mark_arg(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -785,8 +789,11 @@ public:
|
|||
Printf(f_directors, "/* ---------------------------------------------------\n");
|
||||
Printf(f_directors, " * C++ director class methods\n");
|
||||
Printf(f_directors, " * --------------------------------------------------- */\n\n");
|
||||
if (outfile_h)
|
||||
Printf(f_directors, "#include \"%s\"\n\n", Swig_file_filename(outfile_h));
|
||||
if (outfile_h) {
|
||||
String *filename = Swig_file_filename(outfile_h);
|
||||
Printf(f_directors, "#include \"%s\"\n\n", filename);
|
||||
Delete(filename);
|
||||
}
|
||||
}
|
||||
|
||||
/* If shadow classing is enabled, we're going to change the module name to "_module" */
|
||||
|
|
@ -805,6 +812,7 @@ public:
|
|||
filen = NULL;
|
||||
|
||||
f_shadow = NewString("");
|
||||
f_shadow_begin = NewString("");
|
||||
f_shadow_imports = NewHash();
|
||||
f_shadow_builtin_imports = NewString("");
|
||||
f_shadow_stubs = NewString("");
|
||||
|
|
@ -998,10 +1006,10 @@ public:
|
|||
if (!modern) {
|
||||
Printv(f_shadow, "# This file is compatible with both classic and new-style classes.\n", NIL);
|
||||
}
|
||||
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
|
||||
Printv(f_shadow_py, "\n", f_shadow_builtin_imports, "\n", NIL);
|
||||
Printv(f_shadow_py, f_shadow, "\n", NIL);
|
||||
Printv(f_shadow_py, f_shadow_stubs, "\n", NIL);
|
||||
Close(f_shadow_py);
|
||||
Delete(f_shadow_py);
|
||||
}
|
||||
|
||||
|
|
@ -1014,7 +1022,7 @@ public:
|
|||
Printf(f_runtime_h, "\n");
|
||||
Printf(f_runtime_h, "#endif\n");
|
||||
if (f_runtime_h != f_begin)
|
||||
Close(f_runtime_h);
|
||||
Delete(f_runtime_h);
|
||||
Dump(f_directors, f_begin);
|
||||
}
|
||||
|
||||
|
|
@ -1029,8 +1037,6 @@ public:
|
|||
Delete(f_init);
|
||||
Delete(f_directors);
|
||||
Delete(f_directors_h);
|
||||
|
||||
Close(f_begin);
|
||||
Delete(f_runtime);
|
||||
Delete(f_begin);
|
||||
|
||||
|
|
@ -1049,6 +1055,267 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* subpkg_tail()
|
||||
*
|
||||
* Return the name of 'other' package relative to 'base'.
|
||||
*
|
||||
* 1. If 'other' is a sub-package of 'base', returns the 'other' relative to
|
||||
* 'base'.
|
||||
* 2. If 'other' and 'base' are equal, returns empty string "".
|
||||
* 3. In any other case, NULL pointer is returned.
|
||||
*
|
||||
* The 'base' and 'other' are expected to be fully qualified names.
|
||||
*
|
||||
* NOTE: none of 'base' nor 'other' can be null.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* # base other tail
|
||||
* -- ---- ----- ----
|
||||
* 1 "Foo" "Foo.Bar" -> "Bar"
|
||||
* 2 "Foo" "Foo." -> ""
|
||||
* 3 "Foo" "FooB.ar" -> NULL
|
||||
* 4 "Foo.Bar" "Foo.Bar" -> ""
|
||||
* 5 "Foo.Bar" "Foo" -> NULL
|
||||
* 6 "Foo.Bar" "Foo.Gez" -> NULL
|
||||
*
|
||||
* NOTE: the example #2 is actually a syntax error (at input). I believe
|
||||
* swig parser prevents us from this case happening here.
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
static String *subpkg_tail(const String *base, const String *other) {
|
||||
int baselen = Len(base);
|
||||
int otherlen = Len(other);
|
||||
|
||||
if (Strncmp(other, base, baselen) == 0) {
|
||||
if ((baselen < otherlen) && (Char(other))[baselen] == '.') {
|
||||
return NewString((Char(other)) + baselen + 1);
|
||||
} else if (baselen == otherlen) {
|
||||
return NewString("");
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* abs_import_directive_string()
|
||||
*
|
||||
* Return a string containing python code to import module.
|
||||
*
|
||||
* pkg package name or the module being imported
|
||||
* mod module name of the module being imported
|
||||
* pfx optional prefix to module name
|
||||
*
|
||||
* NOTE: keep this function consistent with abs_import_name_string().
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
static String *abs_import_directive_string(const String *pkg, const String *mod, const char *pfx = "") {
|
||||
String *out = NewString("");
|
||||
|
||||
if (pkg && *Char(pkg)) {
|
||||
Printf(out, "import %s.%s%s\n", pkg, pfx, mod);
|
||||
} else {
|
||||
Printf(out, "import %s%s\n", pfx, mod);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* rel_import_directive_string()
|
||||
*
|
||||
* Return a string containing python code to import module that
|
||||
* is potentially within a package.
|
||||
*
|
||||
* mainpkg package name of the module which imports the other module
|
||||
* pkg package name or the module being imported
|
||||
* mod module name of the module being imported
|
||||
* pfx optional prefix to module name
|
||||
*
|
||||
* NOTE: keep this function consistent with rel_import_name_string().
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
static String *rel_import_directive_string(const String *mainpkg, const String *pkg, const String *mod, const char *pfx = "") {
|
||||
|
||||
/* NOTE: things are not so trivial. This is what we do here (by examples):
|
||||
*
|
||||
* 0. To import module 'foo', which is not in any package, we do absolute
|
||||
* import:
|
||||
*
|
||||
* import foo
|
||||
*
|
||||
* 1. To import 'pkg1.pkg2.foo', when mainpkg != "pkg1" and
|
||||
* mainpkg != "pkg1.pkg2" or when mainpkg is not given we do absolute
|
||||
* import:
|
||||
*
|
||||
* import pkg1.pkg2.foo
|
||||
*
|
||||
* 2. To import module pkg1.foo, when mainpkg == "pkg1", we do:
|
||||
*
|
||||
* - for py3 = 0:
|
||||
*
|
||||
* import foo
|
||||
*
|
||||
* - for py3 = 1:
|
||||
*
|
||||
* from . import foo
|
||||
*
|
||||
* 3. To import "pkg1.pkg2.pkg3.foo", when mainpkg = "pkg1", we do:
|
||||
*
|
||||
* - for py3 == 0:
|
||||
*
|
||||
* import pkg2.pkg3.foo
|
||||
*
|
||||
* - for py3 == 1:
|
||||
*
|
||||
* from . import pkg2 # [1]
|
||||
* import pkg1.pkg2.pkg3.foo
|
||||
*
|
||||
* NOTE: [1] is necessary for pkg2.foo to be present in the importing module
|
||||
*/
|
||||
|
||||
String *apkg = 0; // absolute (FQDN) package name of pkg
|
||||
String *rpkg = 0; // relative package name
|
||||
int py3_rlen1 = 0; // length of 1st level sub-package name, used by py3
|
||||
String *out = NewString("");
|
||||
|
||||
if (pkg && *Char(pkg)) {
|
||||
if (mainpkg) {
|
||||
String *tail = subpkg_tail(mainpkg, pkg);
|
||||
if (tail) {
|
||||
if (*Char(tail)) {
|
||||
rpkg = NewString(tail);
|
||||
const char *py3_end1 = Strchr(rpkg, '.');
|
||||
if (!py3_end1)
|
||||
py3_end1 = (Char(rpkg)) + Len(rpkg);
|
||||
py3_rlen1 = py3_end1 - (Char(rpkg));
|
||||
} else {
|
||||
rpkg = NewString("");
|
||||
}
|
||||
Delete(tail);
|
||||
} else {
|
||||
apkg = NewString(pkg);
|
||||
}
|
||||
} else {
|
||||
apkg = NewString(pkg);
|
||||
}
|
||||
} else {
|
||||
apkg = NewString("");
|
||||
}
|
||||
|
||||
if (apkg) {
|
||||
Printf(out, "import %s%s%s%s\n", apkg, *Char(apkg) ? "." : "", pfx, mod);
|
||||
Delete(apkg);
|
||||
} else {
|
||||
if (py3) {
|
||||
if (py3_rlen1)
|
||||
Printf(out, "from . import %.*s\n", py3_rlen1, rpkg);
|
||||
Printf(out, "from .%s import %s%s\n", rpkg, pfx, mod);
|
||||
} else {
|
||||
Printf(out, "import %s%s%s%s\n", rpkg, *Char(rpkg) ? "." : "", pfx, mod);
|
||||
}
|
||||
Delete(rpkg);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* import_directive_string()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
static String *import_directive_string(const String *mainpkg, const String *pkg, const String *mod, const char *pfx = "") {
|
||||
if (!relativeimport) {
|
||||
return abs_import_directive_string(pkg, mod, pfx);
|
||||
} else {
|
||||
return rel_import_directive_string(mainpkg, pkg, mod, pfx);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* abs_import_name_string()
|
||||
*
|
||||
* Return a string with the name of a symbol (perhaps imported
|
||||
* from external module by absolute import directive).
|
||||
*
|
||||
* mainpkg package name of current module
|
||||
* mainmod module name of current module
|
||||
* pkg package name of (perhaps other) module
|
||||
* mod module name of (perhaps other) module
|
||||
* sym symbol name
|
||||
*
|
||||
* NOTE: mainmod, mod, and sym can't be NULL.
|
||||
* NOTE: keep this function consistent with abs_import_directive_string()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
static String *abs_import_name_string(const String *mainpkg, const String *mainmod, const String *pkg, const String *mod, const String *sym) {
|
||||
String *out = NewString("");
|
||||
if (pkg && *Char(pkg)) {
|
||||
if (mainpkg && *Char(mainpkg)) {
|
||||
if (Strcmp(mainpkg,pkg) != 0 || Strcmp(mainmod, mod) != 0) {
|
||||
Printf(out, "%s.%s.", pkg, mod);
|
||||
}
|
||||
} else {
|
||||
Printf(out, "%s.%s.", pkg, mod);
|
||||
}
|
||||
} else if ((mainpkg && *Char(mainpkg)) || Strcmp(mainmod, mod) != 0) {
|
||||
Printf(out, "%s.", mod);
|
||||
}
|
||||
Append(out, sym);
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* rel_import_name_string()
|
||||
*
|
||||
* Return a string with the name of a symbol (perhaps imported
|
||||
* from external module by relative import directive).
|
||||
*
|
||||
* mainpkg package name of current module
|
||||
* mainmod module name of current module
|
||||
* pkg package name of (perhaps other) module
|
||||
* mod module name of (perhaps other) module
|
||||
* sym symbol name
|
||||
*
|
||||
* NOTE: mainmod, mod, and sym can't be NULL.
|
||||
* NOTE: keep this function consistent with rel_import_directive_string()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
static String *rel_import_name_string(const String *mainpkg, const String *mainmod, const String *pkg, const String *mod, const String *sym) {
|
||||
String *out = NewString("");
|
||||
if (pkg && *Char(pkg)) {
|
||||
String *tail = 0;
|
||||
if (mainpkg)
|
||||
tail = subpkg_tail(mainpkg, pkg);
|
||||
if (!tail)
|
||||
tail = NewString(pkg);
|
||||
if (*Char(tail)) {
|
||||
Printf(out, "%s.%s.", tail, mod);
|
||||
} else if (Strcmp(mainmod, mod) != 0) {
|
||||
Printf(out, "%s.", mod);
|
||||
}
|
||||
Delete(tail);
|
||||
} else if ((mainpkg && *Char(mainpkg)) || Strcmp(mainmod, mod) != 0) {
|
||||
Printf(out, "%s.", mod);
|
||||
}
|
||||
Append(out, sym);
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* import_name_string()
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
static String *import_name_string(const String *mainpkg, const String *mainmod, const String *pkg, const String *mod, const String *sym) {
|
||||
if (!relativeimport) {
|
||||
return abs_import_name_string(mainpkg,mainmod,pkg,mod,sym);
|
||||
} else {
|
||||
return rel_import_name_string(mainpkg,mainmod,pkg,mod,sym);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* importDirective()
|
||||
* ------------------------------------------------------------ */
|
||||
|
|
@ -1058,38 +1325,26 @@ public:
|
|||
String *modname = Getattr(n, "module");
|
||||
|
||||
if (modname) {
|
||||
String *import = NewString("import ");
|
||||
|
||||
// Find the module node for this imported module. It should be the
|
||||
// first child but search just in case.
|
||||
Node *mod = firstChild(n);
|
||||
while (mod && Strcmp(nodeType(mod), "module") != 0)
|
||||
mod = nextSibling(mod);
|
||||
|
||||
// Is the imported module in another package? (IOW, does it use the
|
||||
// %module(package="name") option and it's different than the package
|
||||
// of this module.)
|
||||
Node *options = Getattr(mod, "options");
|
||||
String *pkg = options ? Getattr(options, "package") : 0;
|
||||
if (pkg && (!package || Strcmp(pkg, package) != 0)) {
|
||||
Printf(import, "%s.", pkg);
|
||||
}
|
||||
// finally, output the name of the imported module
|
||||
if (shadowimport) {
|
||||
if (!options || (!Getattr(options, "noshadow") && !Getattr(options, "noproxy"))) {
|
||||
Printf(import, "_%s\n", modname);
|
||||
if (!GetFlagAttr(f_shadow_imports, import)) {
|
||||
if (pkg && (!package || Strcmp(pkg, package) != 0)) {
|
||||
Printf(builtin ? f_shadow_builtin_imports : f_shadow, "import %s.%s\n", pkg, modname);
|
||||
} else {
|
||||
Printf(builtin ? f_shadow_builtin_imports : f_shadow, "import %s\n", modname);
|
||||
}
|
||||
SetFlag(f_shadow_imports, import);
|
||||
String *_import = import_directive_string(package, pkg, modname, "_");
|
||||
if (!GetFlagAttr(f_shadow_imports, _import)) {
|
||||
String *import = import_directive_string(package, pkg, modname);
|
||||
Printf(builtin ? f_shadow_builtin_imports : f_shadow, "%s", import);
|
||||
Delete(import);
|
||||
SetFlag(f_shadow_imports, _import);
|
||||
}
|
||||
Delete(_import);
|
||||
}
|
||||
}
|
||||
|
||||
Delete(import);
|
||||
}
|
||||
}
|
||||
return Language::importDirective(n);
|
||||
|
|
@ -1129,7 +1384,7 @@ public:
|
|||
}
|
||||
|
||||
/* Split the input text into lines */
|
||||
List *clist = DohSplitLines(temp);
|
||||
List *clist = SplitLines(temp);
|
||||
Delete(temp);
|
||||
int initial = 0;
|
||||
String *s = 0;
|
||||
|
|
@ -1185,9 +1440,9 @@ public:
|
|||
|
||||
autodoc_l autodoc_level(String *autodoc) {
|
||||
autodoc_l dlevel = NO_AUTODOC;
|
||||
if (autodoc) {
|
||||
char *c = Char(autodoc);
|
||||
if (c && isdigit(c[0])) {
|
||||
char *c = Char(autodoc);
|
||||
if (c) {
|
||||
if (isdigit(c[0])) {
|
||||
dlevel = (autodoc_l) atoi(c);
|
||||
} else {
|
||||
if (strcmp(c, "extended") == 0) {
|
||||
|
|
@ -1602,11 +1857,11 @@ public:
|
|||
else
|
||||
return v;
|
||||
}
|
||||
if (Strcmp(v, "true") == 0 || Strcmp(v, "FALSE") == 0)
|
||||
if (Strcmp(v, "true") == 0 || Strcmp(v, "TRUE") == 0)
|
||||
return NewString("True");
|
||||
if (Strcmp(v, "false") == 0 || Strcmp(v, "FALSE") == 0)
|
||||
return NewString("False");
|
||||
if (Strcmp(v, "NULL") == 0)
|
||||
if (Strcmp(v, "NULL") == 0 || Strcmp(v, "nullptr") == 0)
|
||||
return SwigType_ispointer(t) ? NewString("None") : NewString("0");
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -2354,7 +2609,7 @@ public:
|
|||
Printf(parse_args, "if (!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,0)) SWIG_fail;\n", iname, num_fixed_arguments, tuple_arguments);
|
||||
}
|
||||
}
|
||||
} else if (tuple_arguments > 0) {
|
||||
} else {
|
||||
Printf(parse_args, "if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, num_fixed_arguments, tuple_arguments);
|
||||
Printv(parse_args, arglist, ")) SWIG_fail;\n", NIL);
|
||||
}
|
||||
|
|
@ -2660,7 +2915,7 @@ public:
|
|||
Printf(f->code, "}\n");
|
||||
} else {
|
||||
Printf(f->code, "newargs = PyTuple_GetSlice(args,0,%d);\n", num_fixed_arguments);
|
||||
Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", num_fixed_arguments);
|
||||
Printf(f->code, "varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args));\n", num_fixed_arguments);
|
||||
}
|
||||
Printf(f->code, "resultobj = %s__varargs__(%s,newargs,varargs);\n", wname, builtin ? "self" : "NULL");
|
||||
Append(f->code, "Py_XDECREF(newargs);\n");
|
||||
|
|
@ -3117,22 +3372,23 @@ public:
|
|||
|
||||
But for now, this seems to be the least intrusive way.
|
||||
*/
|
||||
Printf(f_directors_h, "\n\n");
|
||||
Printf(f_directors_h, "/* Internal Director utilities */\n");
|
||||
Printf(f_directors_h, "\n");
|
||||
Printf(f_directors_h, "/* Internal director utilities */\n");
|
||||
Printf(f_directors_h, "public:\n");
|
||||
Printf(f_directors_h, " bool swig_get_inner(const char* swig_protected_method_name) const {\n");
|
||||
Printf(f_directors_h, " bool swig_get_inner(const char *swig_protected_method_name) const {\n");
|
||||
Printf(f_directors_h, " std::map<std::string, bool>::const_iterator iv = swig_inner.find(swig_protected_method_name);\n");
|
||||
Printf(f_directors_h, " return (iv != swig_inner.end() ? iv->second : false);\n");
|
||||
Printf(f_directors_h, " }\n\n");
|
||||
Printf(f_directors_h, " }\n");
|
||||
|
||||
Printf(f_directors_h, " void swig_set_inner(const char* swig_protected_method_name, bool val) const\n");
|
||||
Printf(f_directors_h, " { swig_inner[swig_protected_method_name] = val;}\n\n");
|
||||
Printf(f_directors_h, " void swig_set_inner(const char *swig_protected_method_name, bool val) const {\n");
|
||||
Printf(f_directors_h, " swig_inner[swig_protected_method_name] = val;\n");
|
||||
Printf(f_directors_h, " }\n");
|
||||
Printf(f_directors_h, "private:\n");
|
||||
Printf(f_directors_h, " mutable std::map<std::string, bool> swig_inner;\n");
|
||||
|
||||
}
|
||||
if (director_method_index) {
|
||||
Printf(f_directors_h, "\n\n");
|
||||
Printf(f_directors_h, "\n");
|
||||
Printf(f_directors_h, "#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n");
|
||||
Printf(f_directors_h, "/* VTable implementation */\n");
|
||||
Printf(f_directors_h, " PyObject *swig_get_method(size_t method_index, const char *method_name) const {\n");
|
||||
|
|
@ -3206,19 +3462,13 @@ public:
|
|||
if (shadow && !Getattr(n, "feature:onlychildren")) {
|
||||
Node *mod = Getattr(n, "module");
|
||||
if (mod) {
|
||||
String *importname = NewString("");
|
||||
String *modname = Getattr(mod, "name");
|
||||
if (Strcmp(modname, mainmodule) != 0) {
|
||||
// check if the module has a package option
|
||||
Node *options = Getattr(mod, "options");
|
||||
String *pkg = options ? Getattr(options, "package") : 0;
|
||||
if (pkg && (!package || Strcmp(pkg, package) != 0)) {
|
||||
Printf(importname, "%s.", pkg);
|
||||
}
|
||||
Printf(importname, "%s.", modname);
|
||||
}
|
||||
Append(importname, Getattr(n, "sym:name"));
|
||||
Node *options = Getattr(mod, "options");
|
||||
String *pkg = options ? Getattr(options, "package") : 0;
|
||||
String *sym = Getattr(n, "sym:name");
|
||||
String *importname = import_name_string(package, mainmodule, pkg, modname, sym);
|
||||
Setattr(n, "python:proxy", importname);
|
||||
Delete(importname);
|
||||
}
|
||||
}
|
||||
int result = Language::classDeclaration(n);
|
||||
|
|
@ -3386,7 +3636,20 @@ public:
|
|||
if (GetFlag(n, "feature:python:nondynamic"))
|
||||
Setattr(n, "feature:python:tp_setattro", "SWIG_Python_NonDynamicSetAttr");
|
||||
|
||||
String *quoted_symname = NewStringf("\"%s\"", symname);
|
||||
Node *mod = Getattr(n, "module");
|
||||
String *modname = mod ? Getattr(mod, "name") : 0;
|
||||
String *quoted_symname;
|
||||
if (package) {
|
||||
if (modname)
|
||||
quoted_symname = NewStringf("\"%s.%s.%s\"", package, modname, symname);
|
||||
else
|
||||
quoted_symname = NewStringf("\"%s.%s\"", package, symname);
|
||||
} else {
|
||||
if (modname)
|
||||
quoted_symname = NewStringf("\"%s.%s\"", modname, symname);
|
||||
else
|
||||
quoted_symname = NewStringf("\"%s\"", symname);
|
||||
}
|
||||
String *quoted_rname = NewStringf("\"%s\"", rname);
|
||||
char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "SwigPyBuiltin_BadInit";
|
||||
String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES");
|
||||
|
|
@ -3444,7 +3707,7 @@ public:
|
|||
printSlot(f, getSlot(n, "feature:python:tp_dict"), "tp_dict");
|
||||
printSlot(f, getSlot(n, "feature:python:tp_descr_get"), "tp_descr_get", "descrgetfunc");
|
||||
printSlot(f, getSlot(n, "feature:python:tp_descr_set"), "tp_descr_set", "descrsetfunc");
|
||||
Printf(f, " (size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /* tp_dictoffset */\n");
|
||||
Printf(f, " (Py_ssize_t)offsetof(SwigPyObject, dict), /* tp_dictoffset */\n");
|
||||
printSlot(f, tp_init, "tp_init", "initproc");
|
||||
printSlot(f, getSlot(n, "feature:python:tp_alloc"), "tp_alloc", "allocfunc");
|
||||
printSlot(f, "0", "tp_new", "newfunc");
|
||||
|
|
@ -3773,7 +4036,7 @@ public:
|
|||
if (builtin)
|
||||
builtin_pre_decl(n);
|
||||
|
||||
/* Overide the shadow file so we can capture its methods */
|
||||
/* Override the shadow file so we can capture its methods */
|
||||
f_shadow = NewString("");
|
||||
|
||||
// Set up type check for director class constructor
|
||||
|
|
@ -3840,7 +4103,7 @@ public:
|
|||
if (!have_constructor) {
|
||||
if (!builtin)
|
||||
Printv(f_shadow_file, tab4, "def __init__(self, *args, **kwargs): raise AttributeError(\"", "No constructor defined",
|
||||
(Getattr(n, "abstract") ? " - class is abstract" : ""), "\")\n", NIL);
|
||||
(Getattr(n, "abstracts") ? " - class is abstract" : ""), "\")\n", NIL);
|
||||
} else if (fastinit && !builtin) {
|
||||
|
||||
Printv(f_wrappers, "SWIGINTERN PyObject *", class_name, "_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", NIL);
|
||||
|
|
@ -3855,7 +4118,7 @@ public:
|
|||
if (new_repr) {
|
||||
Printv(f_shadow_file, tab4, "__repr__ = _swig_repr\n", NIL);
|
||||
} else {
|
||||
Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"<C ", rname, " instance at 0x%x>\" % (self.this,)\n", NIL);
|
||||
Printv(f_shadow_file, tab4, "def __repr__(self):\n", tab8, "return \"<C ", rname, " instance at %p>\" % (self.this,)\n", NIL);
|
||||
}
|
||||
Delete(rname);
|
||||
}
|
||||
|
|
@ -4500,12 +4763,16 @@ public:
|
|||
String *code = Getattr(n, "code");
|
||||
String *section = Getattr(n, "section");
|
||||
|
||||
if ((!ImportMode) && ((Cmp(section, "python") == 0) || (Cmp(section, "shadow") == 0))) {
|
||||
if (!ImportMode && (Cmp(section, "python") == 0 || Cmp(section, "shadow") == 0)) {
|
||||
if (shadow) {
|
||||
String *pycode = pythoncode(code, shadow_indent);
|
||||
Printv(f_shadow, pycode, NIL);
|
||||
Delete(pycode);
|
||||
}
|
||||
} else if (!ImportMode && (Cmp(section, "pythonbegin") == 0)) {
|
||||
String *pycode = pythoncode(code, "");
|
||||
Printv(f_shadow_begin, pycode, NIL);
|
||||
Delete(pycode);
|
||||
} else {
|
||||
Language::insertDirective(n);
|
||||
}
|
||||
|
|
@ -4575,18 +4842,17 @@ int PYTHON::classDirectorMethods(Node *n) {
|
|||
int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
||||
int is_void = 0;
|
||||
int is_pointer = 0;
|
||||
String *decl;
|
||||
String *type;
|
||||
String *name;
|
||||
String *classname;
|
||||
String *decl = Getattr(n, "decl");
|
||||
String *name = Getattr(n, "name");
|
||||
String *classname = Getattr(parent, "sym:name");
|
||||
String *c_classname = Getattr(parent, "name");
|
||||
String *symname = Getattr(n, "sym:name");
|
||||
String *declaration;
|
||||
ParmList *l;
|
||||
Wrapper *w;
|
||||
String *declaration = NewString("");
|
||||
ParmList *l = Getattr(n, "parms");
|
||||
Wrapper *w = NewWrapper();
|
||||
String *tm;
|
||||
String *wrap_args = NewString("");
|
||||
String *return_type;
|
||||
String *returntype = Getattr(n, "type");
|
||||
String *value = Getattr(n, "value");
|
||||
String *storage = Getattr(n, "storage");
|
||||
bool pure_virtual = false;
|
||||
|
|
@ -4600,35 +4866,15 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
}
|
||||
}
|
||||
|
||||
classname = Getattr(parent, "sym:name");
|
||||
type = Getattr(n, "type");
|
||||
name = Getattr(n, "name");
|
||||
|
||||
w = NewWrapper();
|
||||
declaration = NewString("");
|
||||
|
||||
/* determine if the method returns a pointer */
|
||||
decl = Getattr(n, "decl");
|
||||
is_pointer = SwigType_ispointer_return(decl);
|
||||
is_void = (!Cmp(type, "void") && !is_pointer);
|
||||
|
||||
/* form complete return type */
|
||||
return_type = Copy(type);
|
||||
{
|
||||
SwigType *t = Copy(decl);
|
||||
SwigType *f = 0;
|
||||
f = SwigType_pop_function(t);
|
||||
SwigType_push(return_type, t);
|
||||
Delete(f);
|
||||
Delete(t);
|
||||
}
|
||||
is_void = (!Cmp(returntype, "void") && !is_pointer);
|
||||
|
||||
/* virtual method definition */
|
||||
l = Getattr(n, "parms");
|
||||
String *target;
|
||||
String *pclassname = NewStringf("SwigDirector_%s", classname);
|
||||
String *qualified_name = NewStringf("%s::%s", pclassname, name);
|
||||
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : type;
|
||||
SwigType *rtype = Getattr(n, "conversion_operator") ? 0 : Getattr(n, "classDirectorMethods:type");
|
||||
target = Swig_method_decl(rtype, decl, qualified_name, l, 0, 0);
|
||||
Printf(w->def, "%s", target);
|
||||
Delete(qualified_name);
|
||||
|
|
@ -4651,7 +4897,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
if (throw_parm_list)
|
||||
Swig_typemap_attach_parms("throws", throw_parm_list, 0);
|
||||
for (p = throw_parm_list; p; p = nextSibling(p)) {
|
||||
if ((tm = Getattr(p, "tmap:throws"))) {
|
||||
if (Getattr(p, "tmap:throws")) {
|
||||
if (gencomma++) {
|
||||
Append(w->def, ", ");
|
||||
Append(declaration, ", ");
|
||||
|
|
@ -4676,7 +4922,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
*/
|
||||
if (!is_void) {
|
||||
if (!(ignored_method && !pure_virtual)) {
|
||||
String *cres = SwigType_lstr(return_type, "c_result");
|
||||
String *cres = SwigType_lstr(returntype, "c_result");
|
||||
Printf(w->code, "%s;\n", cres);
|
||||
Delete(cres);
|
||||
}
|
||||
|
|
@ -4794,7 +5040,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
/* if necessary, cast away const since Python doesn't support it! */
|
||||
if (SwigType_isconst(nptype)) {
|
||||
nonconst = NewStringf("nc_tmp_%s", pname);
|
||||
String *nonconst_i = NewStringf("= const_cast<%s>(%s)", SwigType_lstr(ptype, 0), ppname);
|
||||
String *nonconst_i = NewStringf("= const_cast< %s >(%s)", SwigType_lstr(ptype, 0), ppname);
|
||||
Wrapper_add_localv(w, nonconst, SwigType_lstr(ptype, 0), nonconst, nonconst_i, NIL);
|
||||
Delete(nonconst_i);
|
||||
Swig_warning(WARN_LANG_DISCARD_CONST, input_file, line_number,
|
||||
|
|
@ -4945,16 +5191,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
|
||||
/* marshal return value */
|
||||
if (!is_void) {
|
||||
/* this seems really silly. the node's type excludes
|
||||
* qualifier/pointer/reference markers, which have to be retrieved
|
||||
* from the decl field to construct return_type. but the typemap
|
||||
* lookup routine uses the node's type, so we have to swap in and
|
||||
* out the correct type. it's not just me, similar silliness also
|
||||
* occurs in Language::cDeclaration().
|
||||
*/
|
||||
Setattr(n, "type", return_type);
|
||||
tm = Swig_typemap_lookup("directorout", n, Swig_cresult_name(), w);
|
||||
Setattr(n, "type", type);
|
||||
if (tm != 0) {
|
||||
if (outputs > 1) {
|
||||
Printf(w->code, "output = PyTuple_GetItem(%s, %d);\n", Swig_cresult_name(), idx++);
|
||||
|
|
@ -4980,7 +5217,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
Delete(tm);
|
||||
} else {
|
||||
Swig_warning(WARN_TYPEMAP_DIRECTOROUT_UNDEF, input_file, line_number,
|
||||
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(return_type, 0), SwigType_namestr(c_classname),
|
||||
"Unable to use return type %s in director method %s::%s (skipping method).\n", SwigType_str(returntype, 0), SwigType_namestr(c_classname),
|
||||
SwigType_namestr(name));
|
||||
status = SWIG_ERROR;
|
||||
}
|
||||
|
|
@ -5017,8 +5254,8 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
|
||||
if (!is_void) {
|
||||
if (!(ignored_method && !pure_virtual)) {
|
||||
String *rettype = SwigType_str(return_type, 0);
|
||||
if (!SwigType_isreference(return_type)) {
|
||||
String *rettype = SwigType_str(returntype, 0);
|
||||
if (!SwigType_isreference(returntype)) {
|
||||
Printf(w->code, "return (%s) c_result;\n", rettype);
|
||||
} else {
|
||||
Printf(w->code, "return (%s) *c_result;\n", rettype);
|
||||
|
|
@ -5056,7 +5293,6 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
|
|||
|
||||
/* clean up */
|
||||
Delete(wrap_args);
|
||||
Delete(return_type);
|
||||
Delete(pclassname);
|
||||
DelWrapper(w);
|
||||
return status;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue