This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 4/7] [python] API for macros: Add methods to get a gdb.Macro.
matt rice <ratmice@gmail.com> writes:
> +{
> + struct symtab *st = symtab_object_to_symtab (self);
STPY_REQUIRE_VALID will do this for you.
>
> @@ -242,6 +274,75 @@ salpy_is_valid (PyObject *self, PyObject *args)
> Py_RETURN_TRUE;
> }
>
> +static PyObject *
> +salpy_macros (PyObject *self, PyObject *args)
> +{
> + struct symtab_and_line *sal;
> + PyObject *result;
> + enum macro_walk_result walk_result;
> + struct macropy_user_data mud;
> + struct macro_scope *ms;
> +
> + SALPY_REQUIRE_VALID (self, sal);
> +
> + ms = sal_macro_scope (*sal);
This can return NULL.
> + result = PyList_New (0);
> + if (result == NULL)
> + return NULL;
> +
> + mud.list = result;
> + mud.objfile = macro_table_objfile (ms->file->table);
> + walk_result = macro_for_each_in_scope (ms->file, ms->line,
> + pymacro_add_macro_to_list, &mud);
So you need to check ms before you call this ^^ code.
> @@ -477,6 +578,9 @@ Return true if this symbol table is valid, false if not." },
> { "fullname", stpy_fullname, METH_NOARGS,
> "fullname () -> String.\n\
> Return the symtab's full source filename." },
> + { "macros", stpy_macros, METH_NOARGS,
> + "macros () -> List.\n\
> +Return a list of macros in the symtab." },
I think this should return a Tuple. Tuples are immutable, and unless
you for see a use for the user to manipulate the List, we should guard
against it. If you agree, please alter stpy_macros too.
> +macro cannot be found." },
> + { "macros", salpy_macros, METH_NOARGS,
> + "macros () -> List.\n\
> +Return all the macros which are available at the symbol table and line \
> +object's location." },
See above.