Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e02f2c5

Browse files
authored
Merge pull request #12569 from anntzer/uintptr_t
FIX: Don't confuse uintptr_t and Py_ssize_t.
2 parents 87aa310 + ecec979 commit e02f2c5

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

setupext.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,11 +1235,13 @@ def check(self):
12351235

12361236
def get_extension(self):
12371237
sources = [
1238-
'src/_tkagg.cpp'
1238+
'src/_tkagg.cpp',
1239+
'src/py_converters.cpp',
12391240
]
12401241

12411242
ext = make_extension('matplotlib.backends._tkagg', sources)
12421243
self.add_flags(ext)
1244+
Numpy().add_flags(ext)
12431245
LibAgg().add_flags(ext, add_sources=False)
12441246
return ext
12451247

src/_tkagg.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
// Include our own excerpts from the Tcl / Tk headers
1919
#include "_tkmini.h"
2020

21+
#include "py_converters.h"
22+
2123
#if defined(_MSC_VER)
2224
# define IMG_FORMAT "%d %d %Iu"
2325
#else
@@ -213,9 +215,9 @@ static PyObject *mpl_tk_blit(PyObject *self, PyObject *args)
213215
int x1, x2, y1, y2;
214216
Tk_PhotoHandle photo;
215217
Tk_PhotoImageBlock block;
216-
if (!PyArg_ParseTuple(args, "ns(iin)(iiii)(iiii):blit",
217-
&interp, &photo_name,
218-
&height, &width, &data_ptr,
218+
if (!PyArg_ParseTuple(args, "O&s(iiO&)(iiii)(iiii):blit",
219+
convert_voidptr, &interp, &photo_name,
220+
&height, &width, convert_voidptr, &data_ptr,
219221
&o0, &o1, &o2, &o3,
220222
&x1, &x2, &y1, &y2)) {
221223
goto exit;

src/py_converters.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ int convert_from_attr(PyObject *obj, const char *name, converter func, void *p)
9494
return 1;
9595
}
9696

97+
int convert_voidptr(PyObject *obj, void *p)
98+
{
99+
void **val = (void **)p;
100+
*val = PyLong_AsVoidPtr(obj);
101+
return *val != NULL ? 1 : !PyErr_Occurred();
102+
}
103+
97104
int convert_double(PyObject *obj, void *p)
98105
{
99106
double *val = (double *)p;

src/py_converters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef int (*converter)(PyObject *, void *);
2323
int convert_from_attr(PyObject *obj, const char *name, converter func, void *p);
2424
int convert_from_method(PyObject *obj, const char *name, converter func, void *p);
2525

26+
int convert_voidptr(PyObject *obj, void *p);
2627
int convert_double(PyObject *obj, void *p);
2728
int convert_bool(PyObject *obj, void *p);
2829
int convert_cap(PyObject *capobj, void *capp);

0 commit comments

Comments
 (0)