/* General utility routines for GDB/Python.
- Copyright (C) 2008-2013 Free Software Foundation, Inc.
+ Copyright (C) 2008-2014 Free Software Foundation, Inc.
This file is part of GDB.
{
PyObject *py = p;
- /* Note that we need the extra braces in this 'if' to avoid a
- warning from gcc. */
- if (py)
- {
- Py_DECREF (py);
- }
+ Py_DECREF (py);
}
/* Return a new cleanup which will decrement the Python object's
As an added bonus, the functions accepts a unicode string and returns it
right away, so callers don't need to check which kind of string they've
- got. In Python 3, all strings are Unicode so this case is always the
+ got. In Python 3, all strings are Unicode so this case is always the
one that applies.
If the given object is not one of the mentioned string types, NULL is
if (str == NULL)
return NULL;
- result = unicode_to_encoded_string (str, host_charset ());
+ result = unicode_to_encoded_string (str, host_charset ());
Py_DECREF (str);
return result;
}
}
/* Convert a GDB exception to the appropriate Python exception.
-
+
This sets the Python error indicator. */
void
Py_INCREF (result);
return result;
}
+
+/* Like PyModule_AddObject, but does not steal a reference to
+ OBJECT. */
+
+int
+gdb_pymodule_addobject (PyObject *module, const char *name, PyObject *object)
+{
+ int result;
+
+ Py_INCREF (object);
+ /* Python 2.4 did not have a 'const' here. */
+ result = PyModule_AddObject (module, (char *) name, object);
+ if (result < 0)
+ Py_DECREF (object);
+ return result;
+}