public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
From: tromey@sourceware.org
To: archer-commits@sourceware.org
Subject: [SCM]  archer-tromey-python: gdb
Date: Tue, 21 Oct 2008 18:32:00 -0000	[thread overview]
Message-ID: <20081021183229.2654.qmail@sourceware.org> (raw)

The branch, archer-tromey-python has been updated
       via  86eacf053f8a111cdddb8410aa9b9b7b0527fa75 (commit)
      from  e726423960c41516007f440ed0173b1acf3ba4d9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 86eacf053f8a111cdddb8410aa9b9b7b0527fa75
Author: Tom Tromey <tromey@redhat.com>
Date:   Tue Oct 21 12:30:30 2008 -0600

    gdb
    	* python/python.c (pretty_print_one_value): Use gdbpy_is_string
    	and python_string_to_host_string.
    	* python/python-value.c (valpy_richcompare): Use gdbpy_is_string.
    	(convert_value_from_python): Likewise.
    	* python/python-param.c (set_parameter_value): Use gdbpy_is_string
    	and python_string_to_host_string.
    	(compute_enum_values): Likewise.
    	(parmpy_init): Likewise.
    	* python/python-function.c (fnpy_init): Use gdbpy_is_string and
    	python_string_to_host_string.
    	* python/python-cmd.c (cmdpy_completer): Use gdbpy_is_string and
    	python_string_to_host_string.
    	(cmdpy_init): Likewise.
    	* varobj.c (varobj_get_display_hint): Use gdbpy_is_string.
    	* python/python-internal.h (gdbpy_is_string): Declare.
    	(python_string_to_host_string): Declare.
    	* python/python-utils.c (gdbpy_is_string): New function.
    	(unicode_to_encoded_string): New function.
    	(unicode_to_target_string): Use it.
    	(python_string_to_host_string): New function.
    gdb/testsuite
    	* gdb.python/python-prettyprint.exp (run_lang_tests): Don't expect
    	quotes.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                                   |   23 ++++++++++
 gdb/python/python-cmd.c                         |   10 ++---
 gdb/python/python-function.c                    |    5 +-
 gdb/python/python-internal.h                    |    2 +
 gdb/python/python-param.c                       |   19 ++++----
 gdb/python/python-utils.c                       |   52 +++++++++++++++++++----
 gdb/python/python-value.c                       |    4 +-
 gdb/python/python.c                             |    4 +-
 gdb/testsuite/ChangeLog                         |    5 ++
 gdb/testsuite/gdb.python/python-prettyprint.exp |    6 ++-
 gdb/varobj.c                                    |    4 +-
 11 files changed, 100 insertions(+), 34 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 582cc95..0ee50c8 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,26 @@
+2008-10-21  Tom Tromey  <tromey@redhat.com>
+
+	* python/python.c (pretty_print_one_value): Use gdbpy_is_string
+	and python_string_to_host_string.
+	* python/python-value.c (valpy_richcompare): Use gdbpy_is_string.
+	(convert_value_from_python): Likewise.
+	* python/python-param.c (set_parameter_value): Use gdbpy_is_string
+	and python_string_to_host_string.
+	(compute_enum_values): Likewise.
+	(parmpy_init): Likewise.
+	* python/python-function.c (fnpy_init): Use gdbpy_is_string and
+	python_string_to_host_string.
+	* python/python-cmd.c (cmdpy_completer): Use gdbpy_is_string and
+	python_string_to_host_string.
+	(cmdpy_init): Likewise.
+	* varobj.c (varobj_get_display_hint): Use gdbpy_is_string.
+	* python/python-internal.h (gdbpy_is_string): Declare.
+	(python_string_to_host_string): Declare.
+	* python/python-utils.c (gdbpy_is_string): New function.
+	(unicode_to_encoded_string): New function.
+	(unicode_to_target_string): Use it.
+	(python_string_to_host_string): New function.
+
 2008-10-20  Tom Tromey  <tromey@redhat.com>
 
 	* mi/mi-main.c (mi_cmd_list_features): Add "python" feature.
diff --git a/gdb/python/python-cmd.c b/gdb/python/python-cmd.c
index c628623..58e79da 100644
--- a/gdb/python/python-cmd.c
+++ b/gdb/python/python-cmd.c
@@ -196,17 +196,15 @@ cmdpy_completer (struct cmd_list_element *command, char *text, char *word)
       result = (char **) xmalloc ((len + 1) * sizeof (char *));
       for (i = out = 0; i < len; ++i)
 	{
-	  char *s;
 	  int l;
 	  PyObject *elt = PySequence_GetItem (resultobj, i);
-	  if (elt == NULL || ! PyString_Check (elt))
+	  if (elt == NULL || ! gdbpy_is_string (elt))
 	    {
 	      /* Skip problem elements.  */
 	      PyErr_Clear ();
 	      continue;
 	    }
-	  s = PyString_AsString (elt);
-	  result[out] = xstrdup (s);
+	  result[out] = python_string_to_host_string (elt);
 	  ++out;
 	}
       result[out] = NULL;
@@ -374,8 +372,8 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kwds)
   if (PyObject_HasAttrString (self, "__doc__"))
     {
       PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__");
-      if (ds_obj && PyString_Check (ds_obj))
-	docstring = xstrdup (PyString_AsString (ds_obj));
+      if (ds_obj && gdbpy_is_string (ds_obj))
+	docstring = python_string_to_host_string (ds_obj);
     }
   if (! docstring)
     docstring = xstrdup ("This command is not documented.");
diff --git a/gdb/python/python-function.c b/gdb/python/python-function.c
index 9f31557..c82a13b 100644
--- a/gdb/python/python-function.c
+++ b/gdb/python/python-function.c
@@ -114,8 +114,9 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds)
   if (PyObject_HasAttrString (self, "__doc__"))
     {
       PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__");
-      if (ds_obj && PyString_Check (ds_obj))
-	docstring = PyString_AsString (ds_obj);
+      if (ds_obj && gdbpy_is_string (ds_obj))
+	/* Nothing ever frees this.  */
+	docstring = python_string_to_host_string (ds_obj);
     }
   if (! docstring)
     docstring = "This command is not documented.";
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index ef4e8f8..12b9917 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -117,6 +117,8 @@ void gdbpy_print_stack (void);
 PyObject *python_string_to_unicode (PyObject *obj);
 char *unicode_to_target_string (PyObject *unicode_str);
 char *python_string_to_target_string (PyObject *obj);
+char *python_string_to_host_string (PyObject *obj);
+int gdbpy_is_string (PyObject *obj);
 
 /* Note that these are declared here, and not in python.h with the
    other pretty-printer functions, because they refer to PyObject.  */
diff --git a/gdb/python/python-param.c b/gdb/python/python-param.c
index a9b8c4d..cf1ceaa 100644
--- a/gdb/python/python-param.c
+++ b/gdb/python/python-param.c
@@ -116,7 +116,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
     case var_string_noescape:
     case var_optional_filename:
     case var_filename:
-      if (! PyString_Check (value)
+      if (! gdbpy_is_string (value)
 	  && (self->type == var_filename
 	      || value != Py_None))
 	{
@@ -133,7 +133,7 @@ set_parameter_value (parmpy_object *self, PyObject *value)
 	    self->value.stringval = NULL;
 	}
       else
-	self->value.stringval = xstrdup (PyString_AsString (value));
+	self->value.stringval = python_string_to_host_string (value);
       break;
 
     case var_enum:
@@ -141,16 +141,17 @@ set_parameter_value (parmpy_object *self, PyObject *value)
 	int i;
 	char *str;
 
-	if (! PyString_Check (value))
+	if (! gdbpy_is_string (value))
 	  {
 	    PyErr_SetString (PyExc_RuntimeError, "string required");
 	    return -1;
 	  }
 
-	str = PyString_AsString (value);
+	str = python_string_to_host_string (value);
 	for (i = 0; self->enumeration[i]; ++i)
 	  if (! strcmp (self->enumeration[i], str))
 	    break;
+	xfree (str);
 	if (! self->enumeration[i])
 	  {
 	    PyErr_SetString (PyExc_RuntimeError,
@@ -359,17 +360,15 @@ compute_enum_values (parmpy_object *self, PyObject *enum_values)
 
   for (i = 0; i < size; ++i)
     {
-      char *value;
       PyObject *item = PySequence_GetItem (enum_values, i);
       if (! item)
 	return 0;
-      if (! PyString_Check (item))
+      if (! gdbpy_is_string (item))
 	{
 	  PyErr_SetString (PyExc_RuntimeError, "enumeration item not a string");
 	  return 0;
 	}
-      value = PyString_AsString (item);
-      self->enumeration[i] = xstrdup (value);
+      self->enumeration[i] = python_string_to_host_string (item);
     }
 
   return 1;
@@ -463,8 +462,8 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
   if (PyObject_HasAttrString (self, "__doc__"))
     {
       PyObject *ds_obj = PyObject_GetAttrString (self, "__doc__");
-      if (ds_obj && PyString_Check (ds_obj))
-	docstring = xstrdup (PyString_AsString (ds_obj));
+      if (ds_obj && gdbpy_is_string (ds_obj))
+	docstring = python_string_to_host_string (ds_obj);
     }
   if (! docstring)
     docstring = xstrdup ("This command is not documented.");
diff --git a/gdb/python/python-utils.c b/gdb/python/python-utils.c
index 912845f..2fdd2b7 100644
--- a/gdb/python/python-utils.c
+++ b/gdb/python/python-utils.c
@@ -78,26 +78,37 @@ python_string_to_unicode (PyObject *obj)
 }
 
 /* Returns a newly allocated string with the contents of the given unicode
-   string object converted to the target's charset.  If an error occurs during
+   string object converted to a named charset.  If an error occurs during
    the conversion, NULL will be returned and a python exception will be set.
 
    The caller is responsible for xfree'ing the string.  */
-char *
-unicode_to_target_string (PyObject *unicode_str)
+static char *
+unicode_to_encoded_string (PyObject *unicode_str, const char *charset)
 {
-  char *target_string;
+  char *result;
   PyObject *string;
 
-  /* Translate string to target's charset.  */
-  string = PyUnicode_AsEncodedString (unicode_str, target_charset (), NULL);
+  /* Translate string to named charset.  */
+  string = PyUnicode_AsEncodedString (unicode_str, charset, NULL);
   if (string == NULL)
     return NULL;
 
-  target_string = xstrdup (PyString_AsString (string));
+  result = xstrdup (PyString_AsString (string));
 
   Py_DECREF (string);
 
-  return target_string;
+  return result;
+}
+
+/* Returns a newly allocated string with the contents of the given unicode
+   string 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.
+
+   The caller is responsible for xfree'ing the string.  */
+char *
+unicode_to_target_string (PyObject *unicode_str)
+{
+  return unicode_to_encoded_string (unicode_str, target_charset ());
 }
 
 /* Converts a python string (8-bit or unicode) to a target string in
@@ -115,3 +126,28 @@ python_string_to_target_string (PyObject *obj)
 
   return unicode_to_target_string (str);
 }
+
+/* Converts a python string (8-bit or unicode) to a target string in
+   the host's charset.  Returns NULL on error, with a python exception set.
+
+   The caller is responsible for xfree'ing the string.  */
+char *
+python_string_to_host_string (PyObject *obj)
+{
+  PyObject *str;
+
+  str = python_string_to_unicode (obj);
+  if (str == NULL)
+    return NULL;
+
+  return unicode_to_encoded_string (str, host_charset ());
+}
+
+/* Return true if OBJ is a Python string or unicode object, false
+   otherwise.  */
+
+int
+gdbpy_is_string (PyObject *obj)
+{
+  return PyString_Check (obj) || PyUnicode_Check (obj);
+}
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 7d677dd..93af465 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -495,7 +495,7 @@ valpy_richcompare (PyObject *self, PyObject *other, int op)
 
       value_other = value_from_double (builtin_type_pyfloat, d);
     }
-  else if (PyString_Check (other) || PyUnicode_Check (other))
+  else if (gdbpy_is_string (other))
     {
       char *str;
 
@@ -720,7 +720,7 @@ convert_value_from_python (PyObject *obj)
       if (! PyErr_Occurred ())
 	value = value_from_double (builtin_type_pyfloat, d);
     }
-  else if (PyString_Check (obj) || PyUnicode_Check (obj))
+  else if (gdbpy_is_string (obj))
     {
       char *s;
 
diff --git a/gdb/python/python.c b/gdb/python/python.c
index c4e0fbd..55de351 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -706,8 +706,8 @@ pretty_print_one_value (PyObject *func, struct value *value,
 	result = PyObject_CallFunctionObjArgs (func, val_obj, NULL);
       if (result)
 	{
-	  if (PyString_Check (result))
-	    output = xstrdup (PyString_AsString (result));
+	  if (gdbpy_is_string (result))
+	    output = python_string_to_host_string (result);
 	  else if (PyObject_TypeCheck (result, &value_object_type))
 	    {
 	      /* If we just call convert_value_from_python for this
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index a41bbb0..e6c51bc 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2008-10-21  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.python/python-prettyprint.exp (run_lang_tests): Don't expect
+	quotes.
+
 2008-10-20  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.python/python-prettyprint.exp: Fixed comment.
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.exp b/gdb/testsuite/gdb.python/python-prettyprint.exp
index d6aa537..2a69572 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/python-prettyprint.exp
@@ -72,8 +72,10 @@ proc run_lang_tests {lang} {
 	gdb_test "print cpssa" " = {{zss = 11, s =  a=<12> b=<$hex>}, {zss = 13, s =  a=<14> b=<$hex>}}"
     }
 
-  gdb_test "print x" " = $hex \"this is x\""
-  gdb_test "print c" " = \"container $hex .\"container.\" with 2 elements..?.0. = 23..?.1. = 72\""
+    gdb_test "print x" " = $hex \"this is x\""
+
+    set nl "\[\r\n\]+"
+    gdb_test "print c" " = container $hex \"container\" with 2 elements$nl *.0. = 23$nl *.1. = 72"
 }
 
 run_lang_tests "c"
diff --git a/gdb/varobj.c b/gdb/varobj.c
index e6890e4..c668c7e 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -755,8 +755,8 @@ varobj_get_display_hint (struct varobj *var)
       PyObject *hint = PyObject_CallMethodObjArgs (var->pretty_printer,
 						   gdbpy_display_hint_cst,
 						   NULL);
-      if (PyString_Check (hint))
-	result = xstrdup (PyString_AsString (hint));
+      if (gdbpy_is_string (hint))
+	result = python_string_to_host_string (hint);
       if (hint)
 	Py_DECREF (hint);
       else


hooks/post-receive
--
Repository for Project Archer.


             reply	other threads:[~2008-10-21 18:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-21 18:32 tromey [this message]
2008-10-22 18:18 tromey
2008-10-23 21:28 tromey
2008-10-23 22:27 tromey
2008-11-06 19:58 tromey
2008-11-06 21:11 tromey
2008-11-10 14:15 tromey
2008-11-12  1:54 tromey
2008-11-16 16:56 tromey
2008-11-16 22:18 tromey
2008-11-17 15:45 tromey
2008-11-18 15:54 tromey
2008-11-18 18:52 tromey
2008-11-21 18:25 tromey
2008-11-25 21:17 tromey
2008-12-01 19:10 tromey
2008-12-02 21:29 tromey
2008-12-09  0:33 tromey
2008-12-10 15:28 tromey
2008-12-12 23:54 tromey
2008-12-13  0:37 tromey
2008-12-15 22:38 tromey
2008-12-17 23:10 tromey
2009-02-05 19:56 tromey
2009-03-24 17:27 tromey
2009-04-07 20:28 tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081021183229.2654.qmail@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=archer-commits@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).