From patchwork Sat Nov 12 21:28:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 17434 Received: (qmail 68151 invoked by alias); 12 Nov 2016 21:36:33 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 68140 invoked by uid 89); 12 Nov 2016 21:36:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=sk:pypret, sk:py-pret X-HELO: gproxy1.mail.unifiedlayer.com Received: from gproxy1-pub.mail.unifiedlayer.com (HELO gproxy1.mail.unifiedlayer.com) (69.89.25.95) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 12 Nov 2016 21:36:22 +0000 Received: from cmgw3 (cmgw4 [10.0.90.84]) by gproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id 604BE17AAEA for ; Sat, 12 Nov 2016 14:28:55 -0700 (MST) Received: from box522.bluehost.com ([74.220.219.122]) by cmgw3 with id 79Us1u00Q2f2jeq019UvaX; Sat, 12 Nov 2016 14:28:55 -0700 X-Authority-Analysis: v=2.1 cv=WL/sABcR c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=L24OOQBejmoA:10 a=zstS-IiYAAAA:8 a=LPq2EQyFK1umG6roAf0A:9 a=ZbFNLRhRq0h7tlm7:21 a=EGtdU1AOgwx6maFX:21 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 97-118-168-190.hlrn.qwest.net ([97.118.168.190]:47378 helo=bapiya.localdomain) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.86_1) (envelope-from ) id 1c5fr1-0006jl-Uv; Sat, 12 Nov 2016 14:28:52 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 06/11] Change type of encoding argument to gdbpy_extract_lazy_string Date: Sat, 12 Nov 2016 14:28:40 -0700 Message-Id: <1478986125-15122-7-git-send-email-tom@tromey.com> In-Reply-To: <1478986125-15122-1-git-send-email-tom@tromey.com> References: <1478986125-15122-1-git-send-email-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1c5fr1-0006jl-Uv X-Source-Sender: 97-118-168-190.hlrn.qwest.net (bapiya.localdomain) [97.118.168.190]:47378 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== This changes gdbpy_extract_lazy_string's "encoding" argument to be a unique_xmalloc_ptr. I chose this rather than std::string because it can sometimes be NULL. 2016-11-12 Tom Tromey * python/py-prettyprint.c (print_string_repr, print_children): Update. * python/py-lazy-string.c (gdbpy_extract_lazy_string): Change type of "encoding". * varobj.c (varobj_value_get_print_value): Update. * python/python-internal.h (gdbpy_extract_lazy_string): Update. --- gdb/ChangeLog | 9 +++++++++ gdb/python/py-lazy-string.c | 9 ++++----- gdb/python/py-prettyprint.c | 10 ++++------ gdb/python/python-internal.h | 3 ++- gdb/varobj.c | 7 +++---- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 778b267..db5e029 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2016-11-12 Tom Tromey + * python/py-prettyprint.c (print_string_repr, print_children): + Update. + * python/py-lazy-string.c (gdbpy_extract_lazy_string): Change type + of "encoding". + * varobj.c (varobj_value_get_print_value): Update. + * python/python-internal.h (gdbpy_extract_lazy_string): Update. + +2016-11-12 Tom Tromey + * varobj.c (varobj_get_display_hint) (dynamic_varobj_has_child_method, install_new_value_visualizer) (varobj_set_visualizer, free_variable): Use diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c index d4b40df..74515ae 100644 --- a/gdb/python/py-lazy-string.c +++ b/gdb/python/py-lazy-string.c @@ -180,14 +180,13 @@ gdbpy_is_lazy_string (PyObject *result) } /* Extract the parameters from the lazy string object STRING. - ENCODING will either be set to NULL, or will be allocated with - xmalloc, in which case the callers is responsible for freeing - it. */ + ENCODING may be set to NULL, if no encoding is found. */ void gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr, struct type **str_type, - long *length, char **encoding) + long *length, + gdb::unique_xmalloc_ptr *encoding) { lazy_string_object *lazy; @@ -198,7 +197,7 @@ gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr, *addr = lazy->address; *str_type = lazy->type; *length = lazy->length; - *encoding = lazy->encoding ? xstrdup (lazy->encoding) : NULL; + encoding->reset (lazy->encoding ? xstrdup (lazy->encoding) : NULL); } diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c index 5f11397..e7a3e76 100644 --- a/gdb/python/py-prettyprint.c +++ b/gdb/python/py-prettyprint.c @@ -301,15 +301,14 @@ print_string_repr (PyObject *printer, const char *hint, CORE_ADDR addr; long length; struct type *type; - char *encoding = NULL; + gdb::unique_xmalloc_ptr encoding; struct value_print_options local_opts = *options; - make_cleanup (free_current_contents, &encoding); gdbpy_extract_lazy_string (py_str, &addr, &type, &length, &encoding); local_opts.addressprint = 0; - val_print_string (type, encoding, addr, (int) length, + val_print_string (type, encoding.get (), addr, (int) length, stream, &local_opts); } else @@ -610,14 +609,13 @@ print_children (PyObject *printer, const char *hint, CORE_ADDR addr; struct type *type; long length; - char *encoding = NULL; + gdb::unique_xmalloc_ptr encoding; struct value_print_options local_opts = *options; - make_cleanup (free_current_contents, &encoding); gdbpy_extract_lazy_string (py_v, &addr, &type, &length, &encoding); local_opts.addressprint = 0; - val_print_string (type, encoding, addr, (int) length, stream, + val_print_string (type, encoding.get (), addr, (int) length, stream, &local_opts); } else if (gdbpy_is_string (py_v)) diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index caab6af..d167251 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -580,7 +580,8 @@ gdb::unique_xmalloc_ptr gdbpy_exception_to_string (PyObject *ptype, int gdbpy_is_lazy_string (PyObject *result); void gdbpy_extract_lazy_string (PyObject *string, CORE_ADDR *addr, struct type **str_type, - long *length, char **encoding); + long *length, + gdb::unique_xmalloc_ptr *encoding); int gdbpy_is_value_object (PyObject *obj); diff --git a/gdb/varobj.c b/gdb/varobj.c index dbb80a8..25c5019 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -2413,7 +2413,7 @@ varobj_value_get_print_value (struct value *value, struct value_print_options opts; struct type *type = NULL; long len = 0; - char *encoding = NULL; + gdb::unique_xmalloc_ptr encoding; /* Initialize it just to avoid a GCC false warning. */ CORE_ADDR str_addr = 0; int string_print = 0; @@ -2464,7 +2464,6 @@ varobj_value_get_print_value (struct value *value, { gdbpy_extract_lazy_string (output, &str_addr, &type, &len, &encoding); - make_cleanup (free_current_contents, &encoding); string_print = 1; } else @@ -2520,11 +2519,11 @@ varobj_value_get_print_value (struct value *value, /* If the THEVALUE has contents, it is a regular string. */ if (!thevalue.empty ()) LA_PRINT_STRING (stb, type, (gdb_byte *) thevalue.c_str (), - len, encoding, 0, &opts); + len, encoding.get (), 0, &opts); else if (string_print) /* Otherwise, if string_print is set, and it is not a regular string, it is a lazy string. */ - val_print_string (type, encoding, str_addr, len, stb, &opts); + val_print_string (type, encoding.get (), str_addr, len, stb, &opts); else /* All other cases. */ common_val_print (value, stb, 0, &opts, current_language);