Skip to content

Commit 0f11186

Browse files
committed
gdb/py-target: Make the code compile against python3
* This is a first step in supporting python3 version. Most of the changes cope with the fact that there is no longer a PyString_* object. Instead there is either PyUnicode or PyBytes. In order to obtain a char* one must first convert the PyUnicode object to PyBytes, representing a byte array. And then get a pointer to the byte array. * Another thing is that there is no longer a PyInt. Everything is PyLong, so comment out a PyInt check in register_set_value. (cherry picked from commit 6c1337293ad98d6178b3d6c2f21edbe74e967e22)
1 parent df02ecb commit 0f11186

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

gdb/python/py-block.c

Lines changed: 1 addition & 2 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*/

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);

0 commit comments

Comments
 (0)