40 PyObject *unicode_str;
44 if (PyUnicode_Check (obj))
50 else if (PyString_Check (obj))
51 unicode_str = PyUnicode_FromEncodedObject (obj,
host_charset (), NULL);
55 PyErr_SetString (PyExc_TypeError,
56 _(
"Expected a string or unicode object."));
79 result.reset (xstrdup (PyBytes_AsString (
string.
get ())));
81 result.reset (xstrdup (PyString_AsString (
string.
get ())));
95 return PyUnicode_AsEncodedString (unicode_str, charset, NULL);
166 return PyString_Decode (str, strlen (str),
host_charset (), NULL);
176 return PyUnicode_Check (obj);
178 return PyString_Check (obj) || PyUnicode_Check (obj);
197 msg.reset (xstrdup (PyString_AsString (str_obj.
get ())));
224 if (pvalue && pvalue != Py_None)
240 exc_class = PyExc_KeyboardInterrupt;
246 PyErr_Format (exc_class,
"%s", exception.
message);
279 if (PyErr_Occurred ())
284 PyErr_SetString (PyExc_ValueError,
285 _(
"Overflow converting to address."));
302 if (
sizeof (l) >
sizeof (
long))
303 return PyLong_FromLongLong (l);
304 return PyLong_FromLong (l);
306 #ifdef HAVE_LONG_LONG 309 if (
sizeof (l) >
sizeof (
long)
310 && (l > PyInt_GetMax () || l < (- (
LONGEST) PyInt_GetMax ()) - 1))
311 return PyLong_FromLongLong (l);
313 return PyInt_FromLong (l);
324 if (
sizeof (l) >
sizeof (
unsigned long))
325 return PyLong_FromUnsignedLongLong (l);
326 return PyLong_FromUnsignedLong (l);
328 #ifdef HAVE_LONG_LONG 331 if (
sizeof (l) >
sizeof (
unsigned long) && l > PyInt_GetMax ())
332 return PyLong_FromUnsignedLongLong (l);
335 if (l > PyInt_GetMax ())
336 return PyLong_FromUnsignedLong (l);
338 return PyInt_FromLong (l);
348 *result = PyInt_AsLong (obj);
349 return ! (*result == -1 && PyErr_Occurred ());
362 PyTypeObject *type_obj = (PyTypeObject *) closure;
365 raw_ptr = (
char *)
self + type_obj->tp_dictoffset;
366 result = * (PyObject **) raw_ptr;
382 result = PyModule_AddObject (module, (
char *)
name,
object);
int gdb_pymodule_addobject(PyObject *module, const char *name, PyObject *object)
const char * target_charset(struct gdbarch *gdbarch)
PyObject * gdb_py_generic_dict(PyObject *self, void *closure)
gdb::unique_xmalloc_ptr< char > gdbpy_obj_to_string(PyObject *obj)
int gdbpy_is_string(PyObject *obj)
unsigned long gdb_py_ulongest
PyObject * python_string_to_target_python_string(PyObject *obj)
PyObject * python_string_to_unicode(PyObject *obj)
static gdb::unique_xmalloc_ptr< char > unicode_to_encoded_string(PyObject *unicode_str, const char *charset)
PyObject * host_string_to_python_string(const char *str)
#define CATCH(EXCEPTION, MASK)
std::unique_ptr< T, xfree_deleter< T > > unique_xmalloc_ptr
PyObject * gdb_py_object_from_longest(LONGEST l)
PyObject * gdbpy_gdb_error
gdb::unique_xmalloc_ptr< char > unicode_to_target_string(PyObject *unicode_str)
#define GDB_PY_SET_HANDLE_EXCEPTION(Exception)
struct gdbarch * python_gdbarch
gdb::unique_xmalloc_ptr< char > python_string_to_host_string(PyObject *obj)
int gdbpy_is_value_object(PyObject *obj)
PyObject * gdb_py_object_from_ulongest(ULONGEST l)
void gdbpy_convert_exception(struct gdb_exception exception)
static PyObject * unicode_to_target_python_string(PyObject *unicode_str)
PyObject * gdbpy_gdb_memory_error
#define gdb_py_long_as_ulongest
unsigned long long ULONGEST
int gdb_py_int_as_long(PyObject *obj, long *result)
int get_addr_from_python(PyObject *obj, CORE_ADDR *addr)
gdb::unique_xmalloc_ptr< char > gdbpy_exception_to_string(PyObject *ptype, PyObject *pvalue)
CORE_ADDR value_as_address(struct value *val)
struct value * value_object_to_value(PyObject *self)
gdb::unique_xmalloc_ptr< char > python_string_to_target_string(PyObject *obj)
const char * host_charset(void)
static PyObject * unicode_to_encoded_python_string(PyObject *unicode_str, const char *charset)
enum return_reason reason