diff options
author | Tom Tromey <tromey@adacore.com> | 2022-06-03 07:59:49 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2022-07-05 10:28:39 -0600 |
commit | 3acd9a692ddaf8f24d6d34cb5ccb7c26d057e9b3 (patch) | |
tree | 19216ecf8b1235823b9251f84710982be599e5f8 /gdb/python/py-evts.c | |
parent | 736918239b16cc2ff57bfc64a982f2f0afc8c0f6 (diff) | |
download | binutils-3acd9a692ddaf8f24d6d34cb5ccb7c26d057e9b3.zip binutils-3acd9a692ddaf8f24d6d34cb5ccb7c26d057e9b3.tar.gz binutils-3acd9a692ddaf8f24d6d34cb5ccb7c26d057e9b3.tar.bz2 |
Make 'import gdb.events' work
Pierre-Marie noticed that, while gdb.events is a Python module, it
can't be imported. This patch changes how this module is created, so
that it can be imported, while also ensuring that the module is always
visible, just as it was in the past.
This new approach required one non-obvious change -- when running
gdb.base/warning.exp, where --data-directory is intentionally not
found, the event registries can now be nullptr. Consequently, this
patch probably also requires
https://sourceware.org/pipermail/gdb-patches/2022-June/189796.html
Note that this patch obsoletes
https://sourceware.org/pipermail/gdb-patches/2022-June/189797.html
Diffstat (limited to 'gdb/python/py-evts.c')
-rw-r--r-- | gdb/python/py-evts.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/gdb/python/py-evts.c b/gdb/python/py-evts.c index 23a5d75..ca9326a 100644 --- a/gdb/python/py-evts.c +++ b/gdb/python/py-evts.c @@ -23,7 +23,7 @@ static struct PyModuleDef EventModuleDef = { PyModuleDef_HEAD_INIT, - "gdb.events", + "_gdbevents", NULL, -1, NULL, @@ -33,7 +33,8 @@ static struct PyModuleDef EventModuleDef = NULL }; -/* Initialize python events. */ +/* Helper function to add a single event registry to the events + module. */ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION add_new_registry (eventregistry_object **registryp, const char *name) @@ -48,24 +49,21 @@ add_new_registry (eventregistry_object **registryp, const char *name) (PyObject *)(*registryp)); } -int -gdbpy_initialize_py_events (void) +/* Create and populate the _gdbevents module. Note that this is + always created, see the base gdb __init__.py. */ + +PyMODINIT_FUNC +gdbpy_events_mod_func () { gdb_py_events.module = PyModule_Create (&EventModuleDef); + if (gdb_py_events.module == nullptr) + return nullptr; - if (!gdb_py_events.module) - return -1; - -#define GDB_PY_DEFINE_EVENT(name) \ +#define GDB_PY_DEFINE_EVENT(name) \ if (add_new_registry (&gdb_py_events.name, #name) < 0) \ - return -1; + return nullptr; #include "py-all-events.def" #undef GDB_PY_DEFINE_EVENT - if (gdb_pymodule_addobject (gdb_module, - "events", - (PyObject *) gdb_py_events.module) < 0) - return -1; - - return 0; + return gdb_py_events.module; } |