matplotlib-3.4.3/matplotlib-3.4.3/src/_tkagg.cpp
void load_tkinter_funcs(void)
{
    // Load tkinter global funcs from tkinter compiled module.
    void *main_program = NULL, *tkinter_lib = NULL;
    PyObject *module = NULL, *py_path = NULL, *py_path_b = NULL;
    char *path;

    // Try loading from the main program namespace first.
    main_program = dlopen(NULL, RTLD_LAZY);
    if (load_tk(main_program)) {
        goto exit;
    }
    // Clear exception triggered when we didn't find symbols above.
    PyErr_Clear();

    // Handle PyPy first, as that import will correctly fail on CPython.
    module = PyImport_ImportModule("_tkinter.tklib_cffi");   // PyPy
    if (!module) {
        PyErr_Clear();
        module = PyImport_ImportModule("_tkinter");  // CPython
    }
    if (!(module &&
          (py_path = PyObject_GetAttrString(module, "__file__")) &&
          (py_path_b = PyUnicode_EncodeFSDefault(py_path)) &&
          (path = PyBytes_AsString(py_path_b)))) {
        goto exit;
    }
    tkinter_lib = dlopen(path, RTLD_LAZY);
    if (!tkinter_lib) {
        PyErr_SetString(PyExc_RuntimeError, dlerror());
        goto exit;
    }
    if (load_tk(tkinter_lib)) {
        goto exit;
    }

exit:
    // We don't need to keep a reference open as the main program & tkinter
    // have been imported.  Use a non-short-circuiting "or" to try closing both
    // handles before handling errors.
    if ((main_program && dlclose(main_program))
        | (tkinter_lib && dlclose(tkinter_lib))) {
        PyErr_SetString(PyExc_RuntimeError, dlerror());
    }
    Py_XDECREF(module);
    Py_XDECREF(py_path);
    Py_XDECREF(py_path_b);
}
/*
 * On Unix, we can get the Tk symbols from the tkinter module, because tkinter
 * uses these symbols, and the symbols are therefore visible in the tkinter
 * dynamic library (module).
 */
On Unix, we can get the Tk symbols from the tkinter module, because tkinter
uses these symbols, and the symbols are therefore visible in the tkinter
dynamic library (module).
On Unix we can get the Tk symbols from the tkinter module because tkinter uses these symbols and the symbols are therefore visible in the tkinter dynamic library ( module ) .
void load_tkinter_funcs(void)
{
    void *main_program = NULL, *tkinter_lib = NULL;
    PyObject *module = NULL, *py_path = NULL, *py_path_b = NULL;
    char *path;
    main_program = dlopen(NULL, RTLD_LAZY);
    if (load_tk(main_program)) {
        goto exit;
    }
    PyErr_Clear();
    module = PyImport_ImportModule("_tkinter.tklib_cffi");   
    if (!module) {
        PyErr_Clear();
        module = PyImport_ImportModule("_tkinter");  
    }
    if (!(module &&
          (py_path = PyObject_GetAttrString(module, "__file__")) &&
          (py_path_b = PyUnicode_EncodeFSDefault(py_path)) &&
          (path = PyBytes_AsString(py_path_b)))) {
        goto exit;
    }
    tkinter_lib = dlopen(path, RTLD_LAZY);
    if (!tkinter_lib) {
        PyErr_SetString(PyExc_RuntimeError, dlerror());
        goto exit;
    }
    if (load_tk(tkinter_lib)) {
        goto exit;
    }
exit:
    if ((main_program && dlclose(main_program))
        | (tkinter_lib && dlclose(tkinter_lib))) {
        PyErr_SetString(PyExc_RuntimeError, dlerror());
    }
    Py_XDECREF(module);
    Py_XDECREF(py_path);
    Py_XDECREF(py_path_b);
}
void load_tkinter_funcs ( void ) { void * main_program = NULL , * tkinter_lib = NULL ; PyObject * module = NULL , * py_path = NULL , * py_path_b = NULL ; char * path ; main_program = dlopen ( NULL , RTLD_LAZY ) ; if ( load_tk ( main_program ) ) { goto exit ; } PyErr_Clear ( ) ; module = PyImport_ImportModule ( " " ) ; if ( ! module ) { PyErr_Clear ( ) ; module = PyImport_ImportModule ( " " ) ; } if ( ! ( module && ( py_path = PyObject_GetAttrString ( module , " " ) ) && ( py_path_b = PyUnicode_EncodeFSDefault ( py_path ) ) && ( path = PyBytes_AsString ( py_path_b ) ) ) ) { goto exit ; } tkinter_lib = dlopen ( path , RTLD_LAZY ) ; if ( ! tkinter_lib ) { PyErr_SetString ( PyExc_RuntimeError , dlerror ( ) ) ; goto exit ; } if ( load_tk ( tkinter_lib ) ) { goto exit ; } exit : if ( ( main_program && dlclose ( main_program ) ) | ( tkinter_lib && dlclose ( tkinter_lib ) ) ) { PyErr_SetString ( PyExc_RuntimeError , dlerror ( ) ) ; } Py_XDECREF ( module ) ; Py_XDECREF ( py_path ) ; Py_XDECREF ( py_path_b ) ; }
On Unix, we can get the Tk symbols from the tkinter module, because tkinter
 uses these symbols, and the symbols are therefore visible in the tkinter
 dynamic library (module).
On Unix we can get the Tk symbols from the tkinter module because tkinter uses these symbols and the symbols are therefore visible in the tkinter dynamic library ( module ) .
// Load tkinter global funcs from tkinter compiled module. // Try loading from the main program namespace first. // Clear exception triggered when we didn't find symbols above. // Handle PyPy first, as that import will correctly fail on CPython. // PyPy // CPython // We don't need to keep a reference open as the main program & tkinter // have been imported.  Use a non-short-circuiting "or" to try closing both // handles before handling errors.