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
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue