Skip to content
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

ffi:PyFrameObject doesn't match the structure in CPython #2411

Closed
alex opened this issue May 29, 2022 · 5 comments · Fixed by #2424
Closed

ffi:PyFrameObject doesn't match the structure in CPython #2411

alex opened this issue May 29, 2022 · 5 comments · Fixed by #2424
Labels

Comments

@alex
Copy link
Contributor

alex commented May 29, 2022

Bug Description

https://github.com/PyO3/pyo3/blob/main/pyo3-ffi/src/cpython/frameobject.rs#L20 is the ffi's definition PyFrameObject, however this doesn't match CPython's (3.8): https://github.com/python/cpython/blob/3.8/Include/frameobject.h#L16

Notably the f_exc_type, f_exc_value, f_exc_traceback fields were removed in 3.7 (I believe), and the f_trace_lines and f_trace_opcodes fields were added at some point.

Steps to Reproduce

  1. Look at the links I shared :-)

Any attempt to actually use these fields would result in UB/a segfault.

Backtrace

No response

Your operating system and version

all

Your Python version (python --version)

3.8

Your Rust version (rustc --version)

any

Your PyO3 version

HEAD

How did you install python? Did you use a virtualenv?

Not relevant

Additional Info

I suspect there are other places where the struct definitions do not match upstream. It may make sense to add some sort of test to CI to verify they match on all the configurations tested in CI. The simplest version might be simply verifying that struct sizes match.

@alex alex added the bug label May 29, 2022
@messense
Copy link
Member

messense commented Jun 1, 2022

Tried ctest2 but running into issue with its old libsyntax dependency that can not parse pyo3-ffi code.

@davidhewitt
Copy link
Member

It might be nice to use ctest2 in the future, for now I threw together https://github.com/davidhewitt/pyo3-ffi-check which crudely just checks the size of the generated structs, which will be much better having nothing. @messense if you think it makes sense, I'll transfer it to the PyO3 organisation.

Unfortunately it looks like we might have quite a few incorrect definitions! https://github.com/davidhewitt/pyo3-ffi-check/runs/6710130891?check_suite_focus=true

I'll get working on a patch to get some of those runs green :)

@alex
Copy link
Contributor Author

alex commented Jun 2, 2022 via email

@messense
Copy link
Member

messense commented Jun 2, 2022

Great work on pyo3-ffi-check, the ctest2 issue looks like won't be fixed soon, so it makes sense to take advantage of pyo3-ffi-check now.

@davidhewitt
Copy link
Member

👍 I'll move pyo3-ffi-check into the PyO3 org now!

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 a pull request may close this issue.

3 participants