python3 support; passes all regressions.
Adding argcargvtest_runme3.py, because 2to3 can't handle it. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12425 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
00b5fa9c47
commit
62fef1bf99
6 changed files with 143 additions and 13 deletions
27
Examples/test-suite/python/argcargvtest_runme3.py
Normal file
27
Examples/test-suite/python/argcargvtest_runme3.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from argcargvtest import *
|
||||
|
||||
largs=['hi','hola','hello']
|
||||
if mainc(largs) != 3:
|
||||
raise RuntimeError("bad main typemap")
|
||||
|
||||
targs=('hi','hola')
|
||||
if mainv(targs,1) != 'hola':
|
||||
print(mainv(targs,1))
|
||||
raise RuntimeError("bad main typemap")
|
||||
|
||||
targs=('hi', 'hola')
|
||||
if mainv(targs,1) != 'hola':
|
||||
raise RuntimeError("bad main typemap")
|
||||
|
||||
try:
|
||||
error = 0
|
||||
mainv('hello',1)
|
||||
error = 1
|
||||
except TypeError:
|
||||
pass
|
||||
if error:
|
||||
raise RuntimeError("bad main typemap")
|
||||
|
||||
|
||||
|
||||
initializeApp(largs)
|
||||
|
|
@ -289,9 +289,15 @@ SwigPyStaticVar_dealloc(PyDescrObject *descr)
|
|||
SWIGRUNTIME PyObject *
|
||||
SwigPyStaticVar_repr(PyGetSetDescrObject *descr)
|
||||
{
|
||||
return PyString_FromFormat("<class attribute '%s' of type '%s'>",
|
||||
PyString_AsString(descr->d_name),
|
||||
descr->d_type->tp_name);
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
return PyUnicode_FromFormat
|
||||
("<class attribute '%U' of type '%s'>",
|
||||
descr->d_name, descr->d_type->tp_name);
|
||||
#else
|
||||
return PyString_FromFormat
|
||||
("<class attribute '%s' of type '%s'>",
|
||||
PyString_AsString(descr->d_name), descr->d_type->tp_name);
|
||||
#endif
|
||||
}
|
||||
|
||||
SWIGRUNTIME int
|
||||
|
|
@ -307,10 +313,15 @@ SwigPyStaticVar_get (PyGetSetDescrObject *descr, PyObject *obj, PyObject *type)
|
|||
{
|
||||
if (descr->d_getset->get != NULL)
|
||||
return descr->d_getset->get(obj, descr->d_getset->closure);
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"attribute '%.300U' of '%.100s' objects is not readable",
|
||||
descr->d_name, descr->d_type->tp_name);
|
||||
#else
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"attribute '%.300s' of '%.100s' objects is not readable",
|
||||
PyString_AsString(descr->d_name),
|
||||
descr->d_type->tp_name);
|
||||
PyString_AsString(descr->d_name), descr->d_type->tp_name);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -321,16 +332,27 @@ SwigPyStaticVar_set (PyGetSetDescrObject *descr, PyObject *obj, PyObject *value)
|
|||
|
||||
if (descr->d_getset->set != NULL)
|
||||
return descr->d_getset->set(obj, value, descr->d_getset->closure);
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"attribute '%.300U' of '%.100s' objects is not writable",
|
||||
descr->d_name,
|
||||
descr->d_type->tp_name);
|
||||
#else
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"attribute '%.300s' of '%.100s' objects is not writable",
|
||||
PyString_AsString(descr->d_name),
|
||||
descr->d_type->tp_name);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
SWIGRUNTIME PyTypeObject SwigPyStaticVar_Type = {
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
||||
#else
|
||||
PyObject_HEAD_INIT(&PyType_Type)
|
||||
0,
|
||||
#endif
|
||||
"swig_static_var_getset_descriptor",
|
||||
sizeof(PyGetSetDescrObject),
|
||||
0,
|
||||
|
|
@ -349,7 +371,7 @@ SWIGRUNTIME PyTypeObject SwigPyStaticVar_Type = {
|
|||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
|
||||
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_CLASS, /* tp_flags */
|
||||
0, /* tp_doc */
|
||||
SwigPyStaticVar_traverse, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
|
|
@ -375,13 +397,25 @@ SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value)
|
|||
descrsetfunc local_set = attribute->ob_type->tp_descr_set;
|
||||
if (local_set != NULL)
|
||||
return local_set(attribute, (PyObject*) type, value);
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"cannot modify read-only attribute '%.50s.%.400U'",
|
||||
type->tp_name, name);
|
||||
#else
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"cannot modify read-only attribute '%.50s.%.400s'",
|
||||
type->tp_name, PyString_AS_STRING(name));
|
||||
#endif
|
||||
} else {
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"type '%.50s' has no attribute '%.400U'",
|
||||
type->tp_name, name);
|
||||
#else
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"type '%.50s' has no attribute '%.400s'",
|
||||
type->tp_name, PyString_AS_STRING(name));
|
||||
#endif
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -634,10 +634,12 @@ namespace swig
|
|||
%fragment("SwigPySequence_Base");
|
||||
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
%feature("pyslot", "sq_item", functype="ssizeargfunc") __getitem__;
|
||||
%feature("pyslot", "sq_slice", functype="ssizessizeargfunc") __getslice__;
|
||||
%feature("pyslot", "sq_ass_item", functype="ssizeobjargproc") __setitem__;
|
||||
%feature("pyslot", "sq_ass_slice", functype="ssizessizeobjargproc") __setslice__;
|
||||
//%feature("pyslot", "sq_item", functype="ssizeargfunc") __getitem__;
|
||||
//%feature("pyslot", "sq_slice", functype="ssizessizeargfunc") __getslice__;
|
||||
//%feature("pyslot", "sq_ass_item", functype="ssizeobjargproc") __setitem__;
|
||||
//%feature("pyslot", "sq_ass_slice", functype="ssizessizeobjargproc") __setslice__;
|
||||
%feature("pyslot", "mp_subscript", functype="binaryfunc") __getitem__;
|
||||
%feature("pyslot", "mp_ass_subscript", functype="objobjargproc") __setitem__;
|
||||
#endif // SWIGPYTHON_BUILTIN
|
||||
|
||||
%extend {
|
||||
|
|
@ -651,6 +653,9 @@ namespace swig
|
|||
|
||||
/* typemap for slice object support */
|
||||
%typemap(in) PySliceObject* {
|
||||
if (!PySlice_Check($input)) {
|
||||
%argument_fail(SWIG_TypeError, "$type", $symname, $argnum);
|
||||
}
|
||||
$1 = (PySliceObject *) $input;
|
||||
}
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_POINTER) PySliceObject* {
|
||||
|
|
@ -699,6 +704,17 @@ namespace swig
|
|||
swig::setslice(self, i, j, v);
|
||||
}
|
||||
|
||||
void __setitem__(PySliceObject *slice)
|
||||
throw (std::out_of_range) {
|
||||
Py_ssize_t i, j, step;
|
||||
if( !PySlice_Check(slice) ) {
|
||||
SWIG_Error(SWIG_TypeError, "Slice object expected.");
|
||||
return;
|
||||
}
|
||||
PySlice_GetIndices(slice, self->size(), &i, &j, &step);
|
||||
swig::delslice(self, i,j);
|
||||
}
|
||||
|
||||
void __delitem__(PySliceObject *slice)
|
||||
throw (std::out_of_range) {
|
||||
Py_ssize_t i, j, step;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,13 @@
|
|||
#define PyInt_Check(x) PyLong_Check(x)
|
||||
#define PyInt_AsLong(x) PyLong_AsLong(x)
|
||||
#define PyInt_FromLong(x) PyLong_FromLong(x)
|
||||
#define PyString_FromString(x) PyUnicode_FromString(x)
|
||||
#define PyString_Format(fmt, args) PyUnicode_Format(fmt, args)
|
||||
#define PyString_InternFromString(key) PyUnicode_InternFromString(key)
|
||||
#define PyString_Check(name) PyUnicode_Check(name)
|
||||
#define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE
|
||||
#define PyString_AS_STRING(x) PyUnicode_AS_STRING(x)
|
||||
#define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x)
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -1729,12 +1729,16 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value)
|
|||
|
||||
descr = _PyType_Lookup(tp, name);
|
||||
f = NULL;
|
||||
if (descr != NULL && PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS))
|
||||
if (descr != NULL)
|
||||
f = descr->ob_type->tp_descr_set;
|
||||
if (f == NULL)
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
"'%.100s' object has no attribute '%.200s'",
|
||||
tp->tp_name, PyString_AS_STRING(name));
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
"'%.100s' object has no attribute '%.200U'",
|
||||
#else
|
||||
"'%.100s' object has no attribute '%.200S'",
|
||||
#endif
|
||||
tp->tp_name, name);
|
||||
else
|
||||
res = f(descr, obj, value);
|
||||
|
||||
|
|
|
|||
|
|
@ -3162,7 +3162,11 @@ public:
|
|||
String *templ = NewStringf("SwigPyBuiltin_%s", mname);
|
||||
int funpack = modernargs && fastunpack;
|
||||
|
||||
Printv(f_init, "#if PY_VERSION_HEX >= 0x03000000\n", NIL);
|
||||
Printf(f_init, tab4 "builtin_pytype->ob_base.ob_base.ob_type = metatype;\n");
|
||||
Printv(f_init, "#else\n", NIL);
|
||||
Printf(f_init, tab4 "builtin_pytype->ob_type = metatype;\n");
|
||||
Printv(f_init, "#endif\n", NIL);
|
||||
Printf(f_init, tab4 "builtin_pytype->tp_new = PyType_GenericNew;\n");
|
||||
List *baselist = Getattr(n, "bases");
|
||||
if (baselist) {
|
||||
|
|
@ -3270,14 +3274,19 @@ public:
|
|||
|
||||
char const *tp_init = builtin_tp_init ? Char(builtin_tp_init) : Swig_directorclass(n) ? "0" : "py_builtin_bad_init";
|
||||
String *tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_CHECKTYPES");
|
||||
String *py3_tp_flags = NewString("Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE");
|
||||
|
||||
Printf(f, "static PyHeapTypeObject %s_type = {\n", templ);
|
||||
|
||||
// PyTypeObject ht_type
|
||||
//Printf(f, "template <> PyTypeObject %s::pytype = {\n", templ);
|
||||
Printf(f, " {\n");
|
||||
Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL);
|
||||
Printv(f, " PyVarObject_HEAD_INIT(&PyType_Type, 0)\n", NIL);
|
||||
Printv(f, "#else\n", NIL);
|
||||
Printf(f, " PyObject_HEAD_INIT(NULL)\n");
|
||||
Printf(f, " 0, /*ob_size*/\n");
|
||||
Printv(f, "#endif\n", NIL);
|
||||
Printf(f, " \"%s\", /*tp_name*/\n", symname);
|
||||
Printf(f, " sizeof(SwigPyObject), /*tp_basicsize*/\n", templ);
|
||||
Printf(f, " %s, /*tp_itemsize*/\n", getSlot(n, "feature:tp_itemsize"));
|
||||
|
|
@ -3296,7 +3305,11 @@ public:
|
|||
Printf(f, " %s, /*tp_getattro*/\n", getSlot(n, "feature:tp_getattro"));
|
||||
Printf(f, " %s, /*tp_setattro*/\n", getSlot(n, "feature:tp_setattro"));
|
||||
Printf(f, " &%s_type.as_buffer, /*tp_as_buffer*/\n", templ);
|
||||
Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL);
|
||||
Printf(f, " %s, /*tp_flags*/\n", py3_tp_flags);
|
||||
Printv(f, "#else\n", NIL);
|
||||
Printf(f, " %s, /*tp_flags*/\n", tp_flags);
|
||||
Printv(f, "#endif\n", NIL);
|
||||
Printf(f, " \"%s\", /* tp_doc */\n", rname);
|
||||
Printf(f, " %s, /* tp_traverse */\n", getSlot(n, "feature:tp_traverse"));
|
||||
Printf(f, " %s, /* tp_clear */\n", getSlot(n, "feature:tp_clear"));
|
||||
|
|
@ -3324,7 +3337,9 @@ public:
|
|||
Printf(f, " (binaryfunc) %s, // nb_add;\n", getSlot(n, "feature:nb_add"));
|
||||
Printf(f, " (binaryfunc) %s, // nb_subtract;\n", getSlot(n, "feature:nb_subtract"));
|
||||
Printf(f, " (binaryfunc) %s, // nb_multiply;\n", getSlot(n, "feature:nb_multiply"));
|
||||
Printv(f, "#if PY_VERSION_HEX < 0x03000000\n", NIL);
|
||||
Printf(f, " (binaryfunc) %s, // nb_divide;\n", getSlot(n, "feature:nb_divide"));
|
||||
Printv(f, "#endif\n", NIL);
|
||||
Printf(f, " (binaryfunc) %s, // nb_remainder;\n", getSlot(n, "feature:nb_remainder"));
|
||||
Printf(f, " (binaryfunc) %s, // nb_divmod;\n", getSlot(n, "feature:nb_divmod"));
|
||||
Printf(f, " (ternaryfunc) %s, // nb_power;\n", getSlot(n, "feature:nb_power"));
|
||||
|
|
@ -3338,16 +3353,26 @@ public:
|
|||
Printf(f, " (binaryfunc) %s, // nb_and;\n", getSlot(n, "feature:nb_and"));
|
||||
Printf(f, " (binaryfunc) %s, // nb_xor;\n", getSlot(n, "feature:nb_xor"));
|
||||
Printf(f, " (binaryfunc) %s, // nb_or;\n", getSlot(n, "feature:nb_or"));
|
||||
Printv(f, "#if PY_VERSION_HEX < 0x03000000\n", NIL);
|
||||
Printf(f, " (coercion) %s, // nb_coerce;\n", getSlot(n, "feature:nb_coerce"));
|
||||
Printv(f, "#endif\n", NIL);
|
||||
Printf(f, " (unaryfunc) %s, // nb_int;\n", getSlot(n, "feature:nb_int"));
|
||||
Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL);
|
||||
Printf(f, " (void*) %s, // nb_reserved;\n", getSlot(n, "feature:nb_reserved"));
|
||||
Printv(f, "#else\n", NIL);
|
||||
Printf(f, " (unaryfunc) %s, // nb_long;\n", getSlot(n, "feature:nb_long"));
|
||||
Printv(f, "#endif\n", NIL);
|
||||
Printf(f, " (unaryfunc) %s, // nb_float;\n", getSlot(n, "feature:nb_float"));
|
||||
Printv(f, "#if PY_VERSION_HEX < 0x03000000\n", NIL);
|
||||
Printf(f, " (unaryfunc) %s, // nb_oct;\n", getSlot(n, "feature:nb_oct"));
|
||||
Printf(f, " (unaryfunc) %s, // nb_hex;\n", getSlot(n, "feature:nb_hex"));
|
||||
Printv(f, "#endif\n", NIL);
|
||||
Printf(f, " (binaryfunc) %s, // nb_inplace_add;\n", getSlot(n, "feature:nb_inplace_add"));
|
||||
Printf(f, " (binaryfunc) %s, // nb_inplace_subtract;\n", getSlot(n, "feature:nb_inplace_subtract"));
|
||||
Printf(f, " (binaryfunc) %s, // nb_inplace_multiply;\n", getSlot(n, "feature:nb_inplace_multiply"));
|
||||
Printv(f, "#if PY_VERSION_HEX < 0x03000000\n", NIL);
|
||||
Printf(f, " (binaryfunc) %s, // nb_inplace_divide;\n", getSlot(n, "feature:nb_inplace_divide"));
|
||||
Printv(f, "#endif\n", NIL);
|
||||
Printf(f, " (binaryfunc) %s, // nb_inplace_remainder;\n", getSlot(n, "feature:nb_inplace_remainder"));
|
||||
Printf(f, " (ternaryfunc) %s, // nb_inplace_power;\n", getSlot(n, "feature:nb_inplace_power"));
|
||||
Printf(f, " (binaryfunc) %s, // nb_inplace_lshift;\n", getSlot(n, "feature:nb_inplace_lshift"));
|
||||
|
|
@ -3377,9 +3402,17 @@ public:
|
|||
Printf(f, " (binaryfunc) %s, // sq_concat\n", getSlot(n, "feature:sq_concat"));
|
||||
Printf(f, " (ssizeargfunc) %s, // sq_repeat\n", getSlot(n, "feature:sq_repeat"));
|
||||
Printf(f, " (ssizeargfunc) %s, // sq_item\n", getSlot(n, "feature:sq_item"));
|
||||
Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL);
|
||||
Printf(f, " (void*) %s, // was_sq_slice\n", getSlot(n, "feature:was_sq_slice"));
|
||||
Printv(f, "#else\n", NIL);
|
||||
Printf(f, " (ssizessizeargfunc) %s, // sq_slice\n", getSlot(n, "feature:sq_slice"));
|
||||
Printv(f, "#endif\n", NIL);
|
||||
Printf(f, " (ssizeobjargproc) %s, // sq_ass_item\n", getSlot(n, "feature:sq_ass_item"));
|
||||
Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL);
|
||||
Printf(f, " (void*) %s, // was_sq_ass_slice\n", getSlot(n, "feature:was_sq_ass_slice"));
|
||||
Printv(f, "#else\n", NIL);
|
||||
Printf(f, " (ssizessizeobjargproc) %s, // sq_ass_slice\n", getSlot(n, "feature:sq_ass_slice"));
|
||||
Printv(f, "#endif\n", NIL);
|
||||
Printf(f, " (objobjproc) %s, // sq_contains\n", getSlot(n, "feature:sq_contains"));
|
||||
Printf(f, " (binaryfunc) %s, // sq_inplace_concat\n", getSlot(n, "feature:sq_inplace_concat"));
|
||||
Printf(f, " (ssizeargfunc) %s, // sq_inplace_repeat\n", getSlot(n, "feature:sq_inplace_repeat"));
|
||||
|
|
@ -3387,10 +3420,15 @@ public:
|
|||
|
||||
// PyBufferProcs as_buffer;
|
||||
Printf(f, " {\n");
|
||||
Printv(f, "#if PY_VERSION_HEX >= 0x03000000\n", NIL);
|
||||
Printf(f, " (getbufferproc) %s, // bf_getbuffer\n", getSlot(n, "feature:bf_getbuffer"));
|
||||
Printf(f, " (releasebufferproc) %s, // bf_releasebuffer\n", getSlot(n, "feature:bf_releasebuffer"));
|
||||
Printv(f, "#else\n", NIL);
|
||||
Printf(f, " (readbufferproc) %s, // bf_getreadbuffer\n", getSlot(n, "feature:bf_getreadbuffer"));
|
||||
Printf(f, " (writebufferproc) %s, // bf_getwritebuffer\n", getSlot(n, "feature:bf_getwritebuffer"));
|
||||
Printf(f, " (segcountproc) %s, // bf_getsegcount\n", getSlot(n, "feature:bf_getsegcount"));
|
||||
Printf(f, " (charbufferproc) %s, // bf_getcharbuffer\n", getSlot(n, "feature:bf_getcharbuffer"));
|
||||
Printv(f, "#endif\n", NIL);
|
||||
Printf(f, " },\n");
|
||||
|
||||
// PyObject *ht_name, *ht_slots
|
||||
|
|
@ -3426,7 +3464,11 @@ public:
|
|||
|
||||
Printv(f_init, " if (PyType_Ready(builtin_pytype) < 0) {\n", NIL);
|
||||
Printf(f_init, " PyErr_SetString(PyExc_TypeError, \"Couldn't create type '%s'\");\n", symname);
|
||||
Printv(f_init, "#if PY_VERSION_HEX >= 0x03000000\n", NIL);
|
||||
Printv(f_init, " return NULL;\n", NIL);
|
||||
Printv(f_init, "#else\n", NIL);
|
||||
Printv(f_init, " return;\n", NIL);
|
||||
Printv(f_init, "#endif\n", NIL);
|
||||
Printv(f_init, " }\n", NIL);
|
||||
Printv(f_init, " Py_INCREF(builtin_pytype);\n", NIL);
|
||||
Printf(f_init, " PyModule_AddObject(m, \"%s\", (PyObject*) builtin_pytype);\n", symname);
|
||||
|
|
@ -3441,6 +3483,7 @@ public:
|
|||
Delete(templ);
|
||||
Delete(tp_dealloc);
|
||||
Delete(tp_flags);
|
||||
Delete(py3_tp_flags);
|
||||
Delete(clientdata_klass);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue