don't let bin2hex call strlen
[deliverable/binutils-gdb.git] / gdb / python / py-utils.c
index eac161f2b486dec7d60f47885c756c2d531e071e..deca3e83cb5b7b6f42fc57e3b46db266b0c71798 100644 (file)
@@ -1,6 +1,6 @@
 /* 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.
 
@@ -31,12 +31,7 @@ py_decref (void *p)
 {
   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
@@ -76,7 +71,7 @@ make_cleanup_py_xdecref (PyObject *py)
 
    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
@@ -221,7 +216,7 @@ python_string_to_host_string (PyObject *obj)
   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;
 }
@@ -293,7 +288,7 @@ gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue)
 }
 
 /* Convert a GDB exception to the appropriate Python exception.
-   
+
    This sets the Python error indicator.  */
 
 void
@@ -431,3 +426,19 @@ gdb_py_generic_dict (PyObject *self, void *closure)
   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;
+}
This page took 0.037088 seconds and 4 git commands to generate.