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

Skip to content

Simplify tkagg C extension. #10936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2018
Merged

Simplify tkagg C extension. #10936

merged 1 commit into from
Jul 15, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Apr 1, 2018

PR Summary

(just making it quite a bit shorter...)

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added the GUI: tk label Apr 1, 2018
@anntzer anntzer added this to the v3.0 milestone Apr 1, 2018
@@ -265,20 +264,20 @@ int get_tk(HMODULE hMod)
if (TK_MAIN_WINDOW == NULL) { // Maybe not Tk module
return 0;
}
return ( // -1 if any remaining symbols are NULL
return // -1 if any remaining symbols are NULL
((TK_FIND_PHOTO = (Tk_FindPhoto_t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be clearer if these were a bunch of separate ifs instead of this long chained thing (if every assignment fit on one line, that would also be clearer.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'll be much simpler to do after #10680 is merged and we later get to remove the old version of the API. Then the only functions we'll have to load are Tk_FindPhoto and Tk_PhotoPutBlock_NoComposite, which also means that the Windows and non-Windows versions will only need to differ by how they call _dfunc.
Not convinced it's worth changing for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear, the endgame is to just do (e.g.)

void *_dfunc(void *lib_handle, const char *func_name);

int _func_loader(void *lib)
{
    // Fill global function pointers from dynamic lib.
    // Return number of successfully loaded functions.
    #define LOAD_TK(name) tk::name = Tk_##name##_t(_dfunc(lib, "Tk_" #name))
    return bool(LOAD_TK(FindPhoto)) + bool(LOAD_TK(PhotoPutBlock_NoComposite));
    #undef LOAD_TK
}

followed by OS-specific versions of _dfunc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#10680 is merged now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the old API is still around (the simplification will only come after matplotlib.backends.tkagg is completely removed).

@@ -296,17 +295,17 @@ int load_tkinter_funcs(void)
if (!found_tcl) {
found_tcl = get_tcl(hMods[i]);
if (found_tcl == -1) {
return 1;
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What error is set here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch... fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no, there is indeed an error being set by _dfunc()

void *_dfunc(void *lib_handle, const char *func_name)
{
    // Load function `func_name` from `lib_handle`.
    // Set Python exception if we can't find `func_name` in `lib_handle`.
    // Returns function pointer or NULL if not present.

    void* func;
    // Reset errors.
    dlerror();
    func = dlsym(lib_handle, func_name);
    if (func == NULL) {
        PyErr_SetString(PyExc_RuntimeError, dlerror());  // here
    }
    return func;
}

(and similarly on Windows).

Left the original version as is.

}
}
if (!found_tk) {
found_tk = get_tk(hMods[i]);
if (found_tk == -1) {
return 1;
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or here?

@@ -360,7 +348,7 @@ int _func_loader(void *lib)
{
// Fill global function pointers from dynamic lib.
// Return 1 if any pointer is NULL, 0 otherwise.
return (
return
((TCL_CREATE_COMMAND = (Tcl_CreateCommand_t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same split up here, probably.

@tacaswell tacaswell merged commit 677a3b2 into matplotlib:master Jul 15, 2018
@anntzer anntzer deleted the tkc branch July 15, 2018 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants