From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 93615 invoked by alias); 28 Oct 2018 18:13:50 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 93509 invoked by uid 89); 28 Oct 2018 18:13:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=username, xfree, target's, 1097 X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.47.18) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 28 Oct 2018 18:13:43 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway20.websitewelcome.com (Postfix) with ESMTP id EC0D8400D7490 for ; Sun, 28 Oct 2018 13:13:41 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id GpZFg2IpDSjJAGpZFgVVcN; Sun, 28 Oct 2018 13:13:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=/3POUiKV0PQYu9AYbRdhl0MD89aR1z1mANRsvH3w+ns=; b=AY4IjztIsSsDJoCgidOYlklp7v PJJoP8l+P78diQJ36XUAZcvDVJwT8J7mhfCg6PB/evpihIsnUSJ7gN3aJMNKmM7kj50Iw5xD4pevo pUJfIrRRKxNGxtmkg6llYugPj; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:39426 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1gGpZE-001XD2-P9; Sun, 28 Oct 2018 13:13:40 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/3] Return gdbpy_ref from some Python string functions Date: Sun, 28 Oct 2018 18:13:00 -0000 Message-Id: <20181028181337.21681-3-tom@tromey.com> In-Reply-To: <20181028181337.21681-1-tom@tromey.com> References: <20181028181337.21681-1-tom@tromey.com> X-SW-Source: 2018-10/txt/msg00677.txt.bz2 This changes python_string_to_unicode, python_string_to_target_python_string, and host_string_to_python_string to return gdbpy_ref. gdb/ChangeLog 2018-10-28 Tom Tromey * python/python.c (gdbpy_parameter_value): Update. * python/python-internal.h (python_string_to_unicode) (python_string_to_target_python_string) (host_string_to_python_string): Return gdbpy_ref. * python/py-utils.c (python_string_to_unicode) (unicode_to_encoded_python_string) (unicode_to_target_python_string) (python_string_to_target_string) (python_string_to_target_python_string): Return gdbpy_ref. (python_string_to_host_string): Update. (host_string_to_python_string): Return gdbpy_ref. * python/py-symtab.c (stpy_get_filename, stpy_get_producer) (stpy_fullname): Update. * python/py-progspace.c (pspy_get_filename, pspy_solib_name): Update. * python/py-prettyprint.c (print_string_repr): Update. * python/py-objfile.c (objfpy_get_filename, objfpy_get_username) (objfpy_get_build_id): Update. * python/py-breakpoint.c (bppy_get_location) (bppy_get_expression, bppy_get_condition, bppy_get_commands): Update. --- gdb/ChangeLog | 24 ++++++++++++++++++++++++ gdb/python/py-breakpoint.c | 8 ++++---- gdb/python/py-objfile.c | 7 ++++--- gdb/python/py-prettyprint.c | 2 +- gdb/python/py-progspace.c | 5 +++-- gdb/python/py-symtab.c | 6 +++--- gdb/python/py-utils.c | 25 +++++++++++++------------ gdb/python/python-internal.h | 6 +++--- gdb/python/python.c | 2 +- 9 files changed, 56 insertions(+), 29 deletions(-) diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 94afd503e9..d144bcf2e6 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -399,7 +399,7 @@ bppy_get_location (PyObject *self, void *closure) str = event_location_to_string (location); if (! str) str = ""; - return host_string_to_python_string (str); + return host_string_to_python_string (str).release (); } /* Python function to get the breakpoint expression. */ @@ -421,7 +421,7 @@ bppy_get_expression (PyObject *self, void *closure) if (! str) str = ""; - return host_string_to_python_string (str); + return host_string_to_python_string (str).release (); } /* Python function to get the condition expression of a breakpoint. */ @@ -437,7 +437,7 @@ bppy_get_condition (PyObject *self, void *closure) if (! str) Py_RETURN_NONE; - return host_string_to_python_string (str); + return host_string_to_python_string (str).release (); } /* Returns 0 on success. Returns -1 on error, with a python exception set. @@ -512,7 +512,7 @@ bppy_get_commands (PyObject *self, void *closure) END_CATCH current_uiout->redirect (NULL); - return host_string_to_python_string (stb.c_str ()); + return host_string_to_python_string (stb.c_str ()).release (); } /* Set the commands attached to a breakpoint. Returns 0 on success. diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index 2e24d0f3ff..dc7f342aef 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -79,7 +79,8 @@ objfpy_get_filename (PyObject *self, void *closure) objfile_object *obj = (objfile_object *) self; if (obj->objfile) - return host_string_to_python_string (objfile_name (obj->objfile)); + return (host_string_to_python_string (objfile_name (obj->objfile)) + .release ()); Py_RETURN_NONE; } @@ -95,7 +96,7 @@ objfpy_get_username (PyObject *self, void *closure) { const char *username = obj->objfile->original_name; - return host_string_to_python_string (username); + return host_string_to_python_string (username).release (); } Py_RETURN_NONE; @@ -145,7 +146,7 @@ objfpy_get_build_id (PyObject *self, void *closure) char *hex_form = make_hex_string (build_id->data, build_id->size); PyObject *result; - result = host_string_to_python_string (hex_form); + result = host_string_to_python_string (hex_form).release (); xfree (hex_form); return result; } diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c index a706222581..2386dccbbb 100644 --- a/gdb/python/py-prettyprint.c +++ b/gdb/python/py-prettyprint.c @@ -316,7 +316,7 @@ print_string_repr (PyObject *printer, const char *hint, else { gdbpy_ref<> string - (python_string_to_target_python_string (py_str.get ())); + = python_string_to_target_python_string (py_str.get ()); if (string != NULL) { char *output; diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index 6395d5bb15..bd195a54c1 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -83,7 +83,8 @@ pspy_get_filename (PyObject *self, void *closure) struct objfile *objfile = obj->pspace->symfile_object_file; if (objfile) - return host_string_to_python_string (objfile_name (objfile)); + return (host_string_to_python_string (objfile_name (objfile)) + .release ()); } Py_RETURN_NONE; } @@ -373,7 +374,7 @@ pspy_solib_name (PyObject *o, PyObject *args) soname = solib_name_from_address (self->pspace, pc); if (soname == nullptr) Py_RETURN_NONE; - return host_string_to_python_string (soname); + return host_string_to_python_string (soname).release (); } /* Return the innermost lexical block containing the specified pc value, diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c index 9bb20dab31..4b29299bf9 100644 --- a/gdb/python/py-symtab.c +++ b/gdb/python/py-symtab.c @@ -109,7 +109,7 @@ stpy_get_filename (PyObject *self, void *closure) STPY_REQUIRE_VALID (self, symtab); filename = symtab_to_filename_for_display (symtab); - str_obj = host_string_to_python_string (filename); + str_obj = host_string_to_python_string (filename).release (); return str_obj; } @@ -137,7 +137,7 @@ stpy_get_producer (PyObject *self, void *closure) { const char *producer = COMPUNIT_PRODUCER (cust); - return host_string_to_python_string (producer); + return host_string_to_python_string (producer).release (); } Py_RETURN_NONE; @@ -153,7 +153,7 @@ stpy_fullname (PyObject *self, PyObject *args) fullname = symtab_to_fullname (symtab); - return host_string_to_python_string (fullname); + return host_string_to_python_string (fullname).release (); } /* Implementation of gdb.Symtab.is_valid (self) -> Boolean. diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 4dcac3daaf..2b4779097b 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -34,7 +34,7 @@ If the given object is not one of the mentioned string types, NULL is returned, with the TypeError python exception set. */ -PyObject * +gdbpy_ref<> python_string_to_unicode (PyObject *obj) { PyObject *unicode_str; @@ -57,7 +57,7 @@ python_string_to_unicode (PyObject *obj) unicode_str = NULL; } - return unicode_str; + return gdbpy_ref<> (unicode_str); } /* Returns a newly allocated string with the contents of the given unicode @@ -88,11 +88,11 @@ unicode_to_encoded_string (PyObject *unicode_str, const char *charset) object converted to a named charset. If an error occurs during the conversion, NULL will be returned and a python exception will be set. */ -static PyObject * +static gdbpy_ref<> unicode_to_encoded_python_string (PyObject *unicode_str, const char *charset) { /* Translate string to named charset. */ - return PyUnicode_AsEncodedString (unicode_str, charset, NULL); + return gdbpy_ref<> (PyUnicode_AsEncodedString (unicode_str, charset, NULL)); } /* Returns a newly allocated string with the contents of the given @@ -110,7 +110,7 @@ unicode_to_target_string (PyObject *unicode_str) object converted to the target's charset. If an error occurs during the conversion, NULL will be returned and a python exception will be set. */ -static PyObject * +static gdbpy_ref<> unicode_to_target_python_string (PyObject *unicode_str) { return unicode_to_encoded_python_string (unicode_str, @@ -123,7 +123,7 @@ unicode_to_target_python_string (PyObject *unicode_str) gdb::unique_xmalloc_ptr python_string_to_target_string (PyObject *obj) { - gdbpy_ref<> str (python_string_to_unicode (obj)); + gdbpy_ref<> str = python_string_to_unicode (obj); if (str == NULL) return NULL; @@ -135,12 +135,12 @@ python_string_to_target_string (PyObject *obj) set. In Python 3, the returned object is a "bytes" object (not a string). */ -PyObject * +gdbpy_ref<> python_string_to_target_python_string (PyObject *obj) { - gdbpy_ref<> str (python_string_to_unicode (obj)); + gdbpy_ref<> str = python_string_to_unicode (obj); if (str == NULL) - return NULL; + return str; return unicode_to_target_python_string (str.get ()); } @@ -151,7 +151,7 @@ python_string_to_target_python_string (PyObject *obj) gdb::unique_xmalloc_ptr python_string_to_host_string (PyObject *obj) { - gdbpy_ref<> str (python_string_to_unicode (obj)); + gdbpy_ref<> str = python_string_to_unicode (obj); if (str == NULL) return NULL; @@ -160,10 +160,11 @@ python_string_to_host_string (PyObject *obj) /* Convert a host string to a python string. */ -PyObject * +gdbpy_ref<> host_string_to_python_string (const char *str) { - return PyString_Decode (str, strlen (str), host_charset (), NULL); + return gdbpy_ref<> (PyString_Decode (str, strlen (str), host_charset (), + NULL)); } /* Return true if OBJ is a Python string or unicode object, false diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 5f15a33d5e..582044ad8c 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -656,12 +656,12 @@ int gdbpy_print_python_errors_p (void); void gdbpy_print_stack (void); void gdbpy_handle_exception () ATTRIBUTE_NORETURN; -PyObject *python_string_to_unicode (PyObject *obj); +gdbpy_ref<> python_string_to_unicode (PyObject *obj); gdb::unique_xmalloc_ptr unicode_to_target_string (PyObject *unicode_str); gdb::unique_xmalloc_ptr python_string_to_target_string (PyObject *obj); -PyObject *python_string_to_target_python_string (PyObject *obj); +gdbpy_ref<> python_string_to_target_python_string (PyObject *obj); gdb::unique_xmalloc_ptr python_string_to_host_string (PyObject *obj); -PyObject *host_string_to_python_string (const char *str); +gdbpy_ref<> host_string_to_python_string (const char *str); int gdbpy_is_string (PyObject *obj); gdb::unique_xmalloc_ptr gdbpy_obj_to_string (PyObject *obj); gdb::unique_xmalloc_ptr gdbpy_exception_to_string (PyObject *ptype, diff --git a/gdb/python/python.c b/gdb/python/python.c index 348405e205..a37ed10bcf 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -438,7 +438,7 @@ gdbpy_parameter_value (enum var_types type, void *var) if (! str) str = ""; - return host_string_to_python_string (str); + return host_string_to_python_string (str).release (); } case var_boolean: -- 2.17.1