[PATCH 5/7] [python] API for macros: gdb.Objfile symtabs method.

Phil Muldoon pmuldoon@redhat.com
Tue Aug 30 13:08:00 GMT 2011


matt rice <ratmice@gmail.com> writes:

> +  list = PyList_New (0);
> +  if (!list)
> +    return NULL;
> +
> +  symtabs = obj->objfile->symtabs;
> +  while(symtabs)
> +    {
> +      py_symtab = symtab_to_symtab_object (symtabs);
> +      if (! py_symtab)
> +        goto fail;
> +
> +      if (PyList_Append (list, py_symtab) != 0)
> +        goto fail;
> +
> +      Py_DECREF (py_symtab);
> +
> +      symtabs = symtabs->next;
> +    }
> +  return list;

If there are no symtabs, why return an empty list?  Would Py_None make
more sense here.  And same rules apply to returning a Tuple, too, as
others.

> +  { "symtabs", objfpy_symtabs, METH_NOARGS,
> +    "symtabs () -> List.\n\
> +A List containing the object file's valid symtabs." },

See above.
  
> --- /dev/null
> +++ b/gdb/python/py-symtab.h
> @@ -0,0 +1,26 @@
> +/* Python interface to Symtabs and Symtab_and_line's.
> +
> +   Copyright (C) 2011 Free Software Foundation, Inc.
> +
> +   This file is part of GDB.
> +
> +   This program is free software; you can redistribute it and/or modify
> +   it under the terms of the GNU General Public License as published by
> +   the Free Software Foundation; either version 3 of the License, or
> +   (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
> +
> +#ifndef GDB_PY_SYMTAB_H
> +#define GDB_PY_SYMTAB_H
> +
> +PyObject *
> +symtab_to_symtab_object (struct symtab *symtab);
> +
> +#endif /* GDB_PY_SYMTAB_H */

This is already exported in python-internal.h? Why do we need to
re-export it here?

Cheers,

Phil



More information about the Gdb-patches mailing list