diff options
| author | Matthieu Longo <matthieu.longo@arm.com> | 2026-02-27 10:28:34 +0000 |
|---|---|---|
| committer | Matthieu Longo <matthieu.longo@arm.com> | 2026-03-09 13:09:18 +0000 |
| commit | 83d7283c4b1ec7904120faec04f4a7ee96b898df (patch) | |
| tree | dbd907a315ad809993c5ce754b7380619176b2bb /gdb/python | |
| parent | 072ea1fa0d39ea0110722385f37415ab6352315d (diff) | |
| download | binutils-83d7283c4b1ec7904120faec04f4a7ee96b898df.tar.gz binutils-83d7283c4b1ec7904120faec04f4a7ee96b898df.tar.bz2 binutils-83d7283c4b1ec7904120faec04f4a7ee96b898df.zip | |
gdb/python: accept gdbpy_ref in init helpers and return bool
Passing 'gdbpy_ref<> &' instead of raw 'PyObject *' to init helpers
makes ownership of PyObject clearer at call sites, and removes
unnecessary '.get()' calls.
Changing the return type from 'int' to 'bool' improves readability
and better expresses the success/failure semantics.
Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/python')
| -rw-r--r-- | gdb/python/py-objfile.c | 27 | ||||
| -rw-r--r-- | gdb/python/py-progspace.c | 22 |
2 files changed, 23 insertions, 26 deletions
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 5d7cfe83ec2..bbe21d32549 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -198,36 +198,36 @@ objfpy_dealloc (PyObject *o) /* Initialize an objfile_object. The result is a boolean indicating success. */ -static int -objfpy_initialize (objfile_object *self) +static bool +objfpy_initialize (gdbpy_ref<objfile_object> &self) { self->objfile = NULL; self->dict = PyDict_New (); if (self->dict == NULL) - return 0; + return false; self->printers = PyList_New (0); if (self->printers == NULL) - return 0; + return false; self->frame_filters = PyDict_New (); if (self->frame_filters == NULL) - return 0; + return false; self->frame_unwinders = PyList_New (0); if (self->frame_unwinders == NULL) - return 0; + return false; self->type_printers = PyList_New (0); if (self->type_printers == NULL) - return 0; + return false; self->xmethods = PyList_New (0); if (self->xmethods == NULL) - return 0; + return false; - return 1; + return true; } static PyObject * @@ -235,11 +235,8 @@ objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords) { gdbpy_ref<objfile_object> self ((objfile_object *) type->tp_alloc (type, 0)); - if (self != NULL) - { - if (!objfpy_initialize (self.get ())) - return NULL; - } + if (self != nullptr && !objfpy_initialize (self)) + return nullptr; return (PyObject *) self.release (); } @@ -682,7 +679,7 @@ objfile_to_objfile_object (struct objfile *objfile) ((objfile_object *) PyObject_New (objfile_object, &objfile_object_type)); if (object == NULL) return NULL; - if (!objfpy_initialize (object.get ())) + if (!objfpy_initialize (object)) return NULL; object->objfile = objfile; diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index baab3be5ee6..5a23c4c7177 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -166,40 +166,40 @@ pspy_dealloc (PyObject *self) /* Initialize a pspace_object. The result is a boolean indicating success. */ -static int -pspy_initialize (pspace_object *self) +static bool +pspy_initialize (gdbpy_ref<pspace_object> &self) { self->pspace = NULL; self->dict = PyDict_New (); if (self->dict == NULL) - return 0; + return false; self->printers = PyList_New (0); if (self->printers == NULL) - return 0; + return false; self->frame_filters = PyDict_New (); if (self->frame_filters == NULL) - return 0; + return false; self->frame_unwinders = PyList_New (0); if (self->frame_unwinders == NULL) - return 0; + return false; self->type_printers = PyList_New (0); if (self->type_printers == NULL) - return 0; + return false; self->xmethods = PyList_New (0); if (self->xmethods == NULL) - return 0; + return false; self->missing_file_handlers = PyList_New (0); if (self->missing_file_handlers == nullptr) - return 0; + return false; - return 1; + return true; } PyObject * @@ -591,7 +591,7 @@ pspace_to_pspace_object (struct program_space *pspace) ((pspace_object *) PyObject_New (pspace_object, &pspace_object_type)); if (object == NULL) return NULL; - if (!pspy_initialize (object.get ())) + if (!pspy_initialize (object)) return NULL; object->pspace = pspace; |
