From 99dc5893d85684ba1a586319a3a06adcfb44c7d0 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 30 Mar 2011 19:17:54 +0000 Subject: [PATCH] Style fixes, and switch %U to %S git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12573 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/builtin.swg | 8 ++--- Lib/python/pyrun.swg | 79 +++++++++++++----------------------------- 2 files changed, 28 insertions(+), 59 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index aa7dbbe89..ffd3fbd1c 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -279,7 +279,7 @@ 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); + PyErr_Format(PyExc_AttributeError, "attribute '%.300S' 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); #endif @@ -293,7 +293,7 @@ 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); + PyErr_Format(PyExc_AttributeError, "attribute '%.300S' 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 @@ -351,13 +351,13 @@ SwigPyObjectType_setattro(PyTypeObject *type, PyObject *name, PyObject *value) { 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); + 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 '%.400U'", type->tp_name, name); + 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 diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 84b552a72..2621c4269 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1448,32 +1448,6 @@ SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) { return ptr ? SwigPyPacked_New((void *) ptr, sz, type) : SWIG_Py_Void(); } -/* -SWIGRUNTIME int -SWIG_Python_NewBuiltinObj(PyObject *self, void *ptr, swig_type_info *type, int flags) { - assert(self); - SwigPyClientData *clientdata = (SwigPyClientData *)(type->clientdata); - assert(clientdata); - assert(clientdata->pytype); - int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0; - SwigPyObject *newobj = (SwigPyObject *)self; - if (newobj->ptr) { - PyObject *next_self = clientdata->pytype->tp_alloc(clientdata->pytype, 0); - while (newobj->next) newobj = (SwigPyObject *)newobj->next; - newobj->next = next_self; - newobj = (SwigPyObject *)next_self; - } - newobj->ptr = ptr; - newobj->own = own; - newobj->ty = type; - newobj->next = 0; -#ifdef SWIGPYTHON_BUILTIN - newobj->dict = 0; -#endif - return 0; -} -*/ - /* -----------------------------------------------------------------------------* * Get type list * -----------------------------------------------------------------------------*/ @@ -1712,7 +1686,7 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { PyTypeObject *tp = obj->ob_type; PyObject *descr; descrsetfunc f; - int res = -1; + int res; #ifdef Py_USING_UNICODE if (PyString_Check(name)) { @@ -1721,40 +1695,35 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { return -1; } else if (!PyUnicode_Check(name)) { #else - if (!PyString_Check(name)) { + if (!PyString_Check(name)) { #endif PyErr_Format(PyExc_TypeError, "attribute name must be string, not '%.200s'", name->ob_type->tp_name); return -1; - } else { + } else { Py_INCREF(name); - } - - if (!tp->tp_dict) { - if (PyType_Ready(tp) < 0) - goto done; - } - - descr = _PyType_Lookup(tp, name); - f = NULL; - if (descr != NULL) - f = descr->ob_type->tp_descr_set; - if (!f) { - PyErr_Format(PyExc_AttributeError, -#ifdef Py_USING_UNICODE - "'%.100s' object has no attribute '%.200U'", -#else - "'%.100s' object has no attribute '%.200S'", -#endif - tp->tp_name, name); - } else { - res = f(descr, obj, value); - } - -done: - Py_DECREF(name); - return res; } + if (!tp->tp_dict) { + if (PyType_Ready(tp) < 0) + goto done; + } + + res = -1; + descr = _PyType_Lookup(tp, name); + f = NULL; + if (descr != NULL) + f = descr->ob_type->tp_descr_set; + if (!f) { + PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200S'", tp->tp_name, name); + } else { + res = f(descr, obj, value); + } + + done: + Py_DECREF(name); + return res; +} + #ifdef __cplusplus #if 0