* 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>
* python/py-cmd.c (cmdpy_completer): Use explicit decref.

View file

@ -239,9 +239,8 @@ gdbpy_initialize_arch (void)
if (PyType_Ready (&arch_object_type) < 0)
return -1;
Py_INCREF (&arch_object_type);
return PyModule_AddObject (gdb_module, "Architecture",
(PyObject *) &arch_object_type);
return gdb_pymodule_addobject (gdb_module, "Architecture",
(PyObject *) &arch_object_type);
}
static PyMethodDef arch_object_methods [] = {

View file

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

View file

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

View file

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

View file

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

View file

@ -112,9 +112,8 @@ gdbpy_initialize_eventregistry (void)
if (PyType_Ready (&eventregistry_object_type) < 0)
return -1;
Py_INCREF (&eventregistry_object_type);
return PyModule_AddObject (gdb_module, "EventRegistry",
(PyObject *) &eventregistry_object_type);
return gdb_pymodule_addobject (gdb_module, "EventRegistry",
(PyObject *) &eventregistry_object_type);
}
/* Retern the number of listeners currently connected to this

View file

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

View file

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

View file

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

View file

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

View file

@ -787,9 +787,8 @@ gdbpy_initialize_inferior (void)
if (PyType_Ready (&inferior_object_type) < 0)
return -1;
Py_INCREF (&inferior_object_type);
if (PyModule_AddObject (gdb_module, "Inferior",
(PyObject *) &inferior_object_type) < 0)
if (gdb_pymodule_addobject (gdb_module, "Inferior",
(PyObject *) &inferior_object_type) < 0)
return -1;
infpy_inf_data_key =
@ -806,9 +805,8 @@ gdbpy_initialize_inferior (void)
if (PyType_Ready (&membuf_object_type) < 0)
return -1;
Py_INCREF (&membuf_object_type);
return PyModule_AddObject (gdb_module, "Membuf", (PyObject *)
&membuf_object_type);
return gdb_pymodule_addobject (gdb_module, "Membuf", (PyObject *)
&membuf_object_type);
}
static PyGetSetDef inferior_object_getset[] =

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1392,9 +1392,8 @@ gdbpy_initialize_values (void)
if (PyType_Ready (&value_object_type) < 0)
return -1;
Py_INCREF (&value_object_type);
return PyModule_AddObject (gdb_module, "Value",
(PyObject *) &value_object_type);
return gdb_pymodule_addobject (gdb_module, "Value",
(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);
int gdb_pymodule_addobject (PyObject *module, const char *name,
PyObject *object)
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
#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);
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;
gdbpy_gdb_memory_error = PyErr_NewException ("gdb.MemoryError",
gdbpy_gdb_error, NULL);
if (gdbpy_gdb_memory_error == NULL
|| PyModule_AddObject (gdb_module, "MemoryError",
gdbpy_gdb_memory_error) < 0)
|| gdb_pymodule_addobject (gdb_module, "MemoryError",
gdbpy_gdb_memory_error) < 0)
goto fail;
gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, 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;
gdbpy_initialize_gdb_readline ();
@ -1798,7 +1799,7 @@ finish_python_initialization (void)
return;
}
if (PyModule_AddObject (m, "gdb", gdb_python_module))
if (gdb_pymodule_addobject (m, "gdb", gdb_python_module) < 0)
goto fail;
/* Keep the reference to gdb_python_module since it is in a global