This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python] add argument to Value.string
- From: Tom Tromey <tromey at redhat dot com>
- To: Project Archer <archer at sourceware dot org>
- Date: Tue, 02 Dec 2008 14:28:53 -0700
- Subject: [python] add argument to Value.string
- Reply-to: Tom Tromey <tromey at redhat dot com>
This adds an "errors" argument to Value.string, to let callers control
the python string decoder, just as they would with string.decode.
Tom
2008-12-02 Tom Tromey <tromey@redhat.com>
* python/python-value.c (valpy_string): Add "errors" argument.
2008-12-02 Tom Tromey <tromey@redhat.com>
* gdb.texinfo (Values From Inferior): Document new string
argument.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index dfc19aa..1e7a22d 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18247,7 +18247,7 @@ The result @code{bar} will be a @code{gdb.Value} object holding the
value pointed to by @code{foo}.
@end defmethod
-@defmethod Value string @r{[}encoding@r{]}
+@defmethod Value string @r{[}encoding @r{[}errors@r{]}@r{]}
If this @code{gdb.Value} represents a string, then this method
converts the contents to a Python string. Otherwise, this method will
throw an exception.
@@ -18263,8 +18263,13 @@ by a zero of the appropriate width.
If the optional @var{encoding} argument is given, it must be a string
naming the encoding of the string in the @code{gdb.Value}. The Python
codec machinery will be used to convert the string. If @var{encoding}
-is not given, then the @code{target-charset} (@pxref{Character Sets})
-will be used.
+is not given, or if @var{encoding} is the empty string, then either
+the @code{target-charset} (@pxref{Character Sets}) will be used, or a
+language-specific encoding will be used, if the current language is
+able to supply one.
+
+The optional @var{errors} argument is the same as the corresponding
+argument to Python's @code{string.decode} method.
@end defmethod
@defmethod Value type
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 5a7fae0..342cf28 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -165,10 +165,11 @@ valpy_string (PyObject *self, PyObject *args)
volatile struct gdb_exception except;
PyObject *unicode;
const char *encoding = NULL;
+ const char *errors = NULL;
const char *user_encoding = NULL;
const char *la_encoding = NULL;
- if (!PyArg_ParseTuple (args, "|s", &user_encoding))
+ if (!PyArg_ParseTuple (args, "|ss", &user_encoding, &errors))
return NULL;
TRY_CATCH (except, RETURN_MASK_ALL)
@@ -187,8 +188,8 @@ valpy_string (PyObject *self, PyObject *args)
return NULL;
}
- encoding = user_encoding? user_encoding : la_encoding;
- unicode = PyUnicode_Decode (buffer, length, encoding, NULL);
+ encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
+ unicode = PyUnicode_Decode (buffer, length, encoding, errors);
xfree (buffer);
return unicode;