/* gdb commands implemented in Python
- Copyright (C) 2008-2012 Free Software Foundation, Inc.
+ Copyright (C) 2008-2013 Free Software Foundation, Inc.
This file is part of GDB.
typedef struct cmdpy_object cmdpy_object;
-static PyTypeObject cmdpy_object_type;
+static PyTypeObject cmdpy_object_type
+ CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("cmdpy_object");
/* Constants used by this module. */
static PyObject *invoke_cst;
/* We allocated the name, doc string, and perhaps the prefix
name. */
- xfree (self->name);
+ xfree ((char *) self->name);
xfree (self->doc);
xfree (self->prefixname);
/* Called by gdb for command completion. */
-static char **
-cmdpy_completer (struct cmd_list_element *command, char *text, char *word)
+static VEC (char_ptr) *
+cmdpy_completer (struct cmd_list_element *command,
+ const char *text, const char *word)
{
cmdpy_object *obj = (cmdpy_object *) get_cmd_context (command);
PyObject *textobj, *wordobj, *resultobj = NULL;
- char **result = NULL;
+ VEC (char_ptr) *result = NULL;
struct cleanup *cleanup;
cleanup = ensure_python_env (get_current_arch (), current_language);
if (len < 0)
goto done;
- result = (char **) xmalloc ((len + 1) * sizeof (char *));
for (i = out = 0; i < len; ++i)
{
PyObject *elt = PySequence_GetItem (resultobj, i);
+ char *item;
if (elt == NULL || ! gdbpy_is_string (elt))
{
PyErr_Clear ();
continue;
}
- result[out] = python_string_to_host_string (elt);
- if (result[out] == NULL)
+ item = python_string_to_host_string (elt);
+ if (item == NULL)
{
/* Skip problem elements. */
PyErr_Clear ();
continue;
}
- ++out;
+ VEC_safe_push (char_ptr, result, item);
}
- result[out] = NULL;
}
else if (PyInt_Check (resultobj))
{
struct cmd_list_element *elt;
int len = strlen (name);
int i, lastchar;
- char *prefix_text, *prefix_text2;
+ char *prefix_text;
+ const char *prefix_text2;
char *result;
/* Skip trailing whitespace. */
{
xfree (cmd_name);
xfree (pfx_name);
+ Py_DECREF (ds_obj);
return -1;
}
}
+
+ Py_XDECREF (ds_obj);
}
if (! docstring)
docstring = xstrdup (_("This command is not documented."));
static PyTypeObject cmdpy_object_type =
{
- PyObject_HEAD_INIT (NULL)
- 0, /*ob_size*/
+ PyVarObject_HEAD_INIT (NULL, 0)
"gdb.Command", /*tp_name*/
sizeof (cmdpy_object), /*tp_basicsize*/
0, /*tp_itemsize*/
return NULL;
py_argv = PyList_New (0);
+ if (py_argv == NULL)
+ return NULL;
/* buildargv uses NULL to represent an empty argument list, but we can't use
that in Python. Instead, if ARGS is "" then return an empty list.