joerick/pyinstrument

Python 3.11 compatibility

adriangb opened this issue · 2 comments

I have a project that uses pyinstrument as a dev dependency and it's failing to build on Python 3.11: https://github.com/adriangb/di/runs/6377204976?check_suite_focus=true#step:5:156

I can confirm this also happens locally with a simple pip install pyinstrument on 3.11.

Here's a copy of the error I get.

FWIW, Python's frame structures have changed in 3.11.

2022-06-13T21:49:33.6304500Z       running build_ext
2022-06-13T21:49:33.6304940Z       building 'pyinstrument.low_level.stat_profile' extension
2022-06-13T21:49:33.6305460Z       creating build/temp.macosx-10.15-x86_64-cpython-311
2022-06-13T21:49:33.6305970Z       creating build/temp.macosx-10.15-x86_64-cpython-311/pyinstrument
2022-06-13T21:49:33.6306520Z       creating build/temp.macosx-10.15-x86_64-cpython-311/pyinstrument/low_level
2022-06-13T21:49:33.6307580Z       gcc -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/usr/local/opt/sqlite/include -I/usr/local/opt/sqlite/include -I/Users/runner/hostedtoolcache/Python/3.11.0-beta.3/x64/include/python3.11 -c pyinstrument/low_level/stat_profile.c -o build/temp.macosx-10.15-x86_64-cpython-311/pyinstrument/low_level/stat_profile.o
2022-06-13T21:49:33.6308480Z       pyinstrument/low_level/stat_profile.c:301:43: error: incomplete definition of type 'struct _frame'
2022-06-13T21:49:33.6309530Z                   if (what == WHAT_CALL && frame->f_back) {
2022-06-13T21:49:33.6309820Z                                            ~~~~~^
2022-06-13T21:49:33.6310450Z       /Users/runner/hostedtoolcache/Python/3.11.0-beta.3/x64/include/python3.11/pytypedefs.h:22:16: note: forward declaration of 'struct _frame'
2022-06-13T21:49:33.6310890Z       typedef struct _frame PyFrameObject;
2022-06-13T21:49:33.6311190Z                      ^
2022-06-13T21:49:33.6311720Z       pyinstrument/low_level/stat_profile.c:302:45: error: incomplete definition of type 'struct _frame'
2022-06-13T21:49:33.6312240Z                       context_change_frame = frame->f_back;
2022-06-13T21:49:33.6312510Z                                              ~~~~~^
2022-06-13T21:49:33.6313100Z       /Users/runner/hostedtoolcache/Python/3.11.0-beta.3/x64/include/python3.11/pytypedefs.h:22:16: note: forward declaration of 'struct _frame'
2022-06-13T21:49:33.6313540Z       typedef struct _frame PyFrameObject;
2022-06-13T21:49:33.6313810Z                      ^
2022-06-13T21:49:33.6314060Z       2 errors generated.
2022-06-13T21:49:33.6314490Z       error: command '/usr/bin/gcc' failed with exit code 1
2022-06-13T21:49:33.6314730Z       [end of output]

I'll see if I can raise a PR today or tomorrow