Skip to content

Commit

Permalink
Resolve symbol errors with Python 3.12
Browse files Browse the repository at this point in the history
    Symbols missing in /opt/hostedtoolcache/Python/3.12.4/x64/lib/libpython3.12.so:
    PyCode_New
    PyCode_NewWithPosOnlyArgs
    PyUnicode_AsUnicode
    PyUnicode_AsUnicodeAndSize
    PyUnicode_FromUnicode
    _Py_GetAllocatedBlocks
    _Py_PackageContext

Python 3.12/3.11 renamed/deprecated some APIs. Update code to skip them.
This affects `linux (ubuntu-latest, 3.12, nightly)` CI.
  • Loading branch information
quark-zju committed Jul 1, 2024
1 parent 4fe0dc7 commit b2acd66
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions python3-sys/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub const CO_MAXBLOCKS: usize = 20;
extern "C" {
pub static mut PyCode_Type: PyTypeObject;

#[cfg_attr(Py_3_12, link_name = "PyUnstable_Code_New")]
pub fn PyCode_New(
argcount: c_int,
kwonlyargcount: c_int,
Expand All @@ -175,6 +176,7 @@ extern "C" {
) -> *mut PyCodeObject;

#[cfg(Py_3_8)]
#[cfg_attr(Py_3_12, link_name = "PyUnstable_Code_NewWithPosOnlyArgs")]
pub fn PyCode_NewWithPosOnlyArgs(
argcount: c_int,
posonlyargcount: c_int,
Expand Down
2 changes: 1 addition & 1 deletion python3-sys/src/modsupport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub unsafe fn PyModule_FromDefAndSpec(def: *mut PyModuleDef, spec: *mut PyObject
)
}

#[cfg(not(Py_LIMITED_API))]
#[cfg(all(not(Py_LIMITED_API), not(Py_3_12)))]
#[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" {
pub static mut _Py_PackageContext: *const c_char;
Expand Down
2 changes: 1 addition & 1 deletion python3-sys/src/objimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extern "C" {
#[cfg(all(py_sys_config = "Py_DEBUG", not(Py_3_4)))]
pub fn _PyObject_DebugFree(arg1: *mut c_void);

#[cfg(all(not(Py_LIMITED_API), Py_3_4))]
#[cfg(all(not(Py_LIMITED_API), Py_3_4, not(Py_3_11)))]
pub fn _Py_GetAllocatedBlocks() -> Py_ssize_t;
pub fn PyObject_Init(arg1: *mut PyObject, arg2: *mut PyTypeObject) -> *mut PyObject;
pub fn PyObject_InitVar(
Expand Down
6 changes: 3 additions & 3 deletions python3-sys/src/unicodeobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extern "C" {
length: Py_ssize_t,
fill_char: Py_UCS4,
) -> Py_ssize_t;
#[cfg(not(Py_LIMITED_API))]
#[cfg(all(not(Py_LIMITED_API), not(Py_3_12)))]
#[deprecated(since = "0.2.1", note = "Deprecated since Python 3.3 / PEP 393")]
pub fn PyUnicode_FromUnicode(u: *const Py_UNICODE, size: Py_ssize_t) -> *mut PyObject;

Expand All @@ -78,10 +78,10 @@ extern "C" {
copy_null: c_int,
) -> *mut Py_UCS4;
pub fn PyUnicode_AsUCS4Copy(unicode: *mut PyObject) -> *mut Py_UCS4;
#[cfg(not(Py_LIMITED_API))]
#[cfg(all(not(Py_LIMITED_API), not(Py_3_12)))]
#[deprecated(since = "0.2.1", note = "Deprecated since Python 3.3 / PEP 393")]
pub fn PyUnicode_AsUnicode(unicode: *mut PyObject) -> *mut Py_UNICODE;
#[cfg(not(Py_LIMITED_API))]
#[cfg(all(not(Py_LIMITED_API), not(Py_3_12)))]
#[deprecated(since = "0.2.1", note = "Deprecated since Python 3.3 / PEP 393")]
pub fn PyUnicode_AsUnicodeAndSize(
unicode: *mut PyObject,
Expand Down

0 comments on commit b2acd66

Please sign in to comment.