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: fix PyFrameObject definition #2424

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix FFI definition `PyGenObject` having multiple incorrect members on various Python versions. [#2423](https://github.com/PyO3/pyo3/pull/2423)
- Fix FFI definition `PySyntaxErrorObject` missing members `end_lineno` and `end_offset` on Python 3.10 and up. [#2423](https://github.com/PyO3/pyo3/pull/2423)
- Fix FFI definition `PyHeapTypeObject` missing member `ht_module` on Python 3.9 and up. [#2423](https://github.com/PyO3/pyo3/pull/2423)
- Fix FFI definition `PyFrameObject` having multiple incorrect members on various Python versions. [#2424](https://github.com/PyO3/pyo3/pull/2424)

## [0.16.5] - 2022-05-15

Expand Down
54 changes: 27 additions & 27 deletions pyo3-ffi/src/cpython/frameobject.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::cpython::code::{PyCodeObject, CO_MAXBLOCKS};
use crate::cpython::code::PyCodeObject;
use crate::object::*;
use crate::pystate::PyThreadState;
use std::os::raw::{c_char, c_int};

// skipped _framestate
// skipped PyFrameState

pub type PyFrameState = c_char;

#[repr(C)]
#[derive(Copy, Clone)]
Expand All @@ -14,41 +15,40 @@ pub struct PyTryBlock {
pub b_level: c_int,
}

/// struct _frame as typedef'ed in pyframe.h
#[repr(C)]
#[derive(Copy, Clone)]
#[cfg(not(Py_3_11))]
pub struct PyFrameObject {
pub ob_base: PyVarObject,
pub f_back: *mut PyFrameObject, /* previous frame, or NULL */
pub f_code: *mut PyCodeObject, /* code segment */
pub f_builtins: *mut PyObject, /* builtin symbol table (PyDictObject) */
pub f_globals: *mut PyObject, /* global symbol table (PyDictObject) */
pub f_locals: *mut PyObject, /* local symbol table (any mapping) */
pub f_valuestack: *mut *mut PyObject, /* points after the last local */
/* Next free slot in f_valuestack. Frame creation sets to f_valuestack.
Frame evaluation usually NULLs it, but a frame that yields sets it
to the current stack top. */
pub f_back: *mut PyFrameObject,
pub f_code: *mut PyCodeObject,
pub f_builtins: *mut PyObject,
pub f_globals: *mut PyObject,
pub f_locals: *mut PyObject,
pub f_valuestack: *mut *mut PyObject,

#[cfg(not(Py_3_10))]
pub f_stacktop: *mut *mut PyObject,
pub f_trace: *mut PyObject, /* Trace function */
pub f_trace: *mut PyObject,
pub f_stackdepth: c_int,
pub f_trace_lines: c_char,
pub f_trace_opcodes: c_char,

pub f_exc_type: *mut PyObject,
pub f_exc_value: *mut PyObject,
pub f_exc_traceback: *mut PyObject,
pub f_gen: *mut PyObject,

pub f_lasti: c_int, /* Last instruction if called */
/* Call PyFrame_GetLineNumber() instead of reading this field
directly. As of 2.3 f_lineno is only valid when tracing is
active (i.e. when f_trace is set). At other times we use
PyCode_Addr2Line to calculate the line from the current
bytecode index. */
pub f_lineno: c_int, /* Current line number */
pub f_iblock: c_int, /* index in f_blockstack */
pub f_executing: c_char, /* whether the frame is still executing */
pub f_blockstack: [PyTryBlock; CO_MAXBLOCKS], /* for try and loop blocks */
pub f_localsplus: [*mut PyObject; 1], /* locals+stack, dynamically sized */
pub f_lasti: c_int,
pub f_lineno: c_int,
pub f_iblock: c_int,
#[cfg(not(Py_3_10))]
pub f_executing: c_char,
pub f_state: PyFrameState,
pub f_blockstack: [PyTryBlock; crate::CO_MAXBLOCKS],
pub f_localsplus: [*mut PyObject; 1],
}

#[cfg(Py_3_11)]
opaque_struct!(PyFrameObject);

// skipped _PyFrame_IsRunnable
// skipped _PyFrame_IsExecuting
// skipped _PyFrameHasCompleted
Expand Down