Skip to content

[Bug]: Couldn't build matplotlib 3.6.0 with both Clang-15 and GCC-12 #23943

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

Closed
MehdiChinoune opened this issue Sep 19, 2022 · 4 comments · Fixed by #23947
Closed

[Bug]: Couldn't build matplotlib 3.6.0 with both Clang-15 and GCC-12 #23943

MehdiChinoune opened this issue Sep 19, 2022 · 4 comments · Fixed by #23947
Milestone

Comments

@MehdiChinoune
Copy link
Contributor

Bug summary

It fails to build with Clang-15 and GCC-12
Clang:

  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -march=x86-64 -mtune=generic -O2 -pipe -O3 -march=x86-64 -mtune=generic -O2 -pipe -O3 -march=x86-64 -mtune=generic -O2 -pipe -D__USE_MINGW_ANSI_STDIO=1 -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib_backends__tkagg_ARRAY_API -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -D__STDC_FORMAT_MACROS=1 -Iextern/agg24-svn/include -Isrc -ID:/M/msys64/clang64/lib/python3.10/site-packages/numpy/core/include -ID:/M/msys64/clang64/include/python3.10 -c src/_tkagg.cpp -o build/temp.mingw_x86_64_clang-3.10/matplotlib.backends._tkagg/src/_tkagg.o
  src/_tkagg.cpp:234:15: error: cannot initialize a variable of type 'void *' with an rvalue of type 'FARPROC' (aka 'long long (*)()')
      if (void* ptr = dlsym(lib, "Tcl_SetVar")) {
                ^     ~~~~~~~~~~~~~~~~~~~~~~~~
  src/_tkagg.cpp:273:13: note: in instantiation of function template specialization 'load_tcl_tk<HINSTANCE__ *>' requested here
          if (load_tcl_tk(modules[i])) {
              ^
  src/_tkagg.cpp:237:15: error: cannot initialize a variable of type 'void *' with an rvalue of type 'FARPROC' (aka 'long long (*)()')
      if (void* ptr = dlsym(lib, "Tk_FindPhoto")) {
                ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~
  src/_tkagg.cpp:240:15: error: cannot initialize a variable of type 'void *' with an rvalue of type 'FARPROC' (aka 'long long (*)()')
      if (void* ptr = dlsym(lib, "Tk_PhotoPutBlock")) {
                ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3 errors generated.

GCC:

  gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -march=x86-64 -mtune=generic -O2 -pipe -O3 -march=x86-64 -mtune=generic -O2 -pipe -O3 -march=x86-64 -mtune=generic -O2 -pipe -D__USE_MINGW_ANSI_STDIO=1 -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib_backends__tkagg_ARRAY_API -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -D__STDC_FORMAT_MACROS=1 -Iextern/agg24-svn/include -Isrc -ID:/M/msys64/ucrt64/lib/python3.10/site-packages/numpy/core/include -ID:/M/msys64/ucrt64/include/python3.10 -c src/_tkagg.cpp -o build/temp.mingw_x86_64_ucrt-3.10/matplotlib.backends._tkagg/src/_tkagg.o
  src/_tkagg.cpp: In instantiation of 'bool load_tcl_tk(T) [with T = HINSTANCE__*]':
  src/_tkagg.cpp:273:24:   required from here
  src/_tkagg.cpp:234:26: error: invalid conversion from 'FARPROC' {aka 'long long int (*)()'} to 'void*' [-fpermissive]
    234 |     if (void* ptr = dlsym(lib, "Tcl_SetVar")) {
        |                          ^
        |                          |
        |                          FARPROC {aka long long int (*)()}
  src/_tkagg.cpp:237:26: error: invalid conversion from 'FARPROC' {aka 'long long int (*)()'} to 'void*' [-fpermissive]
    237 |     if (void* ptr = dlsym(lib, "Tk_FindPhoto")) {
        |                          ^
        |                          |
        |                          FARPROC {aka long long int (*)()}
  src/_tkagg.cpp:240:26: error: invalid conversion from 'FARPROC' {aka 'long long int (*)()'} to 'void*' [-fpermissive]
    240 |     if (void* ptr = dlsym(lib, "Tk_PhotoPutBlock")) {
        |                          ^
        |                          |
        |                          FARPROC {aka long long int (*)()}

Code for reproduction

No code required

Actual outcome

Building succeeds

Expected outcome

Building fails

Additional information

No response

Operating system

No response

Matplotlib Version

3.6.0

Matplotlib Backend

No response

Python version

3.10.7

Jupyter version

No response

Installation

No response

@tacaswell tacaswell added this to the v3.7.0 milestone Sep 19, 2022
@tacaswell
Copy link
Member

I have been compiling in linux with gcc 12 without a problem.

It seems that FARPROC is a windows thing: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-callwindowprocw

@MehdiChinoune Do you understand what changed in gcc / clang to make this code fail? Do we need a windows specific version of this function?

@MehdiChinoune
Copy link
Contributor Author

It seems that FARPROC is a windows thing: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-callwindowprocw

@MehdiChinoune Do you understand what changed in gcc / clang to make this code fail? Do we need a windows specific version of this function?

Nothing has changed. the previous version (3.5.3) could be built by both gcc-12 and clang-14, It is matplotlib that changed in e1fcc90

@MehdiChinoune
Copy link
Contributor Author

proposed patch

--- a/src/_tkagg.cpp
+++ b/src/_tkagg.cpp
@@ -231,13 +231,13 @@
 {
     // Try to fill Tcl/Tk global vars with function pointers.  Return whether
     // all of them have been filled.
-    if (void* ptr = dlsym(lib, "Tcl_SetVar")) {
+    if (auto ptr = dlsym(lib, "Tcl_SetVar")) {
         TCL_SETVAR = (Tcl_SetVar_t)ptr;
     }
-    if (void* ptr = dlsym(lib, "Tk_FindPhoto")) {
+    if (auto ptr = dlsym(lib, "Tk_FindPhoto")) {
         TK_FIND_PHOTO = (Tk_FindPhoto_t)ptr;
     }
-    if (void* ptr = dlsym(lib, "Tk_PhotoPutBlock")) {
+    if (auto ptr = dlsym(lib, "Tk_PhotoPutBlock")) {
         TK_PHOTO_PUT_BLOCK = (Tk_PhotoPutBlock_t)ptr;
     }
     return TCL_SETVAR && TK_FIND_PHOTO && TK_PHOTO_PUT_BLOCK;

@QuLogic QuLogic modified the milestones: v3.7.0, v3.6.1 Sep 19, 2022
@tacaswell
Copy link
Member

Nothing has changed.

🐑 fair enough. I forgot we had done some work on that file, sorry for answering without doing my due diligence of checking git-blame.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants