82 PyObject *unicode_str;
86 if (PyUnicode_Check (obj))
92 else if (PyString_Check (obj))
93 unicode_str = PyUnicode_FromEncodedObject (obj,
host_charset (), NULL);
97 PyErr_SetString (PyExc_TypeError,
98 _(
"Expected a string or unicode object."));
117 string = PyUnicode_AsEncodedString (unicode_str, charset, NULL);
122 result = xstrdup (PyBytes_AsString (
string));
124 result = xstrdup (PyString_AsString (
string));
140 return PyUnicode_AsEncodedString (unicode_str, charset, NULL);
231 return PyUnicode_Check (obj);
233 return PyString_Check (obj) || PyUnicode_Check (obj);
244 PyObject *str_obj = PyObject_Str (obj);
251 char *msg = xstrdup (PyString_AsString (str_obj));
282 if (pvalue && pvalue != Py_None)
300 exc_class = PyExc_KeyboardInterrupt;
306 PyErr_Format (exc_class,
"%s", exception.
message);
332 PyObject *num = PyNumber_Long (obj);
340 if (PyErr_Occurred ())
345 PyErr_SetString (PyExc_ValueError,
346 _(
"Overflow converting to address."));
363 if (
sizeof (l) >
sizeof (
long))
364 return PyLong_FromLongLong (l);
365 return PyLong_FromLong (l);
367 #ifdef HAVE_LONG_LONG
370 if (
sizeof (l) >
sizeof (
long)
371 && (l > PyInt_GetMax () || l < (- (
LONGEST) PyInt_GetMax ()) - 1))
372 return PyLong_FromLongLong (l);
374 return PyInt_FromLong (l);
385 if (
sizeof (l) >
sizeof (
unsigned long))
386 return PyLong_FromUnsignedLongLong (l);
387 return PyLong_FromUnsignedLong (l);
389 #ifdef HAVE_LONG_LONG
392 if (
sizeof (l) >
sizeof (
unsigned long) && l > PyInt_GetMax ())
393 return PyLong_FromUnsignedLongLong (l);
396 if (l > PyInt_GetMax ())
397 return PyLong_FromUnsignedLong (l);
399 return PyInt_FromLong (l);
409 *result = PyInt_AsLong (obj);
410 return ! (*result == -1 && PyErr_Occurred ());
423 PyTypeObject *type_obj = closure;
426 raw_ptr = (
char *)
self + type_obj->tp_dictoffset;
427 result = * (PyObject **) raw_ptr;
443 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)
int gdbpy_is_string(PyObject *obj)
unsigned long gdb_py_ulongest
char * gdbpy_obj_to_string(PyObject *obj)
PyObject * python_string_to_target_python_string(PyObject *obj)
char * python_string_to_target_string(PyObject *obj)
PyObject * python_string_to_unicode(PyObject *obj)
static char * unicode_to_encoded_string(PyObject *unicode_str, const char *charset)
struct cleanup * make_cleanup_py_xdecref(PyObject *py)
#define CATCH(EXCEPTION, MASK)
PyObject * gdb_py_object_from_longest(LONGEST l)
PyObject * gdbpy_gdb_error
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
char * python_string_to_host_string(PyObject *obj)
#define GDB_PY_SET_HANDLE_EXCEPTION(Exception)
struct gdbarch * python_gdbarch
char * unicode_to_target_string(PyObject *unicode_str)
int gdbpy_is_value_object(PyObject *obj)
static void py_xdecref(void *p)
static void py_decref(void *p)
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)
CORE_ADDR value_as_address(struct value *val)
struct value * value_object_to_value(PyObject *self)
const char * host_charset(void)
static PyObject * unicode_to_encoded_python_string(PyObject *unicode_str, const char *charset)
struct cleanup * make_cleanup_py_decref(PyObject *py)
char * gdbpy_exception_to_string(PyObject *ptype, PyObject *pvalue)
enum return_reason reason