From patchwork Fri Dec 18 18:04:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 10063 Received: (qmail 26635 invoked by alias); 18 Dec 2015 18:04:17 -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 26626 invoked by uid 89); 18 Dec 2015 18:04:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_LOW, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=H*M:sk:001a114, H*MI:sk:001a114, symtab, sk:symfile X-HELO: mail-pa0-f73.google.com Received: from mail-pa0-f73.google.com (HELO mail-pa0-f73.google.com) (209.85.220.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 18 Dec 2015 18:04:15 +0000 Received: by mail-pa0-f73.google.com with SMTP id tl7so2034356pab.1 for ; Fri, 18 Dec 2015 10:04:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:message-id:date:subject:from:to :content-type; bh=zJ36xFbZ8Smu6keLdXOJ6Y8BArOvgT9UsnrIWolXFCQ=; b=MjerpVEjdLL+j1NtbNCuG0DE8kvge6bYSJi5c2cz94VctS6OZVDN2EUggV336yBxkG qUefiIlFAEngycfC4gP0oXVb4VCD3R6bD0Jfcg6zqk5Lmt+YE+TaxFML/yz9VLy+PHxG ZiSnQ8rO0AqxpbsjbAPUkPG0ar2QFD0sH+Cv0tmzfU5lG5pDEoyOU2rVo8gs9nby2Rnd MWFk+2pckJWWi+oVXycQDAuy4gKB7eCkmLUFKs/tnzBOpLBaam5dx4z8oj/ul85bPumF CQQZTnWc6kHFhu99ObssHeTiq28A5mHvZN0ppEiqhv0RQqPYXFOniSM9nmgt9+Uj6fa6 8mZw== X-Gm-Message-State: ALoCoQmcmdpzPS1eY4YNaN8Vh1nUIR4iZyUGl4al4+ldM/MFwFII4mnhqSEi89Jou8RAX1hpRxfwz+n9xsH9w62Gw/hLzTYhas6ob3q5Zz61OSKI+Pv/xPG+gGpS376ZHK7Ttei8ayvMOjOEIqQVdSt6dIXgemA+SXt4TBwSQQsIdETVxANwFBXqhagQP2Y9E4wX+Pz8BquV MIME-Version: 1.0 X-Received: by 10.98.43.133 with SMTP id r127mr4039116pfr.9.1450461853465; Fri, 18 Dec 2015 10:04:13 -0800 (PST) Message-ID: <001a11438f7c8987ea05272ff754@google.com> Date: Fri, 18 Dec 2015 18:04:13 +0000 Subject: [PATCH] Add function host_string_to_python_string. From: Doug Evans To: gdb-patches@sourceware.org X-IsSubscribed: yes Hi. There's a python_string_to_host_string function, but not its counterpart. I couldn't find anything in the record arguing against its existence, and there's enough of a use for it so I added it. Regression tested on amd64-linux. 2015-12-18 Doug Evans * python/py-utils.c (host_string_to_python_string): New function. * python/python-internal.h (host_string_to_python_string): Declare it. * python/py-*.c (*): Update all calls to PyString_Decode (str, strlen (str), host_charset (), NULL) to use host_string_to_python_string (str) instead. str_obj = Py_None; diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 9c0b0e4..f261e90 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -392,7 +392,7 @@ bppy_get_location (PyObject *self, void *closure) str = event_location_to_string (obj->bp->location); if (! str) str = ""; - return PyString_Decode (str, strlen (str), host_charset (), NULL); + return host_string_to_python_string (str); } /* Python function to get the breakpoint expression. */ @@ -414,7 +414,7 @@ bppy_get_expression (PyObject *self, void *closure) if (! str) str = ""; - return PyString_Decode (str, strlen (str), host_charset (), NULL); + return host_string_to_python_string (str); } /* Python function to get the condition expression of a breakpoint. */ @@ -430,7 +430,7 @@ bppy_get_condition (PyObject *self, void *closure) if (! str) Py_RETURN_NONE; - return PyString_Decode (str, strlen (str), host_charset (), NULL); + return host_string_to_python_string (str); } /* Returns 0 on success. Returns -1 on error, with a python exception set. @@ -515,7 +515,7 @@ bppy_get_commands (PyObject *self, void *closure) ui_out_redirect (current_uiout, NULL); cmdstr = ui_file_xstrdup (string_file, &length); make_cleanup (xfree, cmdstr); - result = PyString_Decode (cmdstr, strlen (cmdstr), host_charset (), NULL); + result = host_string_to_python_string (cmdstr); do_cleanups (chain); return result; } diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c index ed2fe74..bfde3cc 100644 --- a/gdb/python/py-objfile.c +++ b/gdb/python/py-objfile.c @@ -78,9 +78,7 @@ objfpy_get_filename (PyObject *self, void *closure) objfile_object *obj = (objfile_object *) self; if (obj->objfile) - return PyString_Decode (objfile_name (obj->objfile), - strlen (objfile_name (obj->objfile)), - host_charset (), NULL); + return host_string_to_python_string (objfile_name (obj->objfile)); Py_RETURN_NONE; } @@ -96,8 +94,7 @@ objfpy_get_username (PyObject *self, void *closure) { const char *username = obj->objfile->original_name; - return PyString_Decode (username, strlen (username), - host_charset (), NULL); + return host_string_to_python_string (username); } Py_RETURN_NONE; @@ -152,8 +149,7 @@ objfpy_get_build_id (PyObject *self, void *closure) char *hex_form = make_hex_string (build_id->data, build_id->size); PyObject *result; - result = PyString_Decode (hex_form, strlen (hex_form), - host_charset (), NULL); + result = host_string_to_python_string (hex_form); xfree (hex_form); return result; } diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index cd48cbb..4eead1b 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -71,9 +71,7 @@ pspy_get_filename (PyObject *self, void *closure) struct objfile *objfile = obj->pspace->symfile_object_file; if (objfile) - return PyString_Decode (objfile_name (objfile), - strlen (objfile_name (objfile)), - host_charset (), NULL); + return host_string_to_python_string (objfile_name (objfile)); } Py_RETURN_NONE; } diff --git a/gdb/python/py-symtab.c b/gdb/python/py-symtab.c index 79bfeca..66201e8 100644 --- a/gdb/python/py-symtab.c +++ b/gdb/python/py-symtab.c @@ -108,8 +108,7 @@ stpy_get_filename (PyObject *self, void *closure) STPY_REQUIRE_VALID (self, symtab); filename = symtab_to_filename_for_display (symtab); - str_obj = PyString_Decode (filename, strlen (filename), - host_charset (), NULL); + str_obj = host_string_to_python_string (filename); return str_obj; } @@ -140,8 +139,7 @@ stpy_get_producer (PyObject *self, void *closure) { const char *producer = COMPUNIT_PRODUCER (cust); - return PyString_Decode (producer, strlen (producer), - host_charset (), NULL); + return host_string_to_python_string (producer); } Py_RETURN_NONE; @@ -157,7 +155,7 @@ stpy_fullname (PyObject *self, PyObject *args) fullname = symtab_to_fullname (symtab); - return PyString_Decode (fullname, strlen (fullname), host_charset (), NULL); + return host_string_to_python_string (fullname); } /* Implementation of gdb.Symtab.is_valid (self) -> Boolean. diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 9a4d1ed..b766e3b 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -221,6 +221,14 @@ python_string_to_host_string (PyObject *obj) return result; } +/* Convert a host string to a python string. */ + +PyObject * +host_string_to_python_string (const char *str) +{ + return PyString_Decode (str, strlen (str), host_charset (), NULL); +} + /* Return true if OBJ is a Python string or unicode object, false otherwise. */ diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index ee949b7..a43d395 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -538,6 +538,7 @@ char *unicode_to_target_string (PyObject *unicode_str); char *python_string_to_target_string (PyObject *obj); PyObject *python_string_to_target_python_string (PyObject *obj); char *python_string_to_host_string (PyObject *obj); +PyObject *host_string_to_python_string (const char *str); int gdbpy_is_string (PyObject *obj); char *gdbpy_obj_to_string (PyObject *obj); char *gdbpy_exception_to_string (PyObject *ptype, PyObject *pvalue); diff --git a/gdb/python/python.c b/gdb/python/python.c index 6cbe5f0..09c99cf 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -516,7 +516,7 @@ gdbpy_parameter_value (enum var_types type, void *var) if (! str) str = ""; - return PyString_Decode (str, strlen (str), host_charset (), NULL); + return host_string_to_python_string (str); } case var_boolean: @@ -706,7 +706,7 @@ gdbpy_solib_name (PyObject *self, PyObject *args) soname = solib_name_from_address (current_program_space, pc); if (soname) - str_obj = PyString_Decode (soname, strlen (soname), host_charset (), NULL); + str_obj = host_string_to_python_string (soname); else {