Merge branch 'master' into director-unwrap-result

This commit is contained in:
Olly Betts 2022-03-01 11:34:59 +13:00 committed by GitHub
commit deb7cbf741
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1099 changed files with 14845 additions and 34359 deletions

View file

@ -73,8 +73,10 @@ static int py3 = 0;
/* C++ Support + Shadow Classes */
static int have_constructor;
static int have_repr;
static int have_constructor = 0;
static int have_repr = 0;
static bool have_builtin_static_member_method_callback = false;
static bool have_fast_proxy_static_member_method_callback = false;
static String *real_classname;
/* Thread Support */
@ -93,6 +95,7 @@ static int nortti = 0;
static int relativeimport = 0;
/* flags for the make_autodoc function */
namespace {
enum autodoc_t {
AUTODOC_CLASS,
AUTODOC_CTOR,
@ -103,7 +106,7 @@ enum autodoc_t {
AUTODOC_CONST,
AUTODOC_VAR
};
}
static const char *usage1 = "\
Python Options (available with -python)\n\
@ -313,7 +316,6 @@ public:
} else {
Swig_arg_error();
}
/* end added */
} else if (strcmp(argv[i], "-globals") == 0) {
if (argv[i + 1]) {
global_name = NewString(argv[i + 1]);
@ -444,6 +446,15 @@ public:
}
}
if (builtin && !shadow) {
Printf(stderr, "Incompatible options -builtin and -noproxy specified.\n");
SWIG_exit(EXIT_FAILURE);
}
if (fastproxy) {
Preprocessor_define("SWIGPYTHON_FASTPROXY", 0);
}
if (doxygen)
doxygenTranslator = new PyDocConverter(doxygen_translator_flags);
@ -611,6 +622,10 @@ public:
Printf(f_runtime, "#define SWIGPYTHON_BUILTIN\n");
}
if (fastproxy) {
Printf(f_runtime, "#define SWIGPYTHON_FASTPROXY\n");
}
Printf(f_runtime, "\n");
Printf(f_header, "#ifdef SWIG_TypeQuery\n");
@ -814,6 +829,10 @@ public:
Append(const_code, "{0, 0, 0, 0.0, 0, 0}};\n");
Printf(f_wrappers, "%s\n", const_code);
if (have_fast_proxy_static_member_method_callback)
Printf(f_init, " SWIG_Python_FixMethods(SwigMethods_proxydocs, swig_const_table, swig_types, swig_type_initial);\n\n");
initialize_threads(f_init);
Printf(f_init, "#if PY_VERSION_HEX >= 0x03000000\n");
@ -846,8 +865,13 @@ public:
Printv(f_shadow_py, "\n", f_shadow_begin, "\n", NIL);
Printv(f_shadow_py, "\nfrom sys import version_info as _swig_python_version_info\n", NULL);
Printv(f_shadow_py, "if _swig_python_version_info < (2, 7, 0):\n", NULL);
Printv(f_shadow_py, tab4, "raise RuntimeError(\"Python 2.7 or later required\")\n\n", NULL);
if (py3) {
Printv(f_shadow_py, "if _swig_python_version_info < (3, 0):\n", NULL);
Printv(f_shadow_py, tab4, "raise RuntimeError(\"Python 3.x or later required\")\n\n", NULL);
} else {
Printv(f_shadow_py, "if _swig_python_version_info < (2, 7, 0):\n", NULL);
Printv(f_shadow_py, tab4, "raise RuntimeError(\"Python 2.7 or later required\")\n\n", NULL);
}
if (Len(f_shadow_after_begin) > 0)
Printv(f_shadow_py, f_shadow_after_begin, "\n", NIL);
@ -905,15 +929,15 @@ public:
* as a replacement of new.instancemethod in Python 3.
* ------------------------------------------------------------ */
int add_pyinstancemethod_new() {
String *name = NewString("SWIG_PyInstanceMethod_New");
String *line = NewString("");
Printf(line, "\t { \"%s\", %s, METH_O, NULL},\n", name, name);
Append(methods, line);
if (fastproxy) {
if (!builtin && fastproxy) {
String *name = NewString("SWIG_PyInstanceMethod_New");
String *line = NewString("");
Printf(line, "\t { \"%s\", %s, METH_O, NULL},\n", name, name);
Append(methods, line);
Append(methods_proxydocs, line);
Delete(line);
Delete(name);
}
Delete(line);
Delete(name);
return 0;
}
@ -923,7 +947,7 @@ public:
* generated for static methods when using -fastproxy
* ------------------------------------------------------------ */
int add_pystaticmethod_new() {
if (fastproxy) {
if (!builtin && fastproxy) {
String *name = NewString("SWIG_PyStaticMethod_New");
String *line = NewString("");
Printf(line, "\t { \"%s\", %s, METH_O, NULL},\n", name, name);
@ -2250,7 +2274,7 @@ public:
return parms;
}
bool funcanno = py3 ? true : false;
bool funcanno = Equal(Getattr(n, "feature:python:annotations"), "c") ? true : false;
String *params = NewString("");
String *_params = make_autodocParmList(n, false, ((in_class || has_self_for_count)? 2 : 1), is_calling, funcanno);
@ -2366,8 +2390,8 @@ public:
if (ret)
ret = SwigType_str(ret, 0);
}
return (ret && py3) ? NewStringf(" -> \"%s\"", ret)
: NewString("");
bool funcanno = Equal(Getattr(n, "feature:python:annotations"), "c") ? true : false;
return (ret && funcanno) ? NewStringf(" -> \"%s\"", ret) : NewString("");
}
/* ------------------------------------------------------------
@ -2472,6 +2496,7 @@ public:
Printf(methods, "\"swig_ptr: %s\"", Getattr(n, "feature:callback:name"));
if (fastproxy) {
Printf(methods_proxydocs, "\"swig_ptr: %s\"", Getattr(n, "feature:callback:name"));
have_fast_proxy_static_member_method_callback = true;
}
} else {
Append(methods, "NULL");
@ -2527,6 +2552,11 @@ public:
const char *builtin_kwargs = builtin_ctor ? ", PyObject *kwargs" : "";
Printv(f->def, linkage, builtin_ctor ? "int " : "PyObject *", wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
if (builtin) {
/* Avoid warning if the self parameter is not used. */
Append(f->code, "(void)self;\n");
}
Wrapper_add_local(f, "argc", "Py_ssize_t argc");
Printf(tmp, "PyObject *argv[%d] = {0}", maxargs + 1);
Wrapper_add_local(f, "argv", tmp);
@ -2696,7 +2726,6 @@ public:
bool add_self = builtin_self && (!builtin_ctor || director_class);
bool builtin_getter = (builtin && GetFlag(n, "memberget"));
bool builtin_setter = (builtin && GetFlag(n, "memberset") && !builtin_getter);
char const *self_param = builtin ? "self" : "SWIGUNUSEDPARM(self)";
char const *wrap_return = builtin_ctor ? "int " : "PyObject *";
String *linkage = NewString("SWIGINTERN ");
String *wrapper_name = Swig_name_wrapper(iname);
@ -2751,9 +2780,9 @@ public:
const char *builtin_kwargs = builtin_ctor ? ", PyObject *kwargs" : "";
if (!allow_kwargs || overname) {
if (!varargs) {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
} else {
Printv(f->def, linkage, wrap_return, wname, "__varargs__", "(PyObject *", self_param, ", PyObject *args, PyObject *varargs) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "__varargs__", "(PyObject *self, PyObject *args, PyObject *varargs", builtin_kwargs, ") {", NIL);
}
if (allow_kwargs) {
Swig_warning(WARN_LANG_OVERLOAD_KEYWORD, input_file, line_number, "Can't use keyword arguments with overloaded functions (%s).\n", Swig_name_decl(n));
@ -2764,8 +2793,14 @@ public:
Swig_warning(WARN_LANG_VARARGS_KEYWORD, input_file, line_number, "Can't wrap varargs with keyword arguments enabled\n");
varargs = 0;
}
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args, PyObject *kwargs) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args, PyObject *kwargs) {", NIL);
}
if (builtin) {
/* Avoid warning if the self parameter is not used. */
Append(f->code, "(void)self;\n");
}
if (!builtin || !in_class || tuple_arguments > 0 || builtin_ctor) {
if (!allow_kwargs) {
Append(parse_args, " if (!PyArg_ParseTuple(args, \"");
@ -2792,7 +2827,7 @@ public:
/* Generate code for argument marshalling */
if (funpack) {
if (num_arguments > 0 && !overname) {
if (num_arguments > (builtin_self && !constructor ? 1 : 0) && !overname) {
sprintf(source, "PyObject *swig_obj[%d]", num_arguments);
Wrapper_add_localv(f, "swig_obj", source, NIL);
}
@ -2862,8 +2897,6 @@ public:
} else {
Replaceall(tm, "$self", "obj0");
}
Replaceall(tm, "$source", source);
Replaceall(tm, "$target", ln);
Replaceall(tm, "$input", source);
Setattr(p, "emit:input", source); /* Save the location of the object */
@ -2926,14 +2959,14 @@ public:
Clear(f->def);
if (overname) {
if (noargs) {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {", NIL);
} else {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
}
Printf(parse_args, "if ((nobjs < %d) || (nobjs > %d)) SWIG_fail;\n", num_required, num_arguments);
} else {
int is_tp_call = Equal(Getattr(n, "feature:python:slot"), "tp_call");
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
if (builtin_ctor)
Printf(parse_args, "if (!SWIG_Python_CheckNoKeywords(kwargs, \"%s\")) SWIG_fail;\n", iname);
if (onearg && !builtin_ctor && !is_tp_call) {
@ -2971,7 +3004,6 @@ public:
/* Insert constraint checking code */
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:check"))) {
Replaceall(tm, "$target", Getattr(p, "lname"));
Printv(f->code, tm, "\n", NIL);
p = Getattr(p, "tmap:check:next");
} else {
@ -2993,7 +3025,6 @@ public:
}
}
if (tm && (Len(tm) != 0)) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Printv(cleanup, tm, "\n", NIL);
}
p = Getattr(p, "tmap:freearg:next");
@ -3005,8 +3036,6 @@ public:
/* Insert argument output code */
for (p = l; p;) {
if ((tm = Getattr(p, "tmap:argout"))) {
Replaceall(tm, "$source", Getattr(p, "lname"));
Replaceall(tm, "$target", "resultobj");
Replaceall(tm, "$arg", Getattr(p, "emit:input"));
Replaceall(tm, "$input", Getattr(p, "emit:input"));
Printv(outarg, tm, "\n", NIL);
@ -3095,8 +3124,6 @@ public:
} else {
Replaceall(tm, "$self", "obj0");
}
Replaceall(tm, "$source", Swig_cresult_name());
Replaceall(tm, "$target", "resultobj");
Replaceall(tm, "$result", "resultobj");
if (builtin_ctor) {
Replaceall(tm, "$owner", "SWIG_BUILTIN_INIT");
@ -3160,7 +3187,6 @@ public:
/* Look to see if there is any newfree cleanup code */
if (GetFlag(n, "feature:new")) {
if ((tm = Swig_typemap_lookup("newfree", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
@ -3168,7 +3194,6 @@ public:
/* See if there is any return cleanup code */
if ((tm = Swig_typemap_lookup("ret", n, Swig_cresult_name(), 0))) {
Replaceall(tm, "$source", Swig_cresult_name());
Printf(f->code, "%s\n", tm);
Delete(tm);
}
@ -3231,9 +3256,9 @@ public:
f = NewWrapper();
if (funpack) {
// Note: funpack is currently always false for varargs
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, Py_ssize_t nobjs, PyObject **swig_obj) {", NIL);
} else {
Printv(f->def, linkage, wrap_return, wname, "(PyObject *", self_param, ", PyObject *args", builtin_kwargs, ") {", NIL);
Printv(f->def, linkage, wrap_return, wname, "(PyObject *self, PyObject *args", builtin_kwargs, ") {", NIL);
}
Wrapper_add_local(f, "resultobj", builtin_ctor ? "int resultobj" : "PyObject *resultobj");
Wrapper_add_local(f, "varargs", "PyObject *varargs");
@ -3251,10 +3276,10 @@ public:
Printf(f->code, " Py_XINCREF(swig_obj[i + %d]);\n", num_fixed_arguments);
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));\n", num_fixed_arguments);
Printf(f->code, "newargs = PyTuple_GetSlice(args, 0, %d);\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");
Printf(f->code, "resultobj = %s__varargs__(%s, newargs, varargs%s);\n", wname, builtin ? "self" : "NULL", strlen(builtin_kwargs) == 0 ? "" : ", kwargs");
Append(f->code, "Py_XDECREF(newargs);\n");
Append(f->code, "Py_XDECREF(varargs);\n");
Append(f->code, "return resultobj;\n");
@ -3426,7 +3451,6 @@ public:
Printf(f_init, "#endif\n");
Printf(f_init, "\t }\n");
Printf(f_init, "\t PyDict_SetItemString(md, \"%s\", globals);\n", global_name);
Printf(f_init, "\t Py_DECREF(globals);\n");
if (builtin)
Printf(f_init, "\t SwigPyBuiltin_AddPublicSymbol(public_interface, \"%s\");\n", global_name);
have_globals = 1;
@ -3454,8 +3478,6 @@ public:
}
Printf(setf->def, "SWIGINTERN int %s(PyObject *_val) {", varsetname);
if ((tm = Swig_typemap_lookup("varin", n, name, 0))) {
Replaceall(tm, "$source", "_val");
Replaceall(tm, "$target", name);
Replaceall(tm, "$input", "_val");
if (Getattr(n, "tmap:varin:implicitconv")) {
Replaceall(tm, "$implicitconv", get_implicitconv_flag(n));
@ -3496,8 +3518,6 @@ public:
Append(getf->code, " (void)self;\n");
}
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
Replaceall(tm, "$source", name);
Replaceall(tm, "$target", "pyobj");
Replaceall(tm, "$result", "pyobj");
addfail = emit_action_code(n, getf->code, tm);
Delete(tm);
@ -3577,8 +3597,6 @@ public:
}
if ((tm = Swig_typemap_lookup("consttab", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
Printf(const_code, "%s,\n", tm);
Delete(tm);
@ -3593,8 +3611,6 @@ public:
}
if ((tm = Swig_typemap_lookup("constcode", n, name, 0))) {
Replaceall(tm, "$source", value);
Replaceall(tm, "$target", name);
Replaceall(tm, "$value", value);
if (needs_swigconstant(n) && !builtin && (shadow) && (!(shadow & PYSHADOW_MEMBER)) && (!in_class || !Getattr(n, "feature:python:callback"))) {
// Generate `*_swigconstant()` method which registers the new constant.
@ -3606,7 +3622,7 @@ public:
// class type (the SWIG_init() is called before shadow classes are
// defined and registered).
Printf(f_wrappers, "SWIGINTERN PyObject *%s_swigconstant(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {\n", iname);
Printf(f_wrappers, tab2 "PyObject *module;\n", tm);
Printf(f_wrappers, tab2 "PyObject *module;\n");
Printf(f_wrappers, tab2 "PyObject *d;\n");
Printf(f_wrappers, tab2 "if (!SWIG_Python_UnpackTuple(args, \"swigconstant\", 1, 1, &module)) return NULL;\n");
Printf(f_wrappers, tab2 "d = PyModule_GetDict(module);\n");
@ -3946,6 +3962,10 @@ public:
int funpack = fastunpack;
static String *tp_new = NewString("PyType_GenericNew");
if (have_builtin_static_member_method_callback) {
Printf(f_init, " SWIG_Python_FixMethods(SwigPyBuiltin_%s_methods, swig_const_table, swig_types, swig_type_initial);\n", mname);
}
Printv(f_init, " SwigPyBuiltin_SetMetaType(builtin_pytype, metatype);\n", NIL);
// We cant statically initialize a structure member with a function defined in another C module
@ -4016,7 +4036,7 @@ public:
if (GetFlag(mgetset, "static")) {
Printf(f, "static PyGetSetDef %s_def = %s;\n", gspair, entry);
Printf(f_init, "static_getset = SwigPyStaticVar_new_getset(metatype, &%s_def);\n", gspair);
Printf(f_init, "PyDict_SetItemString(d, static_getset->d_getset->name, (PyObject *) static_getset);\n", memname);
Printf(f_init, "PyDict_SetItemString(d, static_getset->d_getset->name, (PyObject *) static_getset);\n");
Printf(f_init, "Py_DECREF(static_getset);\n");
} else {
Printf(getset_def, " %s,\n", entry);
@ -4306,6 +4326,10 @@ public:
// struct _dictkeysobject *ht_cached_keys;
printSlot(f, getSlot(n, "feature:python:ht_cached_keys"), "ht_cached_keys");
Printv(f, "#endif\n", NIL);
Printv(f, "#if PY_VERSION_HEX >= 0x03090000\n", NIL);
printSlot(f, getSlot(n, "feature:python:ht_module"), "ht_module", "PyObject *");
Printv(f, "#endif\n", NIL);
Printf(f, "};\n\n");
String *clientdata = NewString("");
@ -4372,6 +4396,7 @@ public:
/* Create new strings for building up a wrapper function */
have_constructor = 0;
have_repr = 0;
have_builtin_static_member_method_callback = false;
class_name = Getattr(n, "sym:name");
real_classname = Getattr(n, "name");
@ -4461,7 +4486,9 @@ public:
Printf(f_shadow, "(Exception)");
} else {
Printf(f_shadow, "(object");
Printf(f_shadow, py3 && GetFlag(n, "feature:python:nondynamic") ? ", metaclass=_SwigNonDynamicMeta" : "", ")");
if (py3 && GetFlag(n, "feature:python:nondynamic")) {
Printf(f_shadow, ", metaclass=_SwigNonDynamicMeta");
}
Printf(f_shadow, ")");
}
}
@ -4732,6 +4759,7 @@ public:
Swig_restore(n);
}
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
if (builtin && in_class) {
if ((GetFlagAttr(n, "feature:extend") || checkAttribute(n, "access", "public"))
&& !Getattr(class_members, symname)) {
@ -4746,7 +4774,7 @@ public:
else if (funpack && argcount == 1)
Append(pyflags, "METH_O");
else
Append(pyflags, "METH_VARARGS");
Append(pyflags, kw ? "METH_VARARGS|METH_KEYWORDS" : "METH_VARARGS");
// Cast via void(*)(void) to suppress GCC -Wcast-function-type warning.
// Python should always call the function correctly, but the Python C
// API requires us to store it in function pointer of a different type.
@ -4754,6 +4782,11 @@ public:
String *ds = cdocstring(n, AUTODOC_STATICFUNC);
Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"%s\" },\n", symname, wname, pyflags, ds);
Delete(ds);
} else if (Getattr(n, "feature:callback")) {
String *ds = NewStringf("swig_ptr: %s", Getattr(n, "feature:callback:name"));
Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"%s\" },\n", symname, wname, pyflags, ds);
Delete(ds);
have_builtin_static_member_method_callback = true;
} else {
Printf(builtin_methods, " { \"%s\", (PyCFunction)(void(*)(void))%s, %s, \"\" },\n", symname, wname, pyflags);
}
@ -4772,7 +4805,6 @@ public:
String *staticfunc_name = NewString(fastproxy ? "_swig_new_static_method" : "staticmethod");
bool fast = (fastproxy && !have_addtofunc(n)) || Getattr(n, "feature:callback");
if (!fast || olddefs) {
int kw = (check_kwargs(n) && !Getattr(n, "sym:overloaded")) ? 1 : 0;
String *parms = make_pyParmList(n, false, false, kw);
String *callParms = make_pyParmList(n, false, true, kw);
Printv(f_shadow, "\n", tab4, "@staticmethod", NIL);
@ -4869,6 +4901,7 @@ public:
String *classname = Swig_class_name(parent);
String *rclassname = Swig_class_name(getCurrentClass());
assert(rclassname);
(void)rclassname;
String *parms = make_pyParmList(n, true, false, allow_kwargs);
/* Pass 'self' only if using director */