Index: gdb/python/py-cmd.c |
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c |
index aad1ab466cdc3cf7e0f29b6295be14b5c0ba7fc1..d8e375c82ceee8b93030f476f93402eb165c2771 100644 |
--- a/gdb/python/py-cmd.c |
+++ b/gdb/python/py-cmd.c |
@@ -35,7 +35,7 @@ struct cmdpy_completer |
/* Python symbol name. */ |
char *name; |
/* Completion function. */ |
- char **(*completer) (struct cmd_list_element *, char *, char *); |
+ completer_ftype *completer; |
}; |
static struct cmdpy_completer completers[] = |
@@ -206,12 +206,12 @@ cmdpy_function (struct cmd_list_element *command, char *args, int from_tty) |
/* Called by gdb for command completion. */ |
-static char ** |
+static VEC (char_ptr) * |
cmdpy_completer (struct cmd_list_element *command, char *text, 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); |
@@ -253,10 +253,10 @@ cmdpy_completer (struct cmd_list_element *command, char *text, char *word) |
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)) |
{ |
@@ -264,16 +264,15 @@ cmdpy_completer (struct cmd_list_element *command, char *text, char *word) |
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)) |
{ |
@@ -436,7 +435,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw) |
&& cmdtype != class_files && cmdtype != class_support |
&& cmdtype != class_info && cmdtype != class_breakpoint |
&& cmdtype != class_trace && cmdtype != class_obscure |
- && cmdtype != class_maintenance) |
+ && cmdtype != class_maintenance && cmdtype != class_user) |
{ |
PyErr_Format (PyExc_RuntimeError, _("Invalid command class argument.")); |
return -1; |
@@ -578,7 +577,8 @@ gdbpy_initialize_commands (void) |
|| PyModule_AddIntConstant (gdb_module, "COMMAND_OBSCURE", |
class_obscure) < 0 |
|| PyModule_AddIntConstant (gdb_module, "COMMAND_MAINTENANCE", |
- class_maintenance) < 0) |
+ class_maintenance) < 0 |
+ || PyModule_AddIntConstant (gdb_module, "COMMAND_USER", class_user) < 0) |
return; |
for (i = 0; i < N_COMPLETERS; ++i) |