int get_addr_from_python (PyObject *obj, CORE_ADDR *addr) { if (gdbpy_is_value_object (obj)) *addr = value_as_address (value_object_to_value (obj)); else { PyObject *num = PyNumber_Long (obj); gdb_py_ulongest val; if (num == NULL) return 0; val = gdb_py_long_as_ulongest (num); Py_XDECREF (num); if (PyErr_Occurred ()) return 0; if (sizeof (val) > sizeof (CORE_ADDR) && ((CORE_ADDR) val) != val) { PyErr_SetString (PyExc_ValueError, _("Overflow converting to address.")); return 0; } *addr = val; } return 1; }
int get_addr_from_python (PyObject *obj, CORE_ADDR *addr) { if (gdbpy_is_value_object (obj)) *addr = value_as_address (value_object_to_value (obj)); else if (PyLong_Check (obj)) { /* Assume CORE_ADDR corresponds to unsigned long. */ *addr = PyLong_AsUnsignedLong (obj); if (PyErr_Occurred () != NULL) return 0; } else if (PyInt_Check (obj)) { long val; /* Assume CORE_ADDR corresponds to unsigned long. */ val = PyInt_AsLong (obj); if (val >= 0) *addr = val; else { /* If no error ocurred, VAL is indeed negative. */ if (PyErr_Occurred () != NULL) return 0; PyErr_SetString (PyExc_ValueError, _("Supplied address is negative.")); return 0; } } else { PyErr_SetString (PyExc_TypeError, _("Invalid type for address.")); return 0; } return 1; }