-
Notifications
You must be signed in to change notification settings - Fork 792
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 module cleanup #1338
Merged
Merged
ffi module cleanup #1338
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e64b9b8
initial work to clean up ffi module
nw0 d9ec6bd
ffi: mirror cpython Includes
nw0 f802cae
ffi: start to alphebetise, note skipped headers
nw0 d6655f8
ffi: temporarily move _PyFrameEvalFunction back
nw0 7689534
ffi cleanup: fix pypy compilation
nw0 60a1b22
Update src/ffi/mod.rs
nw0 d002c7f
add suggested changes
nw0 4c26a2c
ffi cleanup: remove unnecessary use stmt
nw0 a465481
ffi cleanup: add deprecation warning
nw0 f49e9ee
ffi cleanup: transitively deprecate, update changelog
nw0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,156 +1,2 @@ | ||
use crate::ffi::object::*; | ||
use crate::ffi::pyport::Py_ssize_t; | ||
use std::os::raw::{c_char, c_int, c_uchar, c_void}; | ||
|
||
#[cfg(Py_3_8)] | ||
opaque_struct!(_PyOpcache); | ||
|
||
#[repr(C)] | ||
#[derive(Copy, Clone)] | ||
pub struct PyCodeObject { | ||
pub ob_base: PyObject, | ||
pub co_argcount: c_int, | ||
#[cfg(Py_3_8)] | ||
pub co_posonlyargcount: c_int, | ||
pub co_kwonlyargcount: c_int, | ||
pub co_nlocals: c_int, | ||
pub co_stacksize: c_int, | ||
pub co_flags: c_int, | ||
pub co_firstlineno: c_int, | ||
pub co_code: *mut PyObject, | ||
pub co_consts: *mut PyObject, | ||
pub co_names: *mut PyObject, | ||
pub co_varnames: *mut PyObject, | ||
pub co_freevars: *mut PyObject, | ||
pub co_cellvars: *mut PyObject, | ||
pub co_cell2arg: *mut c_uchar, | ||
pub co_filename: *mut PyObject, | ||
pub co_name: *mut PyObject, | ||
pub co_lnotab: *mut PyObject, | ||
pub co_zombieframe: *mut c_void, | ||
pub co_weakreflist: *mut PyObject, | ||
pub co_extra: *mut c_void, | ||
#[cfg(Py_3_8)] | ||
pub co_opcache_map: *mut c_uchar, | ||
#[cfg(Py_3_8)] | ||
pub co_opcache: *mut _PyOpcache, | ||
#[cfg(Py_3_8)] | ||
pub co_opcache_flag: c_int, | ||
#[cfg(Py_3_8)] | ||
pub co_opcache_size: c_uchar, | ||
} | ||
|
||
/* Masks for co_flags */ | ||
pub const CO_OPTIMIZED: c_int = 0x0001; | ||
pub const CO_NEWLOCALS: c_int = 0x0002; | ||
pub const CO_VARARGS: c_int = 0x0004; | ||
pub const CO_VARKEYWORDS: c_int = 0x0008; | ||
pub const CO_NESTED: c_int = 0x0010; | ||
pub const CO_GENERATOR: c_int = 0x0020; | ||
/* The CO_NOFREE flag is set if there are no free or cell variables. | ||
This information is redundant, but it allows a single flag test | ||
to determine whether there is any extra work to be done when the | ||
call frame it setup. | ||
*/ | ||
pub const CO_NOFREE: c_int = 0x0040; | ||
/* The CO_COROUTINE flag is set for coroutine functions (defined with | ||
``async def`` keywords) */ | ||
pub const CO_COROUTINE: c_int = 0x0080; | ||
pub const CO_ITERABLE_COROUTINE: c_int = 0x0100; | ||
pub const CO_ASYNC_GENERATOR: c_int = 0x0200; | ||
|
||
pub const CO_FUTURE_DIVISION: c_int = 0x2000; | ||
pub const CO_FUTURE_ABSOLUTE_IMPORT: c_int = 0x4000; /* do absolute imports by default */ | ||
pub const CO_FUTURE_WITH_STATEMENT: c_int = 0x8000; | ||
pub const CO_FUTURE_PRINT_FUNCTION: c_int = 0x1_0000; | ||
pub const CO_FUTURE_UNICODE_LITERALS: c_int = 0x2_0000; | ||
pub const CO_FUTURE_BARRY_AS_BDFL: c_int = 0x4_0000; | ||
pub const CO_FUTURE_GENERATOR_STOP: c_int = 0x8_0000; | ||
|
||
pub const CO_MAXBLOCKS: usize = 20; | ||
pub type FreeFunc = extern "C" fn(*mut c_void) -> c_void; | ||
|
||
#[cfg_attr(windows, link(name = "pythonXY"))] | ||
extern "C" { | ||
pub static mut PyCode_Type: PyTypeObject; | ||
} | ||
|
||
extern "C" { | ||
pub fn _PyCode_GetExtra( | ||
code: *mut PyObject, | ||
index: Py_ssize_t, | ||
extra: *const *mut c_void, | ||
) -> c_int; | ||
pub fn _PyCode_SetExtra(code: *mut PyObject, index: Py_ssize_t, extra: *mut c_void) -> c_int; | ||
|
||
#[cfg_attr(PyPy, link_name = "PyPyCode_New")] | ||
pub fn PyCode_New( | ||
argcount: c_int, | ||
kwonlyargcount: c_int, | ||
nlocals: c_int, | ||
stacksize: c_int, | ||
flags: c_int, | ||
code: *mut PyObject, | ||
consts: *mut PyObject, | ||
names: *mut PyObject, | ||
varnames: *mut PyObject, | ||
freevars: *mut PyObject, | ||
cellvars: *mut PyObject, | ||
filename: *mut PyObject, | ||
name: *mut PyObject, | ||
firstlineno: c_int, | ||
lnotab: *mut PyObject, | ||
) -> *mut PyCodeObject; | ||
#[cfg(Py_3_8)] | ||
pub fn PyCode_NewWithPosOnlyArgs( | ||
argcount: c_int, | ||
posonlyargcount: c_int, | ||
kwonlyargcount: c_int, | ||
nlocals: c_int, | ||
stacksize: c_int, | ||
flags: c_int, | ||
code: *mut PyObject, | ||
consts: *mut PyObject, | ||
names: *mut PyObject, | ||
varnames: *mut PyObject, | ||
freevars: *mut PyObject, | ||
cellvars: *mut PyObject, | ||
filename: *mut PyObject, | ||
name: *mut PyObject, | ||
firstlineno: c_int, | ||
lnotab: *mut PyObject, | ||
) -> *mut PyCodeObject; | ||
#[cfg_attr(PyPy, link_name = "PyPyCode_NewEmpty")] | ||
pub fn PyCode_NewEmpty( | ||
filename: *const c_char, | ||
funcname: *const c_char, | ||
firstlineno: c_int, | ||
) -> *mut PyCodeObject; | ||
pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int) -> c_int; | ||
pub fn PyCode_Optimize( | ||
code: *mut PyObject, | ||
consts: *mut PyObject, | ||
names: *mut PyObject, | ||
lnotab: *mut PyObject, | ||
) -> *mut PyObject; | ||
|
||
#[cfg(PyPy)] | ||
#[link_name = "PyPyCode_Check"] | ||
pub fn PyCode_Check(op: *mut PyObject) -> c_int; | ||
|
||
#[cfg(PyPy)] | ||
#[link_name = "PyPyCode_GetNumFree"] | ||
pub fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t; | ||
} | ||
|
||
#[inline] | ||
#[cfg(not(PyPy))] | ||
pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int { | ||
(Py_TYPE(op) == &mut PyCode_Type) as c_int | ||
} | ||
|
||
#[inline] | ||
#[cfg(not(PyPy))] | ||
pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t { | ||
crate::ffi::tupleobject::PyTuple_GET_SIZE((*op).co_freevars) | ||
} | ||
#[cfg(Py_LIMITED_API)] | ||
opaque_struct!(PyCodeObject); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't select the exact line, but PyEval_CallObjectWithKeywords is marked deprecated in 3.9. However, if I mark it with
#[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))]
, I can't compile due todeny(warnings)
on this crate (it's used byPyEval_CallObject
below).Maybe we could consider being a bit more specific with the crate's
deny
attribute? https://github.com/rust-unofficial/patterns/blob/master/anti_patterns/deny-warnings.mdThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I recently added this and I agree it's now an antipattern.
I've opened #1340 to remove the attribute.
As specifically here, I think we will need to put
#[allow(deprecated)]
on the call insidePyEval_CallObject
so that this passes CI. Mildly annoying, but hey!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, I think. I think the only gotcha is that we need to add the deprecation to
PyEval_CallObject
as well.