[PATCH 17/28] convert python init functions to do error-checking

Tom Tromey
2013-04-19T14:37:29Z

The checker pointed out that we did not do Python error checking in
any of our module initialization functions. There is no deep reason
for this -- just that it is common in the Python world to work this
way. However, it seems cleaner to me to be correct, and it makes the
checker quieter besides.

This changes nearly all of the Python initialization functions to
return -1 on error.

This also introduces gdb_python_initialized, which is set to a
non-zero value if initialization went properly. A subsequent patch
will use this to disable Python support if initialization failed.

* python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
---
gdb/python/py-arch.c | 8 +--
gdb/python/py-auto-load.c | 4 +-
gdb/python/py-block.c | 14 +++--
gdb/python/py-breakpoint.c | 14 +++--
gdb/python/py-cmd.c | 19 ++++--
gdb/python/py-event.c | 6 +-
gdb/python/py-event.h | 6 +-
gdb/python/py-evtregistry.c | 8 +--
gdb/python/py-evts.c | 19 +++---
gdb/python/py-finishbreakpoint.c | 11 ++--
gdb/python/py-frame.c | 32 ++++++----
gdb/python/py-function.c | 7 ++-
gdb/python/py-gdb-readline.c | 7 +--
gdb/python/py-inferior.c | 15 ++---
gdb/python/py-infthread.c | 8 +--
gdb/python/py-lazy-string.c | 5 +-
gdb/python/py-objfile.c | 8 +--
gdb/python/py-param.c | 14 ++---
gdb/python/py-progspace.c | 8 +--
gdb/python/py-symbol.c | 79 +++++++++++++++----------
gdb/python/py-symtab.c | 15 ++---
gdb/python/py-type.c | 22 ++++---
gdb/python/py-value.c | 9 ++-
gdb/python/python-internal.h | 87 ++++++++++++++++++---------
gdb/python/python.c | 123 ++++++++++++++++++++++++++-------------
25 files changed, 331 insertions(+), 217 deletions(-)

diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 146a642..7920fbb 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -231,17 +231,17 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)

/* Initializes the Architecture class in the gdb module. */

-void
+int
gdbpy_initialize_arch (void)
{
arch_object_data = gdbarch_data_register_post_init (arch_object_data_init);
arch_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&arch_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&arch_object_type);
- PyModule_AddObject (gdb_module, "Architecture",
- (PyObject *) &arch_object_type);
+ return PyModule_AddObject (gdb_module, "Architecture",
+ (PyObject *) &arch_object_type);
}

static PyMethodDef arch_object_methods [] = {
diff --git a/gdb/python/py-auto-load.c b/gdb/python/py-auto-load.c
index 53a8eb5..fa07432 100644
--- a/gdb/python/py-auto-load.c
+++ b/gdb/python/py-auto-load.c
@@ -238,7 +238,7 @@ info_auto_load_python_scripts (char *pattern, int from_tty)
auto_load_info_scripts (pattern, from_tty, &script_language_python);
}
\f
-void
+int
gdbpy_initialize_auto_load (void)
{
struct cmd_list_element *cmd;
@@ -281,6 +281,8 @@ Usage: info auto-load python-scripts [REGEXP]"),
cmd = add_info ("auto-load-scripts", info_auto_load_python_scripts, _("\
Print the list of automatically loaded Python scripts, deprecated."));
deprecate_cmd (cmd, "info auto-load python-scripts");
+
+ return 0;
}

#else /* ! HAVE_PYTHON */
diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c
index afc8959..f2d9000 100644
--- a/gdb/python/py-block.c
+++ b/gdb/python/py-block.c
@@ -425,16 +425,16 @@ del_objfile_blocks (struct objfile *objfile, void *datum)
}
}

-void
+int
gdbpy_initialize_blocks (void)
{
block_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&block_object_type) < 0)
- return;
+ return -1;

block_syms_iterator_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&block_syms_iterator_object_type) < 0)
- return;
+ return -1;

/* Register an objfile "free" callback so we can properly
invalidate blocks when an object file is about to be
@@ -443,11 +443,13 @@ gdbpy_initialize_blocks (void)
= register_objfile_data_with_cleanup (NULL, del_objfile_blocks);

Py_INCREF (&block_object_type);
- PyModule_AddObject (gdb_module, "Block", (PyObject *) &block_object_type);
+ if (PyModule_AddObject (gdb_module, "Block",
+ (PyObject *) &block_object_type) < 0)
+ return -1;

Py_INCREF (&block_syms_iterator_object_type);
- PyModule_AddObject (gdb_module, "BlockIterator",
- (PyObject *) &block_syms_iterator_object_type);
+ return PyModule_AddObject (gdb_module, "BlockIterator",
+ (PyObject *) &block_syms_iterator_object_type);
}

\f
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 5e5f9b3..b1b6e93 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -859,18 +859,19 @@ gdbpy_breakpoint_deleted (struct breakpoint *b)
\f

/* Initialize the Python breakpoint code. */
-void
+int
gdbpy_initialize_breakpoints (void)
{
int i;

breakpoint_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&breakpoint_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&breakpoint_object_type);
- PyModule_AddObject (gdb_module, "Breakpoint",
- (PyObject *) &breakpoint_object_type);
+ if (PyModule_AddObject (gdb_module, "Breakpoint",
+ (PyObject *) &breakpoint_object_type) < 0)
+ return -1;

observer_attach_breakpoint_created (gdbpy_breakpoint_created);
observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
@@ -882,7 +883,7 @@ gdbpy_initialize_breakpoints (void)
/* Cast needed for Python 2.4. */
(char *) pybp_codes[i].name,
pybp_codes[i].code) < 0)
- return;
+ return -1;
}

/* Add watchpoint types constants. */
@@ -892,9 +893,10 @@ gdbpy_initialize_breakpoints (void)
/* Cast needed for Python 2.4. */
(char *) pybp_watch_types[i].name,
pybp_watch_types[i].code) < 0)
- return;
+ return -1;
}

+ return 0;
}

\f
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 26823c7..ba765e0 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -564,14 +564,14 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)

/* Initialize the 'commands' code. */

-void
+int
gdbpy_initialize_commands (void)
{
int i;

cmdpy_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&cmdpy_object_type) < 0)
- return;
+ return -1;

/* Note: alias and user are special; pseudo appears to be unused,
and there is no reason to expose tui or xdb, I think. */
@@ -592,20 +592,27 @@ gdbpy_initialize_commands (void)
|| PyModule_AddIntConstant (gdb_module, "COMMAND_MAINTENANCE",
class_maintenance) < 0
|| PyModule_AddIntConstant (gdb_module, "COMMAND_USER", class_user) < 0)
- return;
+ return -1;

for (i = 0; i < N_COMPLETERS; ++i)
{
if (PyModule_AddIntConstant (gdb_module, completers[i].name, i) < 0)
- return;
+ return -1;
}

Py_INCREF (&cmdpy_object_type);
- PyModule_AddObject (gdb_module, "Command",
- (PyObject *) &cmdpy_object_type);
+ if (PyModule_AddObject (gdb_module, "Command",
+ (PyObject *) &cmdpy_object_type) < 0)
+ return -1;

invoke_cst = PyString_FromString ("invoke");
+ if (invoke_cst == NULL)
+ return -1;
complete_cst = PyString_FromString ("complete");
+ if (complete_cst == NULL)
+ return -1;
+
+ return 0;
}

\f
diff --git a/gdb/python/py-event.c b/gdb/python/py-event.c
index 72d57cb..04f33ab 100644
--- a/gdb/python/py-event.c
+++ b/gdb/python/py-event.c
@@ -60,11 +60,11 @@ evpy_add_attribute (PyObject *event, char *name, PyObject *attr)

/* Initialize the Python event code. */

-void
+int
gdbpy_initialize_event (void)
{
- gdbpy_initialize_event_generic (&event_object_type,
- "Event");
+ return gdbpy_initialize_event_generic (&event_object_type,
+ "Event");
}

/* Initialize the given event type. If BASE is not NULL it will
diff --git a/gdb/python/py-event.h b/gdb/python/py-event.h
index 4850f1a..f0ff629 100644
--- a/gdb/python/py-event.h
+++ b/gdb/python/py-event.h
@@ -88,11 +88,11 @@
0 /* tp_alloc */ \
}; \
\
-void \
+int \
gdbpy_initialize_##name##_event (void) \
{ \
- gdbpy_initialize_event_generic (&name##_event_object_type, \
- py_name); \
+ return gdbpy_initialize_event_generic (&name##_event_object_type, \
+ py_name); \
}

typedef struct
diff --git a/gdb/python/py-evtregistry.c b/gdb/python/py-evtregistry.c
index 05c8586..d7cbe64 100644
--- a/gdb/python/py-evtregistry.c
+++ b/gdb/python/py-evtregistry.c
@@ -106,15 +106,15 @@ evregpy_dealloc (PyObject *self)

/* Initialize the Python event registry code. */

-void
+int
gdbpy_initialize_eventregistry (void)
{
if (PyType_Ready (&eventregistry_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&eventregistry_object_type);
- PyModule_AddObject (gdb_module, "EventRegistry",
- (PyObject *) &eventregistry_object_type);
+ return PyModule_AddObject (gdb_module, "EventRegistry",
+ (PyObject *) &eventregistry_object_type);
}

/* Retern the number of listeners currently connected to this
diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c
index 427b6d5..bb384e3 100644
--- a/gdb/python/py-evts.c
+++ b/gdb/python/py-evts.c
@@ -57,7 +57,7 @@ add_new_registry (eventregistry_object **registryp, char *name)
return -1;
}

-void
+int
gdbpy_initialize_py_events (void)
{
#ifdef IS_PY3K
@@ -67,19 +67,19 @@ gdbpy_initialize_py_events (void)
#endif

if (!gdb_py_events.module)
- goto fail;
+ return -1;

if (add_new_registry (&gdb_py_events.stop, "stop") < 0)
- goto fail;
+ return -1;

if (add_new_registry (&gdb_py_events.cont, "cont") < 0)
- goto fail;
+ return -1;

if (add_new_registry (&gdb_py_events.exited, "exited") < 0)
- goto fail;
+ return -1;

if (add_new_registry (&gdb_py_events.new_objfile, "new_objfile") < 0)
- goto fail;
+ return -1;

#ifndef IS_PY3K
Py_INCREF (gdb_py_events.module);
@@ -87,10 +87,7 @@ gdbpy_initialize_py_events (void)
if (PyModule_AddObject (gdb_module,
"events",
(PyObject *) gdb_py_events.module) < 0)
- goto fail;
-
- return;
+ return -1;

- fail:
- gdbpy_print_stack ();
+ return 0;
}
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index f65e026..5fd1f4b 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -407,18 +407,21 @@ bpfinishpy_handle_exit (struct inferior *inf)

/* Initialize the Python finish breakpoint code. */

-void
+int
gdbpy_initialize_finishbreakpoints (void)
{
if (PyType_Ready (&finish_breakpoint_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&finish_breakpoint_object_type);
- PyModule_AddObject (gdb_module, "FinishBreakpoint",
- (PyObject *) &finish_breakpoint_object_type);
+ if (PyModule_AddObject (gdb_module, "FinishBreakpoint",
+ (PyObject *) &finish_breakpoint_object_type) < 0)
+ return -1;

observer_attach_normal_stop (bpfinishpy_handle_stop);
observer_attach_inferior_exit (bpfinishpy_handle_exit);
+
+ return 0;
}

static PyGetSetDef finish_breakpoint_object_getset[] = {
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index e2eb9c5..75e84ac 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -610,33 +610,41 @@ frapy_richcompare (PyObject *self, PyObject *other, int op)

/* Sets up the Frame API in the gdb module. */

-void
+int
gdbpy_initialize_frames (void)
{
frame_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&frame_object_type) < 0)
- return;
+ return -1;

/* Note: These would probably be best exposed as class attributes of
Frame, but I don't know how to do it except by messing with the
type's dictionary. That seems too messy. */
- PyModule_AddIntConstant (gdb_module, "NORMAL_FRAME", NORMAL_FRAME);
- PyModule_AddIntConstant (gdb_module, "DUMMY_FRAME", DUMMY_FRAME);
- PyModule_AddIntConstant (gdb_module, "INLINE_FRAME", INLINE_FRAME);
- PyModule_AddIntConstant (gdb_module, "TAILCALL_FRAME", TAILCALL_FRAME);
- PyModule_AddIntConstant (gdb_module, "SIGTRAMP_FRAME", SIGTRAMP_FRAME);
- PyModule_AddIntConstant (gdb_module, "ARCH_FRAME", ARCH_FRAME);
- PyModule_AddIntConstant (gdb_module, "SENTINEL_FRAME", SENTINEL_FRAME);
+ if (PyModule_AddIntConstant (gdb_module, "NORMAL_FRAME", NORMAL_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "DUMMY_FRAME", DUMMY_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "INLINE_FRAME", INLINE_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "TAILCALL_FRAME",
+ TAILCALL_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "SIGTRAMP_FRAME",
+ SIGTRAMP_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "ARCH_FRAME", ARCH_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "SENTINEL_FRAME",
+ SENTINEL_FRAME) < 0)
+ return -1;

#define SET(name, description) \
- PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name);
+ if (PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name) < 0) \
+ return -1;
#define FIRST_ERROR(name) \
- PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name);
+ if (PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name) < 0) \
+ return -1;
#include "unwind_stop_reasons.def"
#undef SET
+#undef FIRST_ERROR

Py_INCREF (&frame_object_type);
- PyModule_AddObject (gdb_module, "Frame", (PyObject *) &frame_object_type);
+ return PyModule_AddObject (gdb_module, "Frame",
+ (PyObject *) &frame_object_type);
}

\f
diff --git a/gdb/python/py-function.c b/gdb/python/py-function.c
index 395eeda..57cdfae 100644
--- a/gdb/python/py-function.c
+++ b/gdb/python/py-function.c
@@ -200,15 +200,16 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds)

/* Initialize internal function support. */

-void
+int
gdbpy_initialize_functions (void)
{
fnpy_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&fnpy_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&fnpy_object_type);
- PyModule_AddObject (gdb_module, "Function", (PyObject *) &fnpy_object_type);
+ return PyModule_AddObject (gdb_module, "Function",
+ (PyObject *) &fnpy_object_type);
}

\f
diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c
index ca7e4a6..d6576a3 100644
--- a/gdb/python/py-gdb-readline.c
+++ b/gdb/python/py-gdb-readline.c
@@ -93,7 +93,7 @@ gdbpy_initialize_gdb_readline (void)
and prevent conflicts. For now, this file implements a
sys.meta_path finder that simply fails to import the readline
module. */
- PyRun_SimpleString ("\
+ if (PyRun_SimpleString ("\
import sys\n\
\n\
class GdbRemoveReadlineFinder:\n\
@@ -106,8 +106,7 @@ class GdbRemoveReadlineFinder:\n\
raise ImportError('readline module disabled under GDB')\n\
\n\
sys.meta_path.append(GdbRemoveReadlineFinder())\n\
-");
-
- PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper;
+") == 0)
+ PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper;
}

diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 45b79ce..b11d786 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -762,15 +762,16 @@ gdbpy_selected_inferior (PyObject *self, PyObject *args)
return inf_obj;
}

-void
+int
gdbpy_initialize_inferior (void)
{
if (PyType_Ready (&inferior_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&inferior_object_type);
- PyModule_AddObject (gdb_module, "Inferior",
- (PyObject *) &inferior_object_type);
+ if (PyModule_AddObject (gdb_module, "Inferior",
+ (PyObject *) &inferior_object_type) < 0)
+ return -1;

infpy_inf_data_key =
register_inferior_data_with_cleanup (NULL, py_free_inferior);
@@ -784,11 +785,11 @@ gdbpy_initialize_inferior (void)

membuf_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&membuf_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&membuf_object_type);
- PyModule_AddObject (gdb_module, "Membuf", (PyObject *)
- &membuf_object_type);
+ return PyModule_AddObject (gdb_module, "Membuf", (PyObject *)
+ &membuf_object_type);
}

static PyGetSetDef inferior_object_getset[] =
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index a0545ec..7a5f262 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -255,15 +255,15 @@ gdbpy_selected_thread (PyObject *self, PyObject *args)

-void
+int
gdbpy_initialize_thread (void)
{
if (PyType_Ready (&thread_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&thread_object_type);
- PyModule_AddObject (gdb_module, "InferiorThread",
- (PyObject *) &thread_object_type);
+ return PyModule_AddObject (gdb_module, "InferiorThread",
+ (PyObject *) &thread_object_type);
}

diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index df54cf4..ea193a9 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -160,13 +160,14 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
return (PyObject *) str_obj;
}

-void
+int
gdbpy_initialize_lazy_string (void)
{
if (PyType_Ready (&lazy_string_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&lazy_string_object_type);
+ return 0;
}

/* Determine whether the printer object pointed to by OBJ is a
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index e5e5408..53f8829 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -240,18 +240,18 @@ objfile_to_objfile_object (struct objfile *objfile)
return (PyObject *) object;
}

-void
+int
gdbpy_initialize_objfile (void)
{
objfpy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, py_free_objfile);

if (PyType_Ready (&objfile_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&objfile_object_type);
- PyModule_AddObject (gdb_module, "Objfile",
- (PyObject *) &objfile_object_type);
+ return PyModule_AddObject (gdb_module, "Objfile",
+ (PyObject *) &objfile_object_type);
}

\f
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index 176bbc2..2cc17b6 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -749,33 +749,33 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
\f

/* Initialize the 'parameters' module. */
-void
+int
gdbpy_initialize_parameters (void)
{
int i;

parmpy_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&parmpy_object_type) < 0)
- return;
+ return -1;

set_doc_cst = PyString_FromString ("set_doc");
if (! set_doc_cst)
- return;
+ return -1;
show_doc_cst = PyString_FromString ("show_doc");
if (! show_doc_cst)
- return;
+ return -1;

for (i = 0; parm_constants[i].name; ++i)
{
if (PyModule_AddIntConstant (gdb_module,
parm_constants[i].name,
parm_constants[i].value) < 0)
- return;
+ return -1;
}

Py_INCREF (&parmpy_object_type);
- PyModule_AddObject (gdb_module, "Parameter",
- (PyObject *) &parmpy_object_type);
+ return PyModule_AddObject (gdb_module, "Parameter",
+ (PyObject *) &parmpy_object_type);
}

\f
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index fa9a193..f964fe0 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -236,18 +236,18 @@ pspace_to_pspace_object (struct program_space *pspace)
return (PyObject *) object;
}

-void
+int
gdbpy_initialize_pspace (void)
{
pspy_pspace_data_key
= register_program_space_data_with_cleanup (NULL, py_free_pspace);

if (PyType_Ready (&pspace_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&pspace_object_type);
- PyModule_AddObject (gdb_module, "Progspace",
- (PyObject *) &pspace_object_type);
+ return PyModule_AddObject (gdb_module, "Progspace",
+ (PyObject *) &pspace_object_type);
}

\f
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index def0fdd..7629f70 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -474,11 +474,11 @@ del_objfile_symbols (struct objfile *objfile, void *datum)
}
}

-void
+int
gdbpy_initialize_symbols (void)
{
if (PyType_Ready (&symbol_object_type) < 0)
- return;
+ return -1;

/* Register an objfile "free" callback so we can properly
invalidate symbol when an object file that is about to be
@@ -486,37 +486,54 @@ gdbpy_initialize_symbols (void)
sympy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, del_objfile_symbols);

- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST", LOC_CONST);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC", LOC_STATIC);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER", LOC_REGISTER);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG", LOC_ARG);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG", LOC_REF_ARG);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL", LOC_LOCAL);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF", LOC_TYPEDEF);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL", LOC_LABEL);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK", LOC_BLOCK);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES",
- LOC_CONST_BYTES);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED",
- LOC_UNRESOLVED);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT",
- LOC_OPTIMIZED_OUT);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED", LOC_COMPUTED);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
- LOC_REGPARM_ADDR);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN", UNDEF_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN", VAR_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN", STRUCT_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN", LABEL_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
- VARIABLES_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
- FUNCTIONS_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN", TYPES_DOMAIN);
+ if (PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST",
+ LOC_CONST) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC",
+ LOC_STATIC) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER",
+ LOC_REGISTER) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG",
+ LOC_ARG) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG",
+ LOC_REF_ARG) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL",
+ LOC_LOCAL) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF",
+ LOC_TYPEDEF) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL",
+ LOC_LABEL) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK",
+ LOC_BLOCK) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES",
+ LOC_CONST_BYTES) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED",
+ LOC_UNRESOLVED) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT",
+ LOC_OPTIMIZED_OUT) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED",
+ LOC_COMPUTED) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
+ LOC_REGPARM_ADDR) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN",
+ UNDEF_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN",
+ VAR_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN",
+ STRUCT_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN",
+ LABEL_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
+ VARIABLES_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
+ FUNCTIONS_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN",
+ TYPES_DOMAIN) < 0)
+ return -1;

Py_INCREF (&symbol_object_type);
- PyModule_AddObject (gdb_module, "Symbol", (PyObject *) &symbol_object_type);
+ return PyModule_AddObject (gdb_module, "Symbol",
+ (PyObject *) &symbol_object_type);
}

\f
diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c
index 94c05be..80a2282 100644
--- a/gdb/python/py-symtab.c
+++ b/gdb/python/py-symtab.c
@@ -484,16 +484,16 @@ del_objfile_sal (struct objfile *objfile, void *datum)
}
}

-void
+int
gdbpy_initialize_symtabs (void)
{
symtab_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&symtab_object_type) < 0)
- return;
+ return -1;

sal_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&sal_object_type) < 0)
- return;
+ return -1;

/* Register an objfile "free" callback so we can properly
invalidate symbol tables, and symbol table and line data
@@ -505,12 +505,13 @@ gdbpy_initialize_symtabs (void)
= register_objfile_data_with_cleanup (NULL, del_objfile_sal);

Py_INCREF (&symtab_object_type);
- PyModule_AddObject (gdb_module, "Symtab",
- (PyObject *) &symtab_object_type);
+ if (PyModule_AddObject (gdb_module, "Symtab",
+ (PyObject *) &symtab_object_type) < 0)
+ return -1;

Py_INCREF (&sal_object_type);
- PyModule_AddObject (gdb_module, "Symtab_and_line",
- (PyObject *) &sal_object_type);
+ return PyModule_AddObject (gdb_module, "Symtab_and_line",
+ (PyObject *) &sal_object_type);
}

\f
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index e29ae81..05e251b 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1521,7 +1521,7 @@ gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
return (PyObject *) type_to_type_object (type);
}

-void
+int
gdbpy_initialize_types (void)
{
int i;
@@ -1530,11 +1530,11 @@ gdbpy_initialize_types (void)
= register_objfile_data_with_cleanup (save_objfile_types, NULL);

if (PyType_Ready (&type_object_type) < 0)
- return;
+ return -1;
if (PyType_Ready (&field_object_type) < 0)
- return;
+ return -1;
if (PyType_Ready (&type_iterator_object_type) < 0)
- return;
+ return -1;

for (i = 0; pyty_codes[i].name; ++i)
{
@@ -1542,18 +1542,22 @@ gdbpy_initialize_types (void)
/* Cast needed for Python 2.4. */
(char *) pyty_codes[i].name,
pyty_codes[i].code) < 0)
- return;
+ return -1;
}

Py_INCREF (&type_object_type);
- PyModule_AddObject (gdb_module, "Type", (PyObject *) &type_object_type);
+ if (PyModule_AddObject (gdb_module, "Type",
+ (PyObject *) &type_object_type) < 0)
+ return -1;

Py_INCREF (&type_iterator_object_type);
- PyModule_AddObject (gdb_module, "TypeIterator",
- (PyObject *) &type_iterator_object_type);
+ if (PyModule_AddObject (gdb_module, "TypeIterator",
+ (PyObject *) &type_iterator_object_type) < 0)
+ return -1;

Py_INCREF (&field_object_type);
- PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
+ return PyModule_AddObject (gdb_module, "Field",
+ (PyObject *) &field_object_type);
}

\f
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 11cc038..d8d90c7 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -1385,16 +1385,15 @@ gdbpy_is_value_object (PyObject *obj)
return PyObject_TypeCheck (obj, &value_object_type);
}

-void
+int
gdbpy_initialize_values (void)
{
if (PyType_Ready (&value_object_type) < 0)
- return;
+ return -1;

Py_INCREF (&value_object_type);
- PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
-
- values_in_python = NULL;
+ return PyModule_AddObject (gdb_module, "Value",
+ (PyObject *) &value_object_type);
}

\f
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 5c3fe51..63d020d 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -316,35 +316,64 @@ struct frame_info *frame_object_to_frame_info (PyObject *frame_obj);
struct gdbarch *arch_object_to_gdbarch (PyObject *obj);

void gdbpy_initialize_gdb_readline (void);
-void gdbpy_initialize_auto_load (void);
-void gdbpy_initialize_values (void);
-void gdbpy_initialize_frames (void);
-void gdbpy_initialize_symtabs (void);
-void gdbpy_initialize_commands (void);
-void gdbpy_initialize_symbols (void);
-void gdbpy_initialize_symtabs (void);
-void gdbpy_initialize_blocks (void);
-void gdbpy_initialize_types (void);
-void gdbpy_initialize_functions (void);
-void gdbpy_initialize_pspace (void);
-void gdbpy_initialize_objfile (void);
-void gdbpy_initialize_breakpoints (void);
-void gdbpy_initialize_finishbreakpoints (void);
-void gdbpy_initialize_lazy_string (void);
-void gdbpy_initialize_parameters (void);
-void gdbpy_initialize_thread (void);
-void gdbpy_initialize_inferior (void);
-void gdbpy_initialize_eventregistry (void);
-void gdbpy_initialize_event (void);
-void gdbpy_initialize_py_events (void);
-void gdbpy_initialize_stop_event (void);
-void gdbpy_initialize_signal_event (void);
-void gdbpy_initialize_breakpoint_event (void);
-void gdbpy_initialize_continue_event (void);
-void gdbpy_initialize_exited_event (void);
-void gdbpy_initialize_thread_event (void);
-void gdbpy_initialize_new_objfile_event (void);
-void gdbpy_initialize_arch (void);
+int gdbpy_initialize_auto_load (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_values (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_frames (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_symtabs (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_commands (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_symbols (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_symtabs (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_blocks (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_types (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_functions (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_pspace (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_objfile (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_breakpoints (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_finishbreakpoints (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_lazy_string (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_parameters (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_thread (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_inferior (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_eventregistry (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_py_events (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_stop_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_signal_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_breakpoint_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_continue_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_exited_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_thread_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_new_objfile_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_arch (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;

struct cleanup *make_cleanup_py_decref (PyObject *py);

diff --git a/gdb/python/python.c b/gdb/python/python.c
index 5ef9e0a..51f8cd5 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -73,6 +73,11 @@ static const char *gdbpy_should_print_stack = python_excp_message;
#include "interps.h"
#include "event-top.h"

+/* True if Python has been successfully initialized, false
+ otherwise. */
+
+int gdb_python_initialized;
+
static PyMethodDef GdbMethods[];

#ifdef IS_PY3K
@@ -871,7 +876,7 @@ gdbpy_post_event (PyObject *self, PyObject *args)
}

/* Initialize the Python event handler. */
-static void
+static int
gdbpy_initialize_events (void)
{
if (serial_pipe (gdbpy_event_fds) == 0)
@@ -879,6 +884,8 @@ gdbpy_initialize_events (void)
gdbpy_event_list_end = &gdbpy_event_list;
serial_async (gdbpy_event_fds[0], gdbpy_run_events, NULL);
}
+
+ return 0;
}

\f
@@ -1580,74 +1587,108 @@ message == an error message without a stack will be printed."),
#else
gdb_module = Py_InitModule ("_gdb", GdbMethods);
#endif
+ if (gdb_module == NULL)
+ goto fail;

/* The casts to (char*) are for python 2.4. */
- PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version);
- PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name);
- PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG",
- (char*) target_name);
+ if (PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version) < 0
+ || PyModule_AddStringConstant (gdb_module, "HOST_CONFIG",
+ (char*) host_name) < 0
+ || PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG",
+ (char*) target_name) < 0)
+ goto fail;

/* Add stream constants. */
- PyModule_AddIntConstant (gdb_module, "STDOUT", 0);
- PyModule_AddIntConstant (gdb_module, "STDERR", 1);
- PyModule_AddIntConstant (gdb_module, "STDLOG", 2);
+ if (PyModule_AddIntConstant (gdb_module, "STDOUT", 0) < 0
+ || PyModule_AddIntConstant (gdb_module, "STDERR", 1) < 0
+ || PyModule_AddIntConstant (gdb_module, "STDLOG", 2) < 0)
+ goto fail;

gdbpy_gdb_error = PyErr_NewException ("gdb.error", PyExc_RuntimeError, NULL);
- PyModule_AddObject (gdb_module, "error", gdbpy_gdb_error);
+ if (gdbpy_gdb_error == NULL
+ || PyModule_AddObject (gdb_module, "error", gdbpy_gdb_error) < 0)
+ goto fail;

gdbpy_gdb_memory_error = PyErr_NewException ("gdb.MemoryError",
gdbpy_gdb_error, NULL);
- PyModule_AddObject (gdb_module, "MemoryError", gdbpy_gdb_memory_error);
+ if (gdbpy_gdb_memory_error == NULL
+ || PyModule_AddObject (gdb_module, "MemoryError",
+ gdbpy_gdb_memory_error) < 0)
+ goto fail;

gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL);
- PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc);
+ if (gdbpy_gdberror_exc == NULL
+ || PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc) < 0)
+ goto fail;

gdbpy_initialize_gdb_readline ();
- gdbpy_initialize_auto_load ();
- gdbpy_initialize_values ();
- gdbpy_initialize_frames ();
- gdbpy_initialize_commands ();
- gdbpy_initialize_symbols ();
- gdbpy_initialize_symtabs ();
- gdbpy_initialize_blocks ();
- gdbpy_initialize_functions ();
- gdbpy_initialize_parameters ();
- gdbpy_initialize_types ();
- gdbpy_initialize_pspace ();
- gdbpy_initialize_objfile ();
- gdbpy_initialize_breakpoints ();
- gdbpy_initialize_finishbreakpoints ();
- gdbpy_initialize_lazy_string ();
- gdbpy_initialize_thread ();
- gdbpy_initialize_inferior ();
- gdbpy_initialize_events ();
-
- gdbpy_initialize_eventregistry ();
- gdbpy_initialize_py_events ();
- gdbpy_initialize_event ();
- gdbpy_initialize_stop_event ();
- gdbpy_initialize_signal_event ();
- gdbpy_initialize_breakpoint_event ();
- gdbpy_initialize_continue_event ();
- gdbpy_initialize_exited_event ();
- gdbpy_initialize_thread_event ();
- gdbpy_initialize_new_objfile_event () ;
- gdbpy_initialize_arch ();
+
+ if (gdbpy_initialize_auto_load () < 0
+ || gdbpy_initialize_values () < 0
+ || gdbpy_initialize_frames () < 0
+ || gdbpy_initialize_commands () < 0
+ || gdbpy_initialize_symbols () < 0
+ || gdbpy_initialize_symtabs () < 0
+ || gdbpy_initialize_blocks () < 0
+ || gdbpy_initialize_functions () < 0
+ || gdbpy_initialize_parameters () < 0
+ || gdbpy_initialize_types () < 0
+ || gdbpy_initialize_pspace () < 0
+ || gdbpy_initialize_objfile () < 0
+ || gdbpy_initialize_breakpoints () < 0
+ || gdbpy_initialize_finishbreakpoints () < 0
+ || gdbpy_initialize_lazy_string () < 0
+ || gdbpy_initialize_thread () < 0
+ || gdbpy_initialize_inferior () < 0
+ || gdbpy_initialize_events () < 0
+ || gdbpy_initialize_eventregistry () < 0
+ || gdbpy_initialize_py_events () < 0
+ || gdbpy_initialize_event () < 0
+ || gdbpy_initialize_stop_event () < 0
+ || gdbpy_initialize_signal_event () < 0
+ || gdbpy_initialize_breakpoint_event () < 0
+ || gdbpy_initialize_continue_event () < 0
+ || gdbpy_initialize_exited_event () < 0
+ || gdbpy_initialize_thread_event () < 0
+ || gdbpy_initialize_new_objfile_event () < 0
+ || gdbpy_initialize_arch () < 0)
+ goto fail;

observer_attach_before_prompt (before_prompt_hook);

gdbpy_to_string_cst = PyString_FromString ("to_string");
+ if (gdbpy_to_string_cst == NULL)
+ goto fail;
gdbpy_children_cst = PyString_FromString ("children");
+ if (gdbpy_children_cst == NULL)
+ goto fail;
gdbpy_display_hint_cst = PyString_FromString ("display_hint");
+ if (gdbpy_display_hint_cst == NULL)
+ goto fail;
gdbpy_doc_cst = PyString_FromString ("__doc__");
+ if (gdbpy_doc_cst == NULL)
+ goto fail;
gdbpy_enabled_cst = PyString_FromString ("enabled");
+ if (gdbpy_enabled_cst == NULL)
+ goto fail;
gdbpy_value_cst = PyString_FromString ("value");
+ if (gdbpy_value_cst == NULL)
+ goto fail;

/* Release the GIL while gdb runs. */
PyThreadState_Swap (NULL);
PyEval_ReleaseLock ();

make_final_cleanup (finalize_python, NULL);
+
+ gdb_python_initialized = 1;
+ return;
+
+ fail:
+ gdbpy_print_stack ();
+ /* Do not set 'gdb_python_initialized'. */
+ return;
+
#endif /* HAVE_PYTHON */
}

--
1.8.1.4