diff --git a/gdb/python/py-block.c b/gdb/python/py-block.c index 280dbad8b04..50f1ab3fb83 100644 --- a/gdb/python/py-block.c +++ b/gdb/python/py-block.c @@ -147,8 +147,7 @@ PyObject* DictIter_iternext(PyObject *self) } static PyTypeObject DictIterType = { -PyObject_HEAD_INIT(NULL) -0, /*ob_size*/ +PyVarObject_HEAD_INIT (NULL, 0) "gdb._DictIter", /*tp_name*/ sizeof(DictIter), /*tp_basicsize*/ 0, /*tp_itemsize*/ @@ -174,8 +173,7 @@ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER, 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ DictIter_iter, /* tp_iter: __iter__() method */ -DictIter_iternext /* tp_iternext: next() method */, -.tp_new = PyType_GenericNew +DictIter_iternext /* tp_iternext: next() method */ }; static PyObject * @@ -538,6 +536,7 @@ gdbpy_initialize_blocks (void) if (PyType_Ready (&block_syms_iterator_object_type) < 0) return -1; + DictIterType.tp_new = PyType_GenericNew; if (PyType_Ready(&DictIterType) < 0) return -1; /* Register an objfile "free" callback so we can properly invalidate blocks when an object file is about to be diff --git a/gdb/python/py-minsymbol.c b/gdb/python/py-minsymbol.c index d98c9933e38..ac4f06cf485 100644 --- a/gdb/python/py-minsymbol.c +++ b/gdb/python/py-minsymbol.c @@ -319,6 +319,9 @@ gdbpy_lookup_minimal_symbol (PyObject *self, PyObject *args, PyObject *kw) static char *keywords[] = { "name", "sfile", "objfile", NULL }; struct bound_minimal_symbol bound_minsym = {}; PyObject *msym_obj = NULL, *sfile_obj = NULL, *objfile_obj = NULL; +#if PY_MAJOR_VERSION >= 3 + PyObject *temp = NULL; +#endif if (!PyArg_ParseTupleAndKeywords (args, kw, "s|OO", keywords, &name, &sfile_obj, &objfile_obj)) @@ -326,16 +329,33 @@ gdbpy_lookup_minimal_symbol (PyObject *self, PyObject *args, PyObject *kw) if (sfile_obj && sfile_obj != Py_None) { - sfile = PyString_AsString (sfile_obj); - if (!sfile) - return NULL; +#if PY_MAJOR_VERSION >= 3 + temp = PyUnicode_AsASCIIString(sfile_obj); + if (!temp) + return NULL; + + sfile = PyBytes_AsString(temp); +#else + sfile = PyString_AsString(sfile_obj); +#endif + + if (!sfile) { +#if PY_MAJOR_VERSION >= 3 + Py_DECREF(temp); +#endif + return NULL; + } } if (objfile_obj && objfile_obj != Py_None) { objfile = objfpy_object_to_objfile (objfile_obj); - if (!objfile) - return NULL; + if (!objfile) { +#if PY_MAJOR_VERSION >= 3 + Py_DECREF(temp); +#endif + return NULL; + } } TRY @@ -348,6 +368,10 @@ gdbpy_lookup_minimal_symbol (PyObject *self, PyObject *args, PyObject *kw) } END_CATCH +#if PY_MAJOR_VERSION >= 3 + Py_XDECREF(temp); +#endif + if (bound_minsym.minsym) msym_obj = bound_minsym_to_minsym_object (&bound_minsym); diff --git a/gdb/python/py-register.c b/gdb/python/py-register.c index c2dc62418cf..8281fd7bf0d 100644 --- a/gdb/python/py-register.c +++ b/gdb/python/py-register.c @@ -205,6 +205,7 @@ register_set_value(PyObject *self, PyObject *value_obj, void *closure) ret = write_register (regcache, obj->regnum, &ul_value); } } +#if PY_MAJOR_VERSION < 3 else if (PyInt_Check (value_obj)) { ul_value = PyInt_AsUnsignedLongMask (value_obj); @@ -216,6 +217,7 @@ register_set_value(PyObject *self, PyObject *value_obj, void *closure) ret = write_register (regcache, obj->regnum, &ul_value); } } +#endif else { value = value_object_to_value(value_obj); diff --git a/gdb/python/py-target.c b/gdb/python/py-target.c index 5e982a0087d..354fe23bd98 100644 --- a/gdb/python/py-target.c +++ b/gdb/python/py-target.c @@ -29,8 +29,8 @@ static PyObject *py_target_xfer_eof_error; static PyObject *py_target_xfer_unavailable_error; -extern PyTypeObject target_object_type - CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("target_object"); +extern PyTypeObject pytarget_object_type + CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("pytarget_object"); /* Require that Target operations are valid */ #define THPY_REQUIRE_VALID_RETURN(Target, ret) \ @@ -96,16 +96,16 @@ extern PyTypeObject target_object_type * This gives us the opportunity to find our Python Object when we are called * from C code */ -static target_object * target_ops_to_target_obj(struct target_ops *ops) +static pytarget_object * target_ops_to_target_obj(struct target_ops *ops) { - target_object *target_obj; + pytarget_object *target_obj; - if (ops->to_data == &target_object_type) { - target_obj = container_of(ops, target_object, python_ops); + if (ops->to_data == &pytarget_object_type) { + target_obj = container_of(ops, pytarget_object, python_ops); return target_obj; } - target_obj = PyObject_New (target_object, &target_object_type); + target_obj = PyObject_New (pytarget_object, &pytarget_object_type); if (target_obj) target_obj->ops = ops; @@ -135,7 +135,7 @@ static const char *py_target_to_thread_name (struct target_ops *ops, struct thread_info *info) { - target_object *target_obj = target_ops_to_target_obj (ops); + pytarget_object *target_obj = target_ops_to_target_obj (ops); PyObject *self = (PyObject *) target_obj; PyObject *arglist = NULL; PyObject *result = NULL; @@ -196,7 +196,7 @@ py_target_to_xfer_partial (struct target_ops *ops, gdb_byte *gdb_readbuf, const gdb_byte *gdb_writebuf, ULONGEST offset, ULONGEST len, ULONGEST *xfered_len) { - target_object *target_obj = target_ops_to_target_obj (ops); + pytarget_object *target_obj = target_ops_to_target_obj (ops); PyObject *self = (PyObject *) target_obj; PyObject *callback = NULL; PyObject *readbuf = NULL; @@ -306,7 +306,7 @@ static char * py_target_to_extra_thread_info (struct target_ops *ops, struct thread_info *info) { /* Note how we can obtain our Parent Python Object from the ops too */ - target_object *target_obj = target_ops_to_target_obj(ops); + pytarget_object *target_obj = target_ops_to_target_obj(ops); PyObject * self = (PyObject *)target_obj; struct cleanup *cleanup; @@ -322,7 +322,7 @@ py_target_to_extra_thread_info (struct target_ops *ops, struct thread_info *info static void py_target_to_update_thread_list (struct target_ops *ops) { - target_object *target_obj = target_ops_to_target_obj (ops); + pytarget_object *target_obj = target_ops_to_target_obj (ops); PyObject * self = (PyObject *) target_obj; PyObject *callback = NULL; PyObject *arglist = NULL; @@ -363,7 +363,7 @@ py_target_to_update_thread_list (struct target_ops *ops) static int py_target_to_thread_alive (struct target_ops *ops, ptid_t ptid) { - target_object *target_obj = target_ops_to_target_obj (ops); + pytarget_object *target_obj = target_ops_to_target_obj (ops); PyObject *self = (PyObject *) target_obj; PyObject *ptid_obj = NULL; PyObject *arglist = NULL; @@ -421,7 +421,7 @@ py_target_to_thread_alive (struct target_ops *ops, ptid_t ptid) static char *py_target_to_pid_to_str(struct target_ops *ops, ptid_t ptid) { /* Note how we can obtain our Parent Python Object from the ops too */ - target_object *target_obj = target_ops_to_target_obj (ops); + pytarget_object *target_obj = target_ops_to_target_obj (ops); PyObject *self = (PyObject *) target_obj; PyObject *ptid_obj = NULL; PyObject *arglist = NULL; @@ -477,7 +477,7 @@ static char *py_target_to_pid_to_str(struct target_ops *ops, ptid_t ptid) static void py_target_to_fetch_registers (struct target_ops *ops, struct regcache *regcache, int reg) { - target_object *target_obj = target_ops_to_target_obj (ops); + pytarget_object *target_obj = target_ops_to_target_obj (ops); PyObject * self = (PyObject *) target_obj; PyObject *arglist = NULL; PyObject *result = NULL; @@ -529,7 +529,7 @@ static void py_target_to_fetch_registers (struct target_ops *ops, static void py_target_to_prepare_to_store (struct target_ops *ops, struct regcache *regcache) { - target_object *target_obj = target_ops_to_target_obj (ops); + pytarget_object *target_obj = target_ops_to_target_obj (ops); PyObject * self = (PyObject *) target_obj; PyObject *arglist = NULL; PyObject *result = NULL; @@ -574,7 +574,7 @@ static void py_target_to_prepare_to_store (struct target_ops *ops, static void py_target_to_store_registers (struct target_ops *ops, struct regcache *regcache, int reg) { - target_object *target_obj = target_ops_to_target_obj (ops); + pytarget_object *target_obj = target_ops_to_target_obj (ops); PyObject * self = (PyObject *) target_obj; PyObject *arglist = NULL; PyObject *result = NULL; @@ -625,7 +625,7 @@ static void py_target_to_store_registers (struct target_ops *ops, static int py_target_to_has_execution (struct target_ops *ops, ptid_t ptid) { - target_object *target_obj = target_ops_to_target_obj (ops); + pytarget_object *target_obj = target_ops_to_target_obj (ops); PyObject * self = (PyObject *) target_obj; PyObject *arglist = NULL; PyObject *result = NULL; @@ -712,7 +712,7 @@ static void py_target_register_ops(struct target_ops * ops) ops->to_magic = OPS_MAGIC; - ops->to_data = &target_object_type; + ops->to_data = &pytarget_object_type; /* Install any remaining operations as delegators */ complete_target_initialization (ops); @@ -732,7 +732,7 @@ target_dealloc (PyObject *self) { ENTRY(); - // Py_DECREF (((target_object *) self)->inf_obj); + // Py_DECREF (((pytarget_object *) self)->inf_obj); // Decremement any references taken.... Py_TYPE (self)->tp_free (self); @@ -748,10 +748,11 @@ enum target_names { static PyObject * tgt_py_get_name (PyObject *self, void * arg) { - enum target_names target_string = (enum target_names) arg; - target_object *target_obj = (target_object *) self; + enum target_names target_string = (enum target_names) (intptr_t)arg; + pytarget_object *target_obj = (pytarget_object *) self; struct target_ops *ops = target_obj->ops; + PyObject *name; const char *shortname; @@ -789,8 +790,8 @@ tgt_py_get_name (PyObject *self, void * arg) static int tgt_py_set_name (PyObject *self, PyObject *newvalue, void * arg) { - enum target_names target_string = (enum target_names) arg; - target_object *target_obj = (target_object *) self; + enum target_names target_string = (enum target_names) (intptr_t)arg; + pytarget_object *target_obj = (pytarget_object *) self; struct target_ops *ops = target_obj->ops; char *name = NULL; @@ -845,7 +846,7 @@ static PyObject *target_getconst(PyObject *_self, void *_value) #define CONST_GET(x) {#x, target_getconst, NULL, #x, (void*)x} -static PyGetSetDef target_object_getset[] = +static PyGetSetDef pytarget_object_getset[] = { { "name", tgt_py_get_name, NULL, "The name of the target", (void*)TGT_NAME }, @@ -909,7 +910,7 @@ CONST_GET(TARGET_OBJECT_EXEC_FILE), static PyObject * tgtpy_default_to_thread_name (PyObject *self, PyObject *args) { - target_object *target_obj = (target_object *) self; + pytarget_object *target_obj = (pytarget_object *) self; PyObject * ThreadName; ENTRY(); @@ -921,7 +922,7 @@ tgtpy_default_to_thread_name (PyObject *self, PyObject *args) return ThreadName; } -static PyMethodDef target_object_methods[] = +static PyMethodDef pytarget_object_methods[] = { { "to_thread_name_int", tgtpy_default_to_thread_name, METH_VARARGS | METH_KEYWORDS, "to_thread_name (thread_info) -> String.\n\ @@ -936,8 +937,8 @@ Return string name representation of the given thread." }, static int target_init (PyObject *self, PyObject *args, PyObject *kw) { - target_object *target_obj = (target_object *) self; - + pytarget_object *target_obj = (pytarget_object *) self; + struct target_ops *ops = target_obj->ops; ENTRY(); TRY @@ -971,9 +972,9 @@ gdbpy_initialize_target (void) ENTRY(); /* Allow us to create instantiations of this class ... */ - target_object_type.tp_new = PyType_GenericNew; + pytarget_object_type.tp_new = PyType_GenericNew; - if (PyType_Ready (&target_object_type) < 0) + if (PyType_Ready (&pytarget_object_type) < 0) return -1; py_target_xfer_eof_error = PyErr_NewException ("gdb.TargetXferEOF", @@ -998,7 +999,7 @@ gdbpy_initialize_target (void) EXIT (); return gdb_pymodule_addobject (gdb_module, "Target", - (PyObject *) &target_object_type); + (PyObject *) &pytarget_object_type); fail: gdbpy_print_stack(); EXIT (); @@ -1010,11 +1011,11 @@ gdbpy_initialize_target (void) -PyTypeObject target_object_type = +PyTypeObject pytarget_object_type = { PyVarObject_HEAD_INIT (NULL, 0) "gdb.Target", /*tp_name*/ - sizeof (target_object), /*tp_basicsize*/ + sizeof (pytarget_object), /*tp_basicsize*/ 0, /*tp_itemsize*/ target_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ @@ -1039,9 +1040,9 @@ PyTypeObject target_object_type = 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ - target_object_methods, /* tp_methods */ + pytarget_object_methods, /* tp_methods */ 0, /* tp_members */ - target_object_getset, /* tp_getset */ + pytarget_object_getset, /* tp_getset */ 0, /* tp_base */ 0, /* tp_dict */ 0, /* tp_descr_get */ @@ -1055,9 +1056,9 @@ PyObject * gdbpy_current_target (PyObject *self, PyObject *args) { struct target_ops *ops = current_target.beneath; - target_object *obj = target_ops_to_target_obj(ops); + pytarget_object *obj = target_ops_to_target_obj(ops); - if (obj->ops->to_data == &target_object_type) + if (obj->ops->to_data == &pytarget_object_type) Py_INCREF(obj); return (PyObject *)obj; diff --git a/gdb/python/py-target.h b/gdb/python/py-target.h index 69a24d2239d..85e811cba09 100644 --- a/gdb/python/py-target.h +++ b/gdb/python/py-target.h @@ -31,6 +31,6 @@ typedef struct struct target_ops python_ops; -} target_object; +} pytarget_object; #endif /* GDB_PY_TARGET_H */