FIX: search for tkinter first in builtins

Python compiled from Python.org source builds the tkinter module as a
built-in module, not an external module, as is the case for the packaged
builds of Debian etc:

    >>> Tkinter.tkinter
    <module '_tkinter' (built-in)>

This breaks the current algorithm for searching for tkinter symbols,
which loaded the external module .so file to get the symbols.

Try searching in the main program namespace for the tkinter symbols,
before looking for the extermal module .so file.

Thanks to github user ettaka for reporting : see
https://github.com/matplotlib/matplotlib/issues/7428
This commit is contained in:
Matthew Brett 2016-11-09 08:58:12 -08:00
parent e768e7fa45
commit 92272f8195

View File

@ -438,10 +438,19 @@ int load_tkinter_funcs(void)
*/ */
int ret = -1; int ret = -1;
void *tkinter_lib; void *main_program, *tkinter_lib;
char *tkinter_libname; char *tkinter_libname;
PyObject *pModule = NULL, *pString = NULL; PyObject *pModule = NULL, *pString = NULL;
/* Try loading from the main program namespace first */
main_program = dlopen(NULL, RTLD_LAZY);
if (_func_loader(main_program) == 0) {
return 0;
}
/* Clear exception triggered when we didn't find symbols above */
PyErr_Clear();
/* Now try finding the tkinter compiled module */
pModule = PyImport_ImportModule(TKINTER_FINDER); pModule = PyImport_ImportModule(TKINTER_FINDER);
if (pModule == NULL) { if (pModule == NULL) {
goto exit; goto exit;