Add gdb.Value.assign method

This adds an 'assign' method to gdb.Value.  This allows for assignment
without requiring the use of parse_and_eval.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
This commit is contained in:
Tom Tromey
2023-05-12 14:10:56 -06:00
parent 510586589e
commit ed80156930
4 changed files with 52 additions and 0 deletions

View File

@ -853,6 +853,33 @@ valpy_reinterpret_cast (PyObject *self, PyObject *args)
return valpy_do_cast (self, args, UNOP_REINTERPRET_CAST);
}
/* Implementation of the "assign" method. */
static PyObject *
valpy_assign (PyObject *self_obj, PyObject *args)
{
PyObject *val_obj;
if (! PyArg_ParseTuple (args, "O", &val_obj))
return nullptr;
struct value *val = convert_value_from_python (val_obj);
if (val == nullptr)
return nullptr;
try
{
value_object *self = (value_object *) self_obj;
value_assign (self->value, val);
}
catch (const gdb_exception &except)
{
GDB_PY_HANDLE_EXCEPTION (except);
}
Py_RETURN_NONE;
}
static Py_ssize_t
valpy_length (PyObject *self)
{
@ -2119,6 +2146,9 @@ Return Unicode string representation of the value." },
"format_string (...) -> string\n\
Return a string representation of the value using the specified\n\
formatting options" },
{ "assign", (PyCFunction) valpy_assign, METH_VARARGS,
"assign (VAL) -> None\n\
Assign VAL to this value." },
{NULL} /* Sentinel */
};