From e43d328c6191b66b5e8d2244471bd530ff6ffbe7 Mon Sep 17 00:00:00 2001 From: Stefan Zager Date: Wed, 30 Mar 2011 21:41:59 +0000 Subject: [PATCH] Eliminate -Wformat compiler warning. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12575 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Lib/python/pyrun.swg | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index 2621c4269..4403a73b9 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -1685,6 +1685,7 @@ SWIGRUNTIME int SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { PyTypeObject *tp = obj->ob_type; PyObject *descr; + PyObject *encoded_name; descrsetfunc f; int res; @@ -1714,7 +1715,14 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) { 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); + if (PyString_Check(name)) { + encoded_name = name; + Py_INCREF(name); + } else { + encoded_name = PyUnicode_AsUTF8String(name); + } + PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.200s'", tp->tp_name, PyString_AsString(encoded_name)); + Py_DECREF(encoded_name); } else { res = f(descr, obj, value); }