Patchwork [review] Use cmd_list_element::doc_allocated for Python commands

login
register
mail settings
Submitter Simon Marchi (Code Review)
Date Nov. 16, 2019, 12:03 a.m.
Message ID <gerrit.1573862632000.I0014edc117b051bba1f4db267687d231e7fe9b56@gnutoolchain-gerrit.osci.io>
Download mbox | patch
Permalink /patch/35965/
State New
Headers show

Comments

Simon Marchi (Code Review) - Nov. 16, 2019, 12:03 a.m.
Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/661
......................................................................

Use cmd_list_element::doc_allocated for Python commands

Python commands manage their "doc" string manually, but
cmd_list_element already has doc_allocated to handle this case.  This
changes the Python code to use the existing facility.

gdb/ChangeLog
2019-11-15  Tom Tromey  <tom@tromey.com>

	* python/py-cmd.c (cmdpy_destroyer): Don't free "doc".
	(cmdpy_init): Set "doc_allocated".

Change-Id: I0014edc117b051bba1f4db267687d231e7fe9b56
---
M gdb/ChangeLog
M gdb/python/py-cmd.c
2 files changed, 6 insertions(+), 1 deletion(-)
Simon Marchi (Code Review) - Nov. 16, 2019, 9:21 a.m.
Andrew Burgess has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/661
......................................................................


Patch Set 1:

(1 comment)

Minor nit but otherwise looks good.

| --- gdb/python/py-cmd.c
| +++ gdb/python/py-cmd.c
| @@ -92,19 +92,18 @@ /* Called if the gdb cmd_list_element is destroyed.  */
|  static void
|  cmdpy_destroyer (struct cmd_list_element *self, void *context)
|  {
|    gdbpy_enter enter_py (get_current_arch (), current_language);
|  
|    /* Release our hold on the command object.  */
|    gdbpy_ref<cmdpy_object> cmd ((cmdpy_object *) context);
|    cmd->command = NULL;
|  
|    /* We allocated the name, doc string, and perhaps the prefix

PS1, Line 101:

Does this comment need updating now?

|       name.  */
|    xfree ((char *) self->name);
| -  xfree ((char *) self->doc);
|    xfree ((char *) self->prefixname);
|  }
|  
|  /* Called by gdb to invoke the command.  */
|  
|  static void
Tom Tromey - Nov. 17, 2019, 1:06 a.m.
>>>>> "Andrew" == Andrew Burgess (Code Review) <gerrit@gnutoolchain-gerrit.osci.io> writes:

Andrew> Does this comment need updating now?

Yeah, though it's updated again in a subsequent patch.

Tom

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 90a2b64..bbef23a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@ 
+2019-11-15  Tom Tromey  <tom@tromey.com>
+
+	* python/py-cmd.c (cmdpy_destroyer): Don't free "doc".
+	(cmdpy_init): Set "doc_allocated".
+
 2019-11-15  Christian Biesinger  <cbiesinger@google.com>
 
 	* Makefile.in: Replace {posix,mingw}-strerror.c with safe-strerror.c.
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 87d1888..5b9a810 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -101,7 +101,6 @@ 
   /* We allocated the name, doc string, and perhaps the prefix
      name.  */
   xfree ((char *) self->name);
-  xfree ((char *) self->doc);
   xfree ((char *) self->prefixname);
 }
 
@@ -563,6 +562,7 @@ 
       /* There appears to be no API to set this.  */
       cmd->func = cmdpy_function;
       cmd->destroyer = cmdpy_destroyer;
+      cmd->doc_allocated = 1;
 
       obj->command = cmd;
       set_cmd_context (cmd, self_ref.release ());