@@ -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" );
424442exit:
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
433451static PyModuleDef _tkagg_module = { PyModuleDef_HEAD_INIT, " _tkagg" , " " , -1 , functions,
434452 NULL , NULL , NULL , NULL };
435453
0 commit comments