| |   |
| 31 | 31 | extern PyTypeObject value_object_type; |
| 32 | 32 | extern PyTypeObject symbol_object_type; |
| 33 | 33 | |
| 34 | | PyObject *gdb_value_from_int (PyObject *self, PyObject *args); |
| 35 | | PyObject *gdb_value_from_history (PyObject *self, PyObject *args); |
| 34 | PyObject *gdbpy_make_value_from_int (PyObject *self, PyObject *args); |
| 35 | PyObject *gdbpy_get_value_from_history (PyObject *self, PyObject *args); |
| 36 | 36 | PyObject *gdbpy_breakpoints (PyObject *, PyObject *); |
| 37 | 37 | PyObject *gdbpy_get_frames (PyObject *, PyObject *); |
| 38 | 38 | PyObject *gdbpy_get_current_frame (PyObject *, PyObject *); |
| … | … | |
| 40 | 40 | PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args); |
| 41 | 41 | PyObject *gdbpy_get_selected_frame (PyObject *self, PyObject *args); |
| 42 | 42 | |
| 43 | | PyObject *value_from_value (struct value *v); |
| 44 | 43 | PyObject *variable_to_python (struct cmd_list_element *); |
| 45 | 44 | PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal); |
| 46 | 45 | PyObject *symtab_to_symtab_object (struct symtab *symtab); |
| 47 | 46 | PyObject *symbol_to_symbol_object (struct symbol *sym); |
| 48 | 47 | PyObject *block_to_block_object (struct block *block); |
| 49 | 48 | PyObject *value_to_value_object (struct value *v); |
| 49 | PyObject *gdb_owned_value_to_value_object (struct value *v); |
| 50 | 50 | |
| 51 | 51 | struct block *block_object_to_block (PyObject *obj); |
| 52 | 52 | struct symbol *symbol_object_to_symbol (PyObject *obj); |
| toggle raw diff |
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -31,8 +31,8 @@ extern PyTypeObject block_object_type;
extern PyTypeObject value_object_type;
extern PyTypeObject symbol_object_type;
-PyObject *gdb_value_from_int (PyObject *self, PyObject *args);
-PyObject *gdb_value_from_history (PyObject *self, PyObject *args);
+PyObject *gdbpy_make_value_from_int (PyObject *self, PyObject *args);
+PyObject *gdbpy_get_value_from_history (PyObject *self, PyObject *args);
PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
PyObject *gdbpy_get_frames (PyObject *, PyObject *);
PyObject *gdbpy_get_current_frame (PyObject *, PyObject *);
@@ -40,13 +40,13 @@ PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args);
PyObject *gdbpy_get_selected_frame (PyObject *self, PyObject *args);
-PyObject *value_from_value (struct value *v);
PyObject *variable_to_python (struct cmd_list_element *);
PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
PyObject *symtab_to_symtab_object (struct symtab *symtab);
PyObject *symbol_to_symbol_object (struct symbol *sym);
PyObject *block_to_block_object (struct block *block);
PyObject *value_to_value_object (struct value *v);
+PyObject *gdb_owned_value_to_value_object (struct value *v);
struct block *block_object_to_block (PyObject *obj);
struct symbol *symbol_object_to_symbol (PyObject *obj); |
| |   |
| 60 | 60 | if (!initialized) |
| 61 | 61 | { |
| 62 | 62 | static PyMethodDef GdbMethods[] = { |
| 63 | | {"value_from_int", gdb_value_from_int, METH_VARARGS, |
| 64 | | "Get a value from int"}, |
| 65 | | {"value_from_history", gdb_value_from_history, METH_VARARGS, |
| 66 | | "Get a value from history"}, |
| 63 | { "make_value_from_int", gdbpy_make_value_from_int, METH_VARARGS, |
| 64 | "Make a value from int" }, |
| 65 | { "get_value_from_history", gdbpy_get_value_from_history, METH_VARARGS, |
| 66 | "Get a value from history" }, |
| 67 | 67 | { "execute", execute_gdb_command, METH_VARARGS, |
| 68 | 68 | "Execute a gdb command" }, |
| 69 | 69 | { "show", get_show_variable, METH_VARARGS, |
| … | … | |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | tuple = PyTuple_New (1); |
| 153 | | PyTuple_SetItem (tuple, 0, value_from_value (value)); |
| 153 | PyTuple_SetItem (tuple, 0, gdb_owned_value_to_value_object (value)); |
| 154 | 154 | |
| 155 | 155 | result = PyObject_Call (format, tuple, Py_None); |
| 156 | 156 | if (result && PyString_Check (result)) |
| … | … | |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | tuple = PyTuple_New (1); |
| 197 | | PyTuple_SetItem (tuple, 0, value_from_value (varobj_get_raw_value (var))); |
| 197 | PyTuple_SetItem (tuple, 0, gdb_owned_value_to_value_object (varobj_get_raw_value (var))); |
| 198 | 198 | |
| 199 | 199 | result = PyObject_Call (format, tuple, Py_None); |
| 200 | 200 | if (!result) |
| toggle raw diff |
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -60,10 +60,10 @@ demand_python ()
if (!initialized)
{
static PyMethodDef GdbMethods[] = {
- {"value_from_int", gdb_value_from_int, METH_VARARGS,
- "Get a value from int"},
- {"value_from_history", gdb_value_from_history, METH_VARARGS,
- "Get a value from history"},
+ { "make_value_from_int", gdbpy_make_value_from_int, METH_VARARGS,
+ "Make a value from int" },
+ { "get_value_from_history", gdbpy_get_value_from_history, METH_VARARGS,
+ "Get a value from history" },
{ "execute", execute_gdb_command, METH_VARARGS,
"Execute a gdb command" },
{ "show", get_show_variable, METH_VARARGS,
@@ -150,7 +150,7 @@ pretty_print_value (struct value *value, const char *pretty_printer)
}
tuple = PyTuple_New (1);
- PyTuple_SetItem (tuple, 0, value_from_value (value));
+ PyTuple_SetItem (tuple, 0, gdb_owned_value_to_value_object (value));
result = PyObject_Call (format, tuple, Py_None);
if (result && PyString_Check (result))
@@ -194,7 +194,7 @@ list_varobj_children (struct varobj *var, const char *function)
}
tuple = PyTuple_New (1);
- PyTuple_SetItem (tuple, 0, value_from_value (varobj_get_raw_value (var)));
+ PyTuple_SetItem (tuple, 0, gdb_owned_value_to_value_object (varobj_get_raw_value (var)));
result = PyObject_Call (format, tuple, Py_None);
if (!result) |
| |   |
| 35 | 35 | |
| 36 | 36 | static void valpy_dealloc (PyObject *obj); |
| 37 | 37 | static PyObject *valpy_dereference (PyObject *self, PyObject *args); |
| 38 | | static PyObject *valpy_element (PyObject *self, PyObject *args); |
| 38 | static PyObject *valpy_get_element (PyObject *self, PyObject *args); |
| 39 | 39 | static PyObject *valpy_str (PyObject *self); |
| 40 | 40 | static PyObject *valpy_increment (PyObject *self, PyObject *args); |
| 41 | 41 | static PyObject *valpy_equal_p (PyObject *self, PyObject *args); |
| … | … | |
| 45 | 45 | |
| 46 | 46 | static PyMethodDef value_object_methods[] = { |
| 47 | 47 | { "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." }, |
| 48 | | { "element", valpy_element, METH_VARARGS, "Obtains element inside value." }, |
| 48 | { "get_element", valpy_get_element, METH_VARARGS, |
| 49 | "Obtains element inside value." }, |
| 49 | 50 | { "increment", valpy_increment, METH_VARARGS, |
| 50 | 51 | "Increment value by the given amount." }, |
| 51 | 52 | { "equals", valpy_equal_p, METH_VARARGS, "Compare values." }, |
| … | … | |
| 134 | 134 | |
| 135 | 135 | /* Takes value and string name of element inside that value. */ |
| 136 | 136 | static PyObject * |
| 137 | | valpy_element (PyObject *self, PyObject *args) |
| 137 | valpy_get_element (PyObject *self, PyObject *args) |
| 138 | 138 | { |
| 139 | 139 | value_object *self_value = (value_object *) self; |
| 140 | 140 | char *field; |
| … | … | |
| 301 | 301 | return PyInt_FromLong (ret); |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | | /* FIXME: clarify the naming to say the value |
| 305 | | won't be deleted by the Python code. */ |
| 304 | /* A value owned by GDB is in the all_values chain, so it will be freed |
| 305 | automatically when not needed anymore (i.e., before the current command |
| 306 | completes). */ |
| 306 | 307 | PyObject * |
| 307 | | value_from_value (struct value *v) |
| 308 | gdb_owned_value_to_value_object (struct value *v) |
| 308 | 309 | { |
| 309 | 310 | value_object *result = PyObject_New (value_object, &value_object_type); |
| 310 | 311 | if (result != NULL) |
| … | … | |
| 313 | 313 | result->value = v; |
| 314 | 314 | result->owned_by_gdb = 1; |
| 315 | 315 | /* FIXME: should we do it? What is it? */ |
| 316 | /* I don't think it is needed, since a GDB owned value has a very short |
| 317 | lifetime. The purpose of the list is explained in the comment above |
| 318 | its declaration. -- bauermann */ |
| 316 | 319 | value_prepend_to_list (&values_in_python, v); |
| 317 | 320 | } |
| 318 | 321 | return (PyObject *)result; |
| 319 | 322 | } |
| 320 | 323 | |
| 324 | /* Returns an object for a value which is released from the all_values chain, |
| 325 | so its lifetime is not bound to the execution of a command. */ |
| 321 | 326 | PyObject * |
| 322 | 327 | value_to_value_object (struct value *v) |
| 323 | 328 | { |
| … | … | |
| 331 | 331 | VALPY_RETURN_VALUE (val_obj, v); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | struct value * |
| 335 | value_object_to_value (PyObject *self) |
| 336 | { |
| 337 | value_object *real = (value_object *)self; |
| 338 | return real->value; |
| 339 | } |
| 340 | |
| 334 | 341 | PyObject * |
| 335 | | gdb_value_from_int (PyObject *self, PyObject *args) |
| 342 | gdbpy_make_value_from_int (PyObject *self, PyObject *args) |
| 336 | 343 | { |
| 337 | 344 | int i; |
| 338 | 345 | struct value *res_val = NULL; /* Initialize to appease gcc warning. */ |
| … | … | |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | PyObject * |
| 362 | | gdb_value_from_history (PyObject *self, PyObject *args) |
| 362 | gdbpy_get_value_from_history (PyObject *self, PyObject *args) |
| 363 | 363 | { |
| 364 | 364 | int i; |
| 365 | 365 | struct value *res_val = NULL; /* Initialize to appease gcc warning. */ |
| … | … | |
| 390 | 390 | |
| 391 | 391 | values_in_python = NULL; |
| 392 | 392 | } |
| 393 | | |
| 394 | | struct value * |
| 395 | | value_object_to_value (PyObject *self) |
| 396 | | { |
| 397 | | value_object *real = (value_object *)self; |
| 398 | | return real->value; |
| 399 | | } |
| toggle raw diff |
--- a/gdb/python/value.c
+++ b/gdb/python/value.c
@@ -35,7 +35,7 @@ struct value *values_in_python;
static void valpy_dealloc (PyObject *obj);
static PyObject *valpy_dereference (PyObject *self, PyObject *args);
-static PyObject *valpy_element (PyObject *self, PyObject *args);
+static PyObject *valpy_get_element (PyObject *self, PyObject *args);
static PyObject *valpy_str (PyObject *self);
static PyObject *valpy_increment (PyObject *self, PyObject *args);
static PyObject *valpy_equal_p (PyObject *self, PyObject *args);
@@ -45,7 +45,8 @@ static PyObject * valpy_common_print (PyObject *self, PyObject *args);
static PyMethodDef value_object_methods[] = {
{ "dereference", valpy_dereference, METH_NOARGS, "Dereferences the value." },
- { "element", valpy_element, METH_VARARGS, "Obtains element inside value." },
+ { "get_element", valpy_get_element, METH_VARARGS,
+ "Obtains element inside value." },
{ "increment", valpy_increment, METH_VARARGS,
"Increment value by the given amount." },
{ "equals", valpy_equal_p, METH_VARARGS, "Compare values." },
@@ -133,7 +134,7 @@ valpy_dereference (PyObject *self, PyObject *args)
/* Takes value and string name of element inside that value. */
static PyObject *
-valpy_element (PyObject *self, PyObject *args)
+valpy_get_element (PyObject *self, PyObject *args)
{
value_object *self_value = (value_object *) self;
char *field;
@@ -300,10 +301,11 @@ valpy_common_print (PyObject *self, PyObject *args)
return PyInt_FromLong (ret);
}
-/* FIXME: clarify the naming to say the value
- won't be deleted by the Python code. */
+/* A value owned by GDB is in the all_values chain, so it will be freed
+ automatically when not needed anymore (i.e., before the current command
+ completes). */
PyObject *
-value_from_value (struct value *v)
+gdb_owned_value_to_value_object (struct value *v)
{
value_object *result = PyObject_New (value_object, &value_object_type);
if (result != NULL)
@@ -311,11 +313,16 @@ value_from_value (struct value *v)
result->value = v;
result->owned_by_gdb = 1;
/* FIXME: should we do it? What is it? */
+ /* I don't think it is needed, since a GDB owned value has a very short
+ lifetime. The purpose of the list is explained in the comment above
+ its declaration. -- bauermann */
value_prepend_to_list (&values_in_python, v);
}
return (PyObject *)result;
}
+/* Returns an object for a value which is released from the all_values chain,
+ so its lifetime is not bound to the execution of a command. */
PyObject *
value_to_value_object (struct value *v)
{
@@ -324,8 +331,15 @@ value_to_value_object (struct value *v)
VALPY_RETURN_VALUE (val_obj, v);
}
+struct value *
+value_object_to_value (PyObject *self)
+{
+ value_object *real = (value_object *)self;
+ return real->value;
+}
+
PyObject *
-gdb_value_from_int (PyObject *self, PyObject *args)
+gdbpy_make_value_from_int (PyObject *self, PyObject *args)
{
int i;
struct value *res_val = NULL; /* Initialize to appease gcc warning. */
@@ -345,7 +359,7 @@ gdb_value_from_int (PyObject *self, PyObject *args)
}
PyObject *
-gdb_value_from_history (PyObject *self, PyObject *args)
+gdbpy_get_value_from_history (PyObject *self, PyObject *args)
{
int i;
struct value *res_val = NULL; /* Initialize to appease gcc warning. */
@@ -376,10 +390,3 @@ gdbpy_initialize_values (void)
values_in_python = NULL;
}
-
-struct value *
-value_object_to_value (PyObject *self)
-{
- value_object *real = (value_object *)self;
- return real->value;
-} |
| |   |
| 857 | 857 | tuple = PyTuple_New (1); |
| 858 | 858 | back_to = make_cleanup_py_decref (tuple); |
| 859 | 859 | /* Steals the reference. */ |
| 860 | | PyTuple_SetItem (tuple, 0, value_from_value (var->value)); |
| 860 | PyTuple_SetItem (tuple, 0, gdb_owned_value_to_value_object (var->value)); |
| 861 | 861 | children = PyObject_Call (var->children_lister, tuple, Py_None); |
| 862 | 862 | make_cleanup_py_decref (children); |
| 863 | 863 | |
| … | … | |
| 2107 | 2107 | PyObject *py_s; |
| 2108 | 2108 | char *s; |
| 2109 | 2109 | |
| 2110 | | py_value = value_from_value (value); |
| 2110 | py_value = gdb_owned_value_to_value_object (value); |
| 2111 | 2111 | tuple = PyTuple_New (1); |
| 2112 | 2112 | back_to = make_cleanup_py_decref (tuple); |
| 2113 | 2113 | /* Steals the reference. */ |
| toggle raw diff |
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -857,7 +857,7 @@ int update_dynamic_varobj_children (struct varobj *var,
tuple = PyTuple_New (1);
back_to = make_cleanup_py_decref (tuple);
/* Steals the reference. */
- PyTuple_SetItem (tuple, 0, value_from_value (var->value));
+ PyTuple_SetItem (tuple, 0, gdb_owned_value_to_value_object (var->value));
children = PyObject_Call (var->children_lister, tuple, Py_None);
make_cleanup_py_decref (children);
@@ -2107,7 +2107,7 @@ value_get_print_value (struct value *value, enum varobj_display_formats format,
PyObject *py_s;
char *s;
- py_value = value_from_value (value);
+ py_value = gdb_owned_value_to_value_object (value);
tuple = PyTuple_New (1);
back_to = make_cleanup_py_decref (tuple);
/* Steals the reference. */ |