Skip to content

Commit d26105c

Browse files
authored
Merge pull request #2 from lorddoskias/pytarget-py3-support
Pytarget py3 support
2 parents 4858ec1 + 0f11186 commit d26105c

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

gdb/python/py-block.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ PyObject* DictIter_iternext(PyObject *self)
147147
}
148148

149149
static PyTypeObject DictIterType = {
150-
PyObject_HEAD_INIT(NULL)
151-
0, /*ob_size*/
150+
PyVarObject_HEAD_INIT (NULL, 0)
152151
"gdb._DictIter", /*tp_name*/
153152
sizeof(DictIter), /*tp_basicsize*/
154153
0, /*tp_itemsize*/
@@ -174,8 +173,7 @@ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
174173
0, /* tp_richcompare */
175174
0, /* tp_weaklistoffset */
176175
DictIter_iter, /* tp_iter: __iter__() method */
177-
DictIter_iternext /* tp_iternext: next() method */,
178-
.tp_new = PyType_GenericNew
176+
DictIter_iternext /* tp_iternext: next() method */
179177
};
180178

181179
static PyObject *
@@ -538,6 +536,7 @@ gdbpy_initialize_blocks (void)
538536
if (PyType_Ready (&block_syms_iterator_object_type) < 0)
539537
return -1;
540538

539+
DictIterType.tp_new = PyType_GenericNew;
541540
if (PyType_Ready(&DictIterType) < 0) return -1;
542541
/* Register an objfile "free" callback so we can properly
543542
invalidate blocks when an object file is about to be

gdb/python/py-minsymbol.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,23 +319,43 @@ gdbpy_lookup_minimal_symbol (PyObject *self, PyObject *args, PyObject *kw)
319319
static char *keywords[] = { "name", "sfile", "objfile", NULL };
320320
struct bound_minimal_symbol bound_minsym = {};
321321
PyObject *msym_obj = NULL, *sfile_obj = NULL, *objfile_obj = NULL;
322+
#if PY_MAJOR_VERSION >= 3
323+
PyObject *temp = NULL;
324+
#endif
322325

323326
if (!PyArg_ParseTupleAndKeywords (args, kw, "s|OO", keywords, &name,
324327
&sfile_obj, &objfile_obj))
325328
return NULL;
326329

327330
if (sfile_obj && sfile_obj != Py_None)
328331
{
329-
sfile = PyString_AsString (sfile_obj);
330-
if (!sfile)
331-
return NULL;
332+
#if PY_MAJOR_VERSION >= 3
333+
temp = PyUnicode_AsASCIIString(sfile_obj);
334+
if (!temp)
335+
return NULL;
336+
337+
sfile = PyBytes_AsString(temp);
338+
#else
339+
sfile = PyString_AsString(sfile_obj);
340+
#endif
341+
342+
if (!sfile) {
343+
#if PY_MAJOR_VERSION >= 3
344+
Py_DECREF(temp);
345+
#endif
346+
return NULL;
347+
}
332348
}
333349

334350
if (objfile_obj && objfile_obj != Py_None)
335351
{
336352
objfile = objfpy_object_to_objfile (objfile_obj);
337-
if (!objfile)
338-
return NULL;
353+
if (!objfile) {
354+
#if PY_MAJOR_VERSION >= 3
355+
Py_DECREF(temp);
356+
#endif
357+
return NULL;
358+
}
339359
}
340360

341361
TRY
@@ -348,6 +368,10 @@ gdbpy_lookup_minimal_symbol (PyObject *self, PyObject *args, PyObject *kw)
348368
}
349369
END_CATCH
350370

371+
#if PY_MAJOR_VERSION >= 3
372+
Py_XDECREF(temp);
373+
#endif
374+
351375
if (bound_minsym.minsym)
352376
msym_obj = bound_minsym_to_minsym_object (&bound_minsym);
353377

gdb/python/py-register.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ register_set_value(PyObject *self, PyObject *value_obj, void *closure)
205205
ret = write_register (regcache, obj->regnum, &ul_value);
206206
}
207207
}
208+
#if PY_MAJOR_VERSION < 3
208209
else if (PyInt_Check (value_obj))
209210
{
210211
ul_value = PyInt_AsUnsignedLongMask (value_obj);
@@ -216,6 +217,7 @@ register_set_value(PyObject *self, PyObject *value_obj, void *closure)
216217
ret = write_register (regcache, obj->regnum, &ul_value);
217218
}
218219
}
220+
#endif
219221
else
220222
{
221223
value = value_object_to_value(value_obj);

gdb/python/py-target.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,11 @@ enum target_names {
748748
static PyObject *
749749
tgt_py_get_name (PyObject *self, void * arg)
750750
{
751-
enum target_names target_string = (enum target_names) (unsigned long)arg;
751+
enum target_names target_string = (enum target_names) (intptr_t)arg;
752752
pytarget_object *target_obj = (pytarget_object *) self;
753753
struct target_ops *ops = target_obj->ops;
754754

755+
755756
PyObject *name;
756757

757758
const char *shortname;
@@ -789,7 +790,7 @@ tgt_py_get_name (PyObject *self, void * arg)
789790
static int
790791
tgt_py_set_name (PyObject *self, PyObject *newvalue, void * arg)
791792
{
792-
enum target_names target_string = (enum target_names)(unsigned long) arg;
793+
enum target_names target_string = (enum target_names) (intptr_t)arg;
793794
pytarget_object *target_obj = (pytarget_object *) self;
794795
struct target_ops *ops = target_obj->ops;
795796
char *name = NULL;

0 commit comments

Comments
 (0)