PyVarObject_HEAD_INIT to conform to C standard - pointers cannot be used in static initializers

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12661 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2011-05-12 21:07:57 +00:00
commit 1aa65e2220

View file

@ -336,7 +336,39 @@ SwigPyStaticVar_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value)
return -1; return -1;
} }
SWIGINTERN PyTypeObject SwigPyStaticVar_Type = { SWIGINTERN int
SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) {
PyObject *attribute;
descrsetfunc local_set;
attribute = _PyType_Lookup(type, name);
if (attribute != NULL) {
/* Implement descriptor functionality, if any */
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.%.400S'", 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 '%.400S'", 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;
}
SWIGINTERN PyTypeObject*
SwigPyStaticVar_Type(void) {
static PyTypeObject staticvar_type;
static int type_init = 0;
if (!type_init) {
const PyTypeObject tmp = {
/* PyObject header changed in Python 3 */
#if PY_VERSION_HEX >= 0x03000000 #if PY_VERSION_HEX >= 0x03000000
PyVarObject_HEAD_INIT(&PyType_Type, 0) PyVarObject_HEAD_INIT(&PyType_Type, 0)
#else #else
@ -396,38 +428,24 @@ SWIGINTERN PyTypeObject SwigPyStaticVar_Type = {
#ifdef COUNT_ALLOCS #ifdef COUNT_ALLOCS
0,0,0,0 /* tp_alloc -> tp_next */ 0,0,0,0 /* tp_alloc -> tp_next */
#endif #endif
}; };
staticvar_type = tmp;
SWIGINTERN int type_init = 1;
SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) { #if PY_VERSION_HEX < 0x02020000
PyObject *attribute; staticvar_type.ob_type = &PyType_Type;
descrsetfunc local_set;
attribute = _PyType_Lookup(type, name);
if (attribute != NULL) {
/* Implement descriptor functionality, if any */
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.%.400S'", type->tp_name, name);
#else #else
PyErr_Format(PyExc_AttributeError, "cannot modify read-only attribute '%.50s.%.400s'", type->tp_name, PyString_AS_STRING(name)); if (PyType_Ready(&staticvar_type) < 0)
#endif return NULL;
} else {
#if PY_VERSION_HEX >= 0x03000000
PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400S'", type->tp_name, name);
#else
PyErr_Format(PyExc_AttributeError, "type '%.50s' has no attribute '%.400s'", type->tp_name, PyString_AS_STRING(name));
#endif #endif
} }
return &staticvar_type;
return -1;
} }
SWIGINTERN PyGetSetDescrObject * SWIGINTERN PyGetSetDescrObject *
SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) { SwigPyStaticVar_new_getset(PyTypeObject *type, PyGetSetDef *getset) {
PyGetSetDescrObject *descr; PyGetSetDescrObject *descr;
descr = (PyGetSetDescrObject *)PyType_GenericAlloc(&SwigPyStaticVar_Type, 0); descr = (PyGetSetDescrObject *)PyType_GenericAlloc(SwigPyStaticVar_Type(), 0);
assert(descr); assert(descr);
Py_XINCREF(type); Py_XINCREF(type);
PyDescr_TYPE(descr) = type; PyDescr_TYPE(descr) = type;