2009-02-04  Tom Tromey  <tromey@redhat.com>
	    Thiago Jung Bauermann  <bauerman@br.ibm.com>
	    Phil Muldoon  <pmuldoon@redhat.com>

	* python/python-internal.h (gdbpy_get_value_from_history): Rename
	prototype to gdbpy_history.
	(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.
	* python/python-value.c (valpy_address): New function.
	(convert_value_from_python): Use gdbpy_is_string.  Change to throw
	Python exception instead of a GDB exception on error.  Properly check
	Python booleans.
	(valpy_getitem): Convert field name to host string.  Handle array
	accesses.  Adapt to new behaviour of convert_value_from_python.
	(valpy_new): Adapt to new behaviour of convert_value_from_python.
	(enum valpy_opcode) <VALPY_LSH, VALPY_RSH, VALPY_BITAND,
	VALPY_BITXOR, VALPY_BITOR>: New constants.
	(valpy_binop): Update.  Adapt to new behaviour of
	convert_value_from_python.
	(valpy_invert): New function.
	(valpy_lsh): Likewise.
	(valpy_rsh): Likewise.
	(valpy_and): Likewise.
	(valpy_or): Likewise.
	(valpy_xor): Likewise.
	(valpy_richcompare): Call convert_value_from_python instead of doing
	conversions itself.
	(is_intlike, valpy_int, valpy_long, valpy_float): New functions.
	(gdbpy_get_value_from_history): Rename
	function to gdbpy_history.
	(gdbpy_initialize_values): Don't set tp_new.
	(value_object_type): Add valpy_new.
	(value_object_methods): Add `address' entry.
	(value_object_as_number): Update for new methods.
	* python/python.c (GdbMethods): Rename entry from
	`get_value_from_history' to `history'.

gdb/doc/
2009-02-04  Tom Tromey  <tromey@redhat.com>

	* gdb.texinfo (Basic Python): Document gdb.history.

gdb/testsuite/
2009-02-04  Tom Tromey  <tromey@redhat.com>
	    Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* gdb.python/python-value.exp: Use `gdb.history' instead of
	`gdb.value_from_history'.
	(test_value_numeric_ops): Add test for conversion of enum constant.
	* gdb.python/python-value.c (enum e): New type.
	(evalue): New global.
	(main): Use argv.
This commit is contained in:
Thiago Jung Bauermann 2009-02-04 21:55:40 +00:00
parent 20261af84c
commit 08c637dee2
10 changed files with 436 additions and 117 deletions

View file

@ -94,6 +94,29 @@ python_string_to_unicode (PyObject *obj)
return unicode_str;
}
/* Returns a newly allocated string with the contents of the given unicode
string object converted to 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. */
static char *
unicode_to_encoded_string (PyObject *unicode_str, const char *charset)
{
char *result;
PyObject *string;
/* Translate string to named charset. */
string = PyUnicode_AsEncodedString (unicode_str, charset, NULL);
if (string == NULL)
return NULL;
result = xstrdup (PyString_AsString (string));
Py_DECREF (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.
@ -102,19 +125,7 @@ python_string_to_unicode (PyObject *obj)
char *
unicode_to_target_string (PyObject *unicode_str)
{
char *target_string;
PyObject *string;
/* Translate string to target's charset. */
string = PyUnicode_AsEncodedString (unicode_str, target_charset (), NULL);
if (string == NULL)
return NULL;
target_string = xstrdup (PyString_AsString (string));
Py_DECREF (string);
return target_string;
return unicode_to_encoded_string (unicode_str, target_charset ());
}
/* Converts a python string (8-bit or unicode) to a target string in
@ -132,3 +143,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);
}