From 0396ad6f77b69952b596c8550f45abe0f579cf78 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 22 Oct 2018 15:50:45 -0400 Subject: [PATCH] Backport PR #12569: Don't confuse uintptr_t and Py_ssize_t. --- setupext.py | 4 +++- src/_tkagg.cpp | 8 +++++--- src/py_converters.cpp | 7 +++++++ src/py_converters.h | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/setupext.py b/setupext.py index d52cfa3e7f40..a77f3dbac0b1 100644 --- a/setupext.py +++ b/setupext.py @@ -1363,11 +1363,13 @@ def check(self): def get_extension(self): sources = [ - 'src/_tkagg.cpp' + 'src/_tkagg.cpp', + 'src/py_converters.cpp', ] ext = make_extension('matplotlib.backends._tkagg', sources) self.add_flags(ext) + Numpy().add_flags(ext) LibAgg().add_flags(ext, add_sources=False) return ext diff --git a/src/_tkagg.cpp b/src/_tkagg.cpp index 5e51f6733357..431465ca3348 100644 --- a/src/_tkagg.cpp +++ b/src/_tkagg.cpp @@ -18,6 +18,8 @@ // Include our own excerpts from the Tcl / Tk headers #include "_tkmini.h" +#include "py_converters.h" + #if defined(_MSC_VER) # define IMG_FORMAT "%d %d %Iu" #else @@ -213,9 +215,9 @@ static PyObject *mpl_tk_blit(PyObject *self, PyObject *args) int x1, x2, y1, y2; Tk_PhotoHandle photo; Tk_PhotoImageBlock block; - if (!PyArg_ParseTuple(args, "ns(iin)(iiii)(iiii):blit", - &interp, &photo_name, - &height, &width, &data_ptr, + if (!PyArg_ParseTuple(args, "O&s(iiO&)(iiii)(iiii):blit", + convert_voidptr, &interp, &photo_name, + &height, &width, convert_voidptr, &data_ptr, &o0, &o1, &o2, &o3, &x1, &x2, &y1, &y2)) { goto exit; diff --git a/src/py_converters.cpp b/src/py_converters.cpp index 9119df6b6571..bb445c0794a7 100644 --- a/src/py_converters.cpp +++ b/src/py_converters.cpp @@ -94,6 +94,13 @@ int convert_from_attr(PyObject *obj, const char *name, converter func, void *p) return 1; } +int convert_voidptr(PyObject *obj, void *p) +{ + void **val = (void **)p; + *val = PyLong_AsVoidPtr(obj); + return *val != NULL ? 1 : !PyErr_Occurred(); +} + int convert_double(PyObject *obj, void *p) { double *val = (double *)p; diff --git a/src/py_converters.h b/src/py_converters.h index 64bdcb3f369f..ee38aacf4ca0 100644 --- a/src/py_converters.h +++ b/src/py_converters.h @@ -23,6 +23,7 @@ typedef int (*converter)(PyObject *, void *); int convert_from_attr(PyObject *obj, const char *name, converter func, void *p); int convert_from_method(PyObject *obj, const char *name, converter func, void *p); +int convert_voidptr(PyObject *obj, void *p); int convert_double(PyObject *obj, void *p); int convert_bool(PyObject *obj, void *p); int convert_cap(PyObject *capobj, void *capp);