-
Notifications
You must be signed in to change notification settings - Fork 777
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 cleanup: methodobject to moduleobject #1425
Changes from 6 commits
d84d0de
d34856b
b35a6a5
aaddb20
1c845e7
96fcfe6
39a29a5
2d7d482
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,12 @@ extern "C" { | |
#[cfg_attr(PyPy, link_name = "PyPyModule_GetName")] | ||
pub fn PyModule_GetName(arg1: *mut PyObject) -> *const c_char; | ||
#[cfg(not(all(windows, PyPy)))] | ||
#[deprecated(note = "Python 3.2")] | ||
pub fn PyModule_GetFilename(arg1: *mut PyObject) -> *const c_char; | ||
pub fn PyModule_GetFilenameObject(arg1: *mut PyObject) -> *mut PyObject; | ||
// skipped non-limited _PyModule_Clear | ||
// skipped non-limited _PyModule_ClearDict | ||
// skipped non-limited _PyModuleSpec_IsInitializing | ||
#[cfg_attr(PyPy, link_name = "PyPyModule_GetDef")] | ||
pub fn PyModule_GetDef(arg1: *mut PyObject) -> *mut PyModuleDef; | ||
#[cfg_attr(PyPy, link_name = "PyPyModule_GetState")] | ||
|
@@ -71,6 +75,8 @@ pub struct PyModuleDef_Slot { | |
pub const Py_mod_create: c_int = 1; | ||
pub const Py_mod_exec: c_int = 2; | ||
|
||
// skipped non-limited _Py_mod_LAST_SLOT | ||
|
||
#[repr(C)] | ||
#[derive(Copy, Clone)] | ||
pub struct PyModuleDef { | ||
|
@@ -85,6 +91,10 @@ pub struct PyModuleDef { | |
pub m_free: Option<freefunc>, | ||
} | ||
|
||
/// Helper initial value of [`PyModuleDef`] for a Python class. | ||
/// | ||
/// Not present in the Python C API. | ||
#[deprecated(note = "not present in Python headers; to be removed")] | ||
pub const PyModuleDef_INIT: PyModuleDef = PyModuleDef { | ||
Comment on lines
+97
to
98
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be breaking, but I guess the only user is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, as I think we're going to do a breaking release next anyway it's fine to just scrap this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @davidhewitt You'll do this in #1426 or should I add to this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think probably simpler for you to do it in this PR so there's no risk of merge conflicts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually nvm, I see that other than that, this PR is ready to go. I'll merge this PR now and do it in #1426. |
||
m_base: PyModuleDef_HEAD_INIT, | ||
m_name: std::ptr::null(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ use crate::ffi; | |
use crate::instance::PyNativeType; | ||
use crate::pyclass::PyClass; | ||
use crate::type_object::PyTypeObject; | ||
use crate::types::{PyAny, PyDict, PyList}; | ||
use crate::types::{PyAny, PyDict, PyList, PyString}; | ||
use crate::types::{PyCFunction, PyTuple}; | ||
use crate::{AsPyPointer, IntoPy, Py, PyObject, Python}; | ||
use std::ffi::{CStr, CString}; | ||
|
@@ -121,7 +121,11 @@ impl PyModule { | |
/// May fail if the module does not have a `__file__` attribute. | ||
#[cfg(not(all(windows, PyPy)))] | ||
pub fn filename(&self) -> PyResult<&str> { | ||
unsafe { self.str_from_ptr(ffi::PyModule_GetFilename(self.as_ptr())) } | ||
unsafe { | ||
self.py() | ||
.from_owned_ptr_or_err::<PyString>(ffi::PyModule_GetFilenameObject(self.as_ptr()))? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏼 |
||
.to_str() | ||
} | ||
} | ||
|
||
/// Calls a function in the module. | ||
|
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 definition
PyCFunction_Check
is the same as the newPyCFunction_CheckExact
- does it need updating?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.
Oops, thanks. Looks like this one was renamed in Python 3.9, with the new definition of
PyCFunction_Check
usingPyObject_TypeCheck
. Updated.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.
Looks like 3.9 introduced the
Py_IS_TYPE
macro inobject.h
, which I'll add -- should help catch these changes when eyeballing