Skip to content

Commit

Permalink
Added missing field to PyCodeObject. Changed definitions on the struct
Browse files Browse the repository at this point in the history
condition to be smarter (any versions that are above 3.7 (not
including))
  • Loading branch information
Aviram Hassan committed Oct 24, 2020
1 parent 33ec5b5 commit 9d2e7b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Fix missing field in `PyCodeObject` struct (`co_posonlyargcount`) - caused invalid access to other fields in Python >3.7. [#1260](https://github.com/PyO3/pyo3/pull/1260)
### Packaging
- Drop support for Python 3.5 (as it is now end-of-life). [#1250](https://github.com/PyO3/pyo3/pull/1250)

Expand Down
12 changes: 7 additions & 5 deletions src/ffi/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub enum _PyOpcache {}
pub struct PyCodeObject {
pub ob_base: PyObject,
pub co_argcount: c_int,
#[cfg(not(any(Py_3_7, Py_3_6)))]
pub co_posonlyargcount: c_int,
pub co_kwonlyargcount: c_int,
pub co_nlocals: c_int,
pub co_stacksize: c_int,
Expand All @@ -28,13 +30,13 @@ pub struct PyCodeObject {
pub co_zombieframe: *mut c_void,
pub co_weakreflist: *mut PyObject,
pub co_extra: *mut c_void,
#[cfg(Py_3_8)]
#[cfg(not(any(Py_3_7, Py_3_6)))]
pub co_opcache_map: *mut c_uchar,
#[cfg(Py_3_8)]
#[cfg(not(any(Py_3_7, Py_3_6)))]
pub co_opcache: *mut _PyOpcache,
#[cfg(Py_3_8)]
#[cfg(not(any(Py_3_7, Py_3_6)))]
pub co_opcache_flag: c_int,
#[cfg(Py_3_8)]
#[cfg(not(any(Py_3_7, Py_3_6)))]
pub co_opcache_size: c_uchar,
}

Expand Down Expand Up @@ -99,7 +101,7 @@ extern "C" {
firstlineno: c_int,
lnotab: *mut PyObject,
) -> *mut PyCodeObject;
#[cfg(Py_3_8)]
#[cfg(not(any(Py_3_7, Py_3_6)))]
pub fn PyCode_NewWithPosOnlyArgs(
argcount: c_int,
posonlyargcount: c_int,
Expand Down

0 comments on commit 9d2e7b9

Please sign in to comment.