-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Simplify tkagg C extension. #10936
Conversation
@@ -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) |
There was a problem hiding this comment.
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 if
s instead of this long chained thing (if every assignment fit on one line, that would also be clearer.)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#10680 is merged now.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch... fixed.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
PR Summary
(just making it quite a bit shorter...)
PR Checklist