Unicode fixes for python3.
Added a few more closure types. Guard against operator overloads outside of a class declaration. Incorporate fix for patch #3171793. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12446 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6fa3033971
commit
b5889b8b0f
5 changed files with 83 additions and 46 deletions
|
|
@ -153,6 +153,37 @@ wrapper##_closure (PyObject *a, PyObject *b, PyObject *c) \
|
|||
return result; \
|
||||
}
|
||||
|
||||
#define PYSWIG_REPRFUNC_CLOSURE(wrapper) \
|
||||
SWIGINTERN PyObject* \
|
||||
wrapper##_closure (PyObject *a) \
|
||||
{ \
|
||||
return wrapper(a, NULL); \
|
||||
}
|
||||
|
||||
#define PYSWIG_HASHFUNC_CLOSURE(wrapper) \
|
||||
SWIGINTERN long \
|
||||
wrapper##_closure (PyObject *a) \
|
||||
{ \
|
||||
PyObject *pyresult = wrapper(a, NULL); \
|
||||
if (!pyresult || !PyLong_Check(pyresult)) \
|
||||
return -1; \
|
||||
long result = PyLong_AsLong(pyresult); \
|
||||
Py_DECREF(pyresult); \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define PYSWIG_ITERNEXT_CLOSURE(wrapper) \
|
||||
SWIGINTERN PyObject* \
|
||||
wrapper##_closure (PyObject *a) \
|
||||
{ \
|
||||
PyObject *result = wrapper(a, NULL); \
|
||||
if (result && result == Py_None) { \
|
||||
Py_DECREF(result); \
|
||||
result = NULL; \
|
||||
} \
|
||||
return result; \
|
||||
}
|
||||
|
||||
SWIGRUNTIME int py_builtin_bad_init (PyObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "Cannot create new instances of type '%.300s'", self->ob_type->tp_name);
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@
|
|||
#define PyInt_Check(x) PyLong_Check(x)
|
||||
#define PyInt_AsLong(x) PyLong_AsLong(x)
|
||||
#define PyInt_FromLong(x) PyLong_FromLong(x)
|
||||
#define PyString_Check(name) PyBytes_Check(name)
|
||||
#define PyString_FromString(x) PyUnicode_FromString(x)
|
||||
#define PyString_Format(fmt, args) PyUnicode_Format(fmt, args)
|
||||
#define PyString_AsString(str) PyBytes_AsString(str)
|
||||
#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)
|
||||
|
|
|
|||
|
|
@ -1703,24 +1703,22 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value)
|
|||
descrsetfunc f;
|
||||
int res = -1;
|
||||
|
||||
if (!PyString_Check(name)) {
|
||||
#ifdef Py_USING_UNICODE
|
||||
if (PyUnicode_Check(name)) {
|
||||
name = PyUnicode_AsEncodedString(name, NULL, NULL);
|
||||
if (name == NULL)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
if (PyString_Check(name)) {
|
||||
name = PyUnicode_Decode(PyString_AsString(name), PyBytes_Size(name), NULL, NULL);
|
||||
if (name == NULL)
|
||||
return -1;
|
||||
} else if (!PyUnicode_Check(name)) {
|
||||
#else
|
||||
if (!PyString_Check(name)) {
|
||||
#endif
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"attribute name must be string, not '%.200s'",
|
||||
name->ob_type->tp_name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"attribute name must be string, not '%.200s'",
|
||||
name->ob_type->tp_name);
|
||||
return -1;
|
||||
} else {
|
||||
Py_INCREF(name);
|
||||
}
|
||||
|
||||
if (tp->tp_dict == NULL) {
|
||||
if (PyType_Ready(tp) < 0)
|
||||
|
|
@ -1731,21 +1729,22 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value)
|
|||
f = NULL;
|
||||
if (descr != NULL)
|
||||
f = descr->ob_type->tp_descr_set;
|
||||
if (f == NULL)
|
||||
if (f == NULL) {
|
||||
PyErr_Format(PyExc_AttributeError,
|
||||
#if PY_VERSION_HEX >= 0x03000000
|
||||
#ifdef Py_USING_UNICODE
|
||||
"'%.100s' object has no attribute '%.200U'",
|
||||
#else
|
||||
"'%.100s' object has no attribute '%.200S'",
|
||||
#endif
|
||||
tp->tp_name, name);
|
||||
else
|
||||
} else {
|
||||
res = f(descr, obj, value);
|
||||
|
||||
done:
|
||||
}
|
||||
|
||||
done:
|
||||
Py_DECREF(name);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue