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

Skip to content

Commit 512e4d8

Browse files
committed
search for cffi c-extension module to find c-functions
1 parent 8e80a20 commit 512e4d8

3 files changed

Lines changed: 31 additions & 93 deletions

File tree

lib/matplotlib/backends/_tkagg.py

Lines changed: 0 additions & 78 deletions
This file was deleted.

lib/matplotlib/backends/tkagg.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ def blit(photoimage, aggimage, bbox=None, colormode=1):
2424
"PyAggImagePhoto", photoimage,
2525
dataptr, colormode, bboxptr)
2626
except Tk.TclError:
27-
try:
28-
try:
29-
_tkagg.tkinit(tk.interpaddr(), 1)
30-
except AttributeError:
31-
_tkagg.tkinit(tk, 0)
32-
tk.call("PyAggImagePhoto", photoimage,
33-
dataptr, colormode, bboxptr)
34-
except (ImportError, AttributeError, Tk.TclError):
35-
raise
27+
if hasattr(tk, 'interpaddr'):
28+
_tkagg.tkinit(tk.interpaddr(), 1)
29+
else:
30+
# very old python?
31+
_tkagg.tkinit(tk, 0)
32+
tk.call("PyAggImagePhoto", photoimage,
33+
dataptr, colormode, bboxptr)
3634

3735
def test(aggimage):
3836
import time

src/_tkagg.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static PyObject *_tkinit(PyObject *self, PyObject *args)
181181
} else {
182182
/* Do it the hard way. This will break if the TkappObject
183183
layout changes */
184-
app = (TkappObject *)PyLong_AsVoidPtr(arg);
184+
app = (TkappObject *)arg;
185185
interp = app->interp;
186186
}
187187

@@ -320,7 +320,7 @@ int load_tkinter_funcs(void)
320320
* tkinter uses these symbols, and the symbols are therefore visible in the
321321
* tkinter dynamic library (module).
322322
*/
323-
#if PY3K
323+
#if PY_MAJOR_VERSION >= 3
324324
#define TKINTER_PKG "tkinter"
325325
#define TKINTER_MOD "_tkinter"
326326
// From module __file__ attribute to char *string for dlopen.
@@ -414,13 +414,31 @@ int load_tkinter_funcs(void)
414414
}
415415
tkinter_lib = dlopen(tkinter_libname, RTLD_LAZY);
416416
if (tkinter_lib == NULL) {
417-
PyErr_SetString(PyExc_RuntimeError,
418-
"Cannot dlopen tkinter module file");
419-
goto exit;
417+
/* Perhaps it is a cffi module, like in PyPy? */
418+
pString = PyObject_GetAttrString(pSubmodule, "tklib_cffi");
419+
if (pString == NULL) {
420+
goto fail;
421+
}
422+
pString = PyObject_GetAttrString(pString, "__file__");
423+
if (pString == NULL) {
424+
goto fail;
425+
}
426+
tkinter_libname = fname2char(pString);
427+
if (tkinter_libname == NULL) {
428+
goto fail;
429+
}
430+
tkinter_lib = dlopen(tkinter_libname, RTLD_LAZY);
431+
}
432+
if (tkinter_lib == NULL) {
433+
goto fail;
420434
}
421435
ret = _func_loader(tkinter_lib);
422436
// dlclose probably safe because tkinter has been imported.
423437
dlclose(tkinter_lib);
438+
goto exit;
439+
fail:
440+
PyErr_SetString(PyExc_RuntimeError,
441+
"Cannot dlopen tkinter module file");
424442
exit:
425443
Py_XDECREF(pModule);
426444
Py_XDECREF(pSubmodule);
@@ -429,7 +447,7 @@ int load_tkinter_funcs(void)
429447
}
430448
#endif // end not Windows
431449

432-
#if PY3K
450+
#if PY_MAJOR_VERSION >= 3
433451
static PyModuleDef _tkagg_module = { PyModuleDef_HEAD_INIT, "_tkagg", "", -1, functions,
434452
NULL, NULL, NULL, NULL };
435453

0 commit comments

Comments
 (0)