* python/py-arch.c (gdbpy_initialize_arch): Use

gdb_pymodule_addobject.
	* python/py-block.c (gdbpy_initialize_blocks): Use
	gdb_pymodule_addobject.
	* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Use
	gdb_pymodule_addobject.
	* python/py-cmd.c (gdbpy_initialize_breakpoints): Use
	gdb_pymodule_addobject.
	* python/py-event.c (gdbpy_initialize_event_generic): Use
	gdb_pymodule_addobject.
	* python/py-evtregistry.c (gdbpy_initialize_eventregistry): Use
	gdb_pymodule_addobject.
	* python/py-evts.c (add_new_registry): Use
	gdb_pymodule_addobject.
	(gdbpy_initialize_py_events): Likewise.
	* python/py-finishbreakpoint.c
	(gdbpy_initialize_finishbreakpoints): Use
	gdb_pymodule_addobject.
	* python/py-frame.c (gdbpy_initialize_frames): Use
	gdb_pymodule_addobject.
	* python/py-function.c (gdbpy_initialize_functions): Use
	gdb_pymodule_addobject.
	* python/py-inferior.c (gdbpy_initialize_inferior): Use
	gdb_pymodule_addobject.
	* python/py-infthread.c (gdbpy_initialize_thread): Use
	gdb_pymodule_addobject.
	* python/py-objfile.c (gdbpy_initialize_objfile): Use
	gdb_pymodule_addobject.
	* python/py-param.c (gdbpy_initialize_parameters): Use
	gdb_pymodule_addobject.
	* python/py-progspace.c (gdbpy_initialize_pspace): Use
	gdb_pymodule_addobject.
	* python/py-symbol.c (gdbpy_initialize_symbols): Use
	gdb_pymodule_addobject.
	* python/py-symtab.c (gdbpy_initialize_symtabs): Use
	gdb_pymodule_addobject.
	* python/py-type.c (gdbpy_initialize_types): Use
	gdb_pymodule_addobject.
	* python/py-utils.c (gdb_pymodule_addobject): New function.
	* python/py-value.c (gdbpy_initialize_values): Use
	gdb_pymodule_addobject.
	* python/python-internal.h (gdb_pymodule_addobject): Declare.
	* python/python.c (_initialize_python): Use
	gdb_pymodule_addobject.
This commit is contained in:
Tom Tromey 2013-05-20 20:36:19 +00:00
parent 3d4a3c3ea2
commit aa36459a92
23 changed files with 126 additions and 94 deletions

View file

@ -1,3 +1,50 @@
2013-05-20 Tom Tromey <tromey@redhat.com>
* python/py-arch.c (gdbpy_initialize_arch): Use
gdb_pymodule_addobject.
* python/py-block.c (gdbpy_initialize_blocks): Use
gdb_pymodule_addobject.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Use
gdb_pymodule_addobject.
* python/py-cmd.c (gdbpy_initialize_breakpoints): Use
gdb_pymodule_addobject.
* python/py-event.c (gdbpy_initialize_event_generic): Use
gdb_pymodule_addobject.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry): Use
gdb_pymodule_addobject.
* python/py-evts.c (add_new_registry): Use
gdb_pymodule_addobject.
(gdbpy_initialize_py_events): Likewise.
* python/py-finishbreakpoint.c
(gdbpy_initialize_finishbreakpoints): Use
gdb_pymodule_addobject.
* python/py-frame.c (gdbpy_initialize_frames): Use
gdb_pymodule_addobject.
* python/py-function.c (gdbpy_initialize_functions): Use
gdb_pymodule_addobject.
* python/py-inferior.c (gdbpy_initialize_inferior): Use
gdb_pymodule_addobject.
* python/py-infthread.c (gdbpy_initialize_thread): Use
gdb_pymodule_addobject.
* python/py-objfile.c (gdbpy_initialize_objfile): Use
gdb_pymodule_addobject.
* python/py-param.c (gdbpy_initialize_parameters): Use
gdb_pymodule_addobject.
* python/py-progspace.c (gdbpy_initialize_pspace): Use
gdb_pymodule_addobject.
* python/py-symbol.c (gdbpy_initialize_symbols): Use
gdb_pymodule_addobject.
* python/py-symtab.c (gdbpy_initialize_symtabs): Use
gdb_pymodule_addobject.
* python/py-type.c (gdbpy_initialize_types): Use
gdb_pymodule_addobject.
* python/py-utils.c (gdb_pymodule_addobject): New function.
* python/py-value.c (gdbpy_initialize_values): Use
gdb_pymodule_addobject.
* python/python-internal.h (gdb_pymodule_addobject): Declare.
* python/python.c (_initialize_python): Use
gdb_pymodule_addobject.
2013-05-20 Tom Tromey <tromey@redhat.com> 2013-05-20 Tom Tromey <tromey@redhat.com>
* python/py-cmd.c (cmdpy_completer): Use explicit decref. * python/py-cmd.c (cmdpy_completer): Use explicit decref.

View file

@ -239,8 +239,7 @@ gdbpy_initialize_arch (void)
if (PyType_Ready (&arch_object_type) < 0) if (PyType_Ready (&arch_object_type) < 0)
return -1; return -1;
Py_INCREF (&arch_object_type); return gdb_pymodule_addobject (gdb_module, "Architecture",
return PyModule_AddObject (gdb_module, "Architecture",
(PyObject *) &arch_object_type); (PyObject *) &arch_object_type);
} }

View file

@ -442,13 +442,11 @@ gdbpy_initialize_blocks (void)
blpy_objfile_data_key blpy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, del_objfile_blocks); = register_objfile_data_with_cleanup (NULL, del_objfile_blocks);
Py_INCREF (&block_object_type); if (gdb_pymodule_addobject (gdb_module, "Block",
if (PyModule_AddObject (gdb_module, "Block",
(PyObject *) &block_object_type) < 0) (PyObject *) &block_object_type) < 0)
return -1; return -1;
Py_INCREF (&block_syms_iterator_object_type); return gdb_pymodule_addobject (gdb_module, "BlockIterator",
return PyModule_AddObject (gdb_module, "BlockIterator",
(PyObject *) &block_syms_iterator_object_type); (PyObject *) &block_syms_iterator_object_type);
} }

View file

@ -868,8 +868,7 @@ gdbpy_initialize_breakpoints (void)
if (PyType_Ready (&breakpoint_object_type) < 0) if (PyType_Ready (&breakpoint_object_type) < 0)
return -1; return -1;
Py_INCREF (&breakpoint_object_type); if (gdb_pymodule_addobject (gdb_module, "Breakpoint",
if (PyModule_AddObject (gdb_module, "Breakpoint",
(PyObject *) &breakpoint_object_type) < 0) (PyObject *) &breakpoint_object_type) < 0)
return -1; return -1;

View file

@ -600,8 +600,7 @@ gdbpy_initialize_commands (void)
return -1; return -1;
} }
Py_INCREF (&cmdpy_object_type); if (gdb_pymodule_addobject (gdb_module, "Command",
if (PyModule_AddObject (gdb_module, "Command",
(PyObject *) &cmdpy_object_type) < 0) (PyObject *) &cmdpy_object_type) < 0)
return -1; return -1;

View file

@ -78,15 +78,7 @@ gdbpy_initialize_event_generic (PyTypeObject *type,
if (PyType_Ready (type) < 0) if (PyType_Ready (type) < 0)
return -1; return -1;
Py_INCREF (type); return gdb_pymodule_addobject (gdb_module, name, (PyObject *) type);
if (PyModule_AddObject (gdb_module, name, (PyObject *) type) < 0)
goto fail;
return 0;
fail:
Py_XDECREF (type);
return -1;
} }

View file

@ -112,8 +112,7 @@ gdbpy_initialize_eventregistry (void)
if (PyType_Ready (&eventregistry_object_type) < 0) if (PyType_Ready (&eventregistry_object_type) < 0)
return -1; return -1;
Py_INCREF (&eventregistry_object_type); return gdb_pymodule_addobject (gdb_module, "EventRegistry",
return PyModule_AddObject (gdb_module, "EventRegistry",
(PyObject *) &eventregistry_object_type); (PyObject *) &eventregistry_object_type);
} }

View file

@ -40,21 +40,16 @@ static struct PyModuleDef EventModuleDef =
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
add_new_registry (eventregistry_object **registryp, char *name) add_new_registry (eventregistry_object **registryp, char *name)
{ {
int result;
*registryp = create_eventregistry_object (); *registryp = create_eventregistry_object ();
if (*registryp == NULL) if (*registryp == NULL)
goto fail;
if (PyModule_AddObject (gdb_py_events.module,
name,
(PyObject *)(*registryp)) < 0)
goto fail;
return 0;
fail:
Py_XDECREF (*registryp);
return -1; return -1;
return gdb_pymodule_addobject (gdb_py_events.module,
name,
(PyObject *)(*registryp));
} }
int int
@ -81,7 +76,7 @@ gdbpy_initialize_py_events (void)
if (add_new_registry (&gdb_py_events.new_objfile, "new_objfile") < 0) if (add_new_registry (&gdb_py_events.new_objfile, "new_objfile") < 0)
return -1; return -1;
if (PyModule_AddObject (gdb_module, if (gdb_pymodule_addobject (gdb_module,
"events", "events",
(PyObject *) gdb_py_events.module) < 0) (PyObject *) gdb_py_events.module) < 0)
return -1; return -1;

View file

@ -413,8 +413,7 @@ gdbpy_initialize_finishbreakpoints (void)
if (PyType_Ready (&finish_breakpoint_object_type) < 0) if (PyType_Ready (&finish_breakpoint_object_type) < 0)
return -1; return -1;
Py_INCREF (&finish_breakpoint_object_type); if (gdb_pymodule_addobject (gdb_module, "FinishBreakpoint",
if (PyModule_AddObject (gdb_module, "FinishBreakpoint",
(PyObject *) &finish_breakpoint_object_type) < 0) (PyObject *) &finish_breakpoint_object_type) < 0)
return -1; return -1;

View file

@ -638,8 +638,7 @@ gdbpy_initialize_frames (void)
#undef SET #undef SET
#undef FIRST_ERROR #undef FIRST_ERROR
Py_INCREF (&frame_object_type); return gdb_pymodule_addobject (gdb_module, "Frame",
return PyModule_AddObject (gdb_module, "Frame",
(PyObject *) &frame_object_type); (PyObject *) &frame_object_type);
} }

View file

@ -207,8 +207,7 @@ gdbpy_initialize_functions (void)
if (PyType_Ready (&fnpy_object_type) < 0) if (PyType_Ready (&fnpy_object_type) < 0)
return -1; return -1;
Py_INCREF (&fnpy_object_type); return gdb_pymodule_addobject (gdb_module, "Function",
return PyModule_AddObject (gdb_module, "Function",
(PyObject *) &fnpy_object_type); (PyObject *) &fnpy_object_type);
} }

View file

@ -787,8 +787,7 @@ gdbpy_initialize_inferior (void)
if (PyType_Ready (&inferior_object_type) < 0) if (PyType_Ready (&inferior_object_type) < 0)
return -1; return -1;
Py_INCREF (&inferior_object_type); if (gdb_pymodule_addobject (gdb_module, "Inferior",
if (PyModule_AddObject (gdb_module, "Inferior",
(PyObject *) &inferior_object_type) < 0) (PyObject *) &inferior_object_type) < 0)
return -1; return -1;
@ -806,8 +805,7 @@ gdbpy_initialize_inferior (void)
if (PyType_Ready (&membuf_object_type) < 0) if (PyType_Ready (&membuf_object_type) < 0)
return -1; return -1;
Py_INCREF (&membuf_object_type); return gdb_pymodule_addobject (gdb_module, "Membuf", (PyObject *)
return PyModule_AddObject (gdb_module, "Membuf", (PyObject *)
&membuf_object_type); &membuf_object_type);
} }

View file

@ -261,8 +261,7 @@ gdbpy_initialize_thread (void)
if (PyType_Ready (&thread_object_type) < 0) if (PyType_Ready (&thread_object_type) < 0)
return -1; return -1;
Py_INCREF (&thread_object_type); return gdb_pymodule_addobject (gdb_module, "InferiorThread",
return PyModule_AddObject (gdb_module, "InferiorThread",
(PyObject *) &thread_object_type); (PyObject *) &thread_object_type);
} }

View file

@ -307,8 +307,7 @@ gdbpy_initialize_objfile (void)
if (PyType_Ready (&objfile_object_type) < 0) if (PyType_Ready (&objfile_object_type) < 0)
return -1; return -1;
Py_INCREF (&objfile_object_type); return gdb_pymodule_addobject (gdb_module, "Objfile",
return PyModule_AddObject (gdb_module, "Objfile",
(PyObject *) &objfile_object_type); (PyObject *) &objfile_object_type);
} }

View file

@ -774,8 +774,7 @@ gdbpy_initialize_parameters (void)
return -1; return -1;
} }
Py_INCREF (&parmpy_object_type); return gdb_pymodule_addobject (gdb_module, "Parameter",
return PyModule_AddObject (gdb_module, "Parameter",
(PyObject *) &parmpy_object_type); (PyObject *) &parmpy_object_type);
} }

View file

@ -303,8 +303,7 @@ gdbpy_initialize_pspace (void)
if (PyType_Ready (&pspace_object_type) < 0) if (PyType_Ready (&pspace_object_type) < 0)
return -1; return -1;
Py_INCREF (&pspace_object_type); return gdb_pymodule_addobject (gdb_module, "Progspace",
return PyModule_AddObject (gdb_module, "Progspace",
(PyObject *) &pspace_object_type); (PyObject *) &pspace_object_type);
} }

View file

@ -531,8 +531,7 @@ gdbpy_initialize_symbols (void)
TYPES_DOMAIN) < 0) TYPES_DOMAIN) < 0)
return -1; return -1;
Py_INCREF (&symbol_object_type); return gdb_pymodule_addobject (gdb_module, "Symbol",
return PyModule_AddObject (gdb_module, "Symbol",
(PyObject *) &symbol_object_type); (PyObject *) &symbol_object_type);
} }

View file

@ -501,13 +501,11 @@ gdbpy_initialize_symtabs (void)
salpy_objfile_data_key salpy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, del_objfile_sal); = register_objfile_data_with_cleanup (NULL, del_objfile_sal);
Py_INCREF (&symtab_object_type); if (gdb_pymodule_addobject (gdb_module, "Symtab",
if (PyModule_AddObject (gdb_module, "Symtab",
(PyObject *) &symtab_object_type) < 0) (PyObject *) &symtab_object_type) < 0)
return -1; return -1;
Py_INCREF (&sal_object_type); return gdb_pymodule_addobject (gdb_module, "Symtab_and_line",
return PyModule_AddObject (gdb_module, "Symtab_and_line",
(PyObject *) &sal_object_type); (PyObject *) &sal_object_type);
} }

View file

@ -1548,18 +1548,15 @@ gdbpy_initialize_types (void)
return -1; return -1;
} }
Py_INCREF (&type_object_type); if (gdb_pymodule_addobject (gdb_module, "Type",
if (PyModule_AddObject (gdb_module, "Type",
(PyObject *) &type_object_type) < 0) (PyObject *) &type_object_type) < 0)
return -1; return -1;
Py_INCREF (&type_iterator_object_type); if (gdb_pymodule_addobject (gdb_module, "TypeIterator",
if (PyModule_AddObject (gdb_module, "TypeIterator",
(PyObject *) &type_iterator_object_type) < 0) (PyObject *) &type_iterator_object_type) < 0)
return -1; return -1;
Py_INCREF (&field_object_type); return gdb_pymodule_addobject (gdb_module, "Field",
return PyModule_AddObject (gdb_module, "Field",
(PyObject *) &field_object_type); (PyObject *) &field_object_type);
} }

View file

@ -431,3 +431,18 @@ gdb_py_generic_dict (PyObject *self, void *closure)
Py_INCREF (result); Py_INCREF (result);
return 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);
result = PyModule_AddObject (module, name, object);
if (result < 0)
Py_DECREF (object);
return result;
}

View file

@ -1392,8 +1392,7 @@ gdbpy_initialize_values (void)
if (PyType_Ready (&value_object_type) < 0) if (PyType_Ready (&value_object_type) < 0)
return -1; return -1;
Py_INCREF (&value_object_type); return gdb_pymodule_addobject (gdb_module, "Value",
return PyModule_AddObject (gdb_module, "Value",
(PyObject *) &value_object_type); (PyObject *) &value_object_type);
} }

View file

@ -473,4 +473,8 @@ int gdb_py_int_as_long (PyObject *, long *);
PyObject *gdb_py_generic_dict (PyObject *self, void *closure); PyObject *gdb_py_generic_dict (PyObject *self, void *closure);
int gdb_pymodule_addobject (PyObject *module, const char *name,
PyObject *object)
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
#endif /* GDB_PYTHON_INTERNAL_H */ #endif /* GDB_PYTHON_INTERNAL_H */

View file

@ -1639,19 +1639,20 @@ message == an error message without a stack will be printed."),
gdbpy_gdb_error = PyErr_NewException ("gdb.error", PyExc_RuntimeError, NULL); gdbpy_gdb_error = PyErr_NewException ("gdb.error", PyExc_RuntimeError, NULL);
if (gdbpy_gdb_error == NULL if (gdbpy_gdb_error == NULL
|| PyModule_AddObject (gdb_module, "error", gdbpy_gdb_error) < 0) || gdb_pymodule_addobject (gdb_module, "error", gdbpy_gdb_error) < 0)
goto fail; goto fail;
gdbpy_gdb_memory_error = PyErr_NewException ("gdb.MemoryError", gdbpy_gdb_memory_error = PyErr_NewException ("gdb.MemoryError",
gdbpy_gdb_error, NULL); gdbpy_gdb_error, NULL);
if (gdbpy_gdb_memory_error == NULL if (gdbpy_gdb_memory_error == NULL
|| PyModule_AddObject (gdb_module, "MemoryError", || gdb_pymodule_addobject (gdb_module, "MemoryError",
gdbpy_gdb_memory_error) < 0) gdbpy_gdb_memory_error) < 0)
goto fail; goto fail;
gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL); gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL);
if (gdbpy_gdberror_exc == NULL if (gdbpy_gdberror_exc == NULL
|| PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc) < 0) || gdb_pymodule_addobject (gdb_module, "GdbError",
gdbpy_gdberror_exc) < 0)
goto fail; goto fail;
gdbpy_initialize_gdb_readline (); gdbpy_initialize_gdb_readline ();
@ -1798,7 +1799,7 @@ finish_python_initialization (void)
return; return;
} }
if (PyModule_AddObject (m, "gdb", gdb_python_module)) if (gdb_pymodule_addobject (m, "gdb", gdb_python_module) < 0)
goto fail; goto fail;
/* Keep the reference to gdb_python_module since it is in a global /* Keep the reference to gdb_python_module since it is in a global