Skip to content
Closed
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions include/pyo3-ffi-pylong-asbytearray-with-exceptions.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/include/pyo3/pyo3-ffi/src/cpython/longobject.rs b/include/pyo3/pyo3-ffi/src/cpython/longobject.rs
index 45acaae..6063575 100644
--- a/include/pyo3/pyo3-ffi/src/cpython/longobject.rs
+++ b/include/pyo3/pyo3-ffi/src/cpython/longobject.rs
@@ -61,6 +61,18 @@ extern "C" {
is_signed: c_int,
) -> *mut PyObject;

+ #[cfg(Py_3_13)]
+ #[cfg_attr(PyPy, link_name = "_PyPyLong_AsByteArrayO")]
+ pub fn _PyLong_AsByteArray(
+ v: *mut PyLongObject,
+ bytes: *mut c_uchar,
+ n: size_t,
+ little_endian: c_int,
+ is_signed: c_int,
+ with_exceptions: c_int,
+ ) -> c_int;
+
+ #[cfg(not(Py_3_13))]
#[cfg_attr(PyPy, link_name = "_PyPyLong_AsByteArrayO")]
pub fn _PyLong_AsByteArray(
v: *mut PyLongObject,
20 changes: 20 additions & 0 deletions include/pyo3-ffi-pymutex-new.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/include/pyo3/pyo3-ffi/src/cpython/lock.rs b/include/pyo3/pyo3-ffi/src/cpython/lock.rs
index 6c80b00..c451666 100644
--- a/include/pyo3/pyo3-ffi/src/cpython/lock.rs
+++ b/include/pyo3/pyo3-ffi/src/cpython/lock.rs
@@ -8,6 +8,15 @@ pub struct PyMutex {
pub(crate) _pin: PhantomPinned,
}

+impl PyMutex {
+ pub const fn new() -> PyMutex {
+ PyMutex {
+ _bits: AtomicU8::new(0),
+ _pin: PhantomPinned,
+ }
+ }
+}
+
extern "C" {
pub fn PyMutex_Lock(m: *mut PyMutex);
pub fn PyMutex_Unlock(m: *mut PyMutex);
6 changes: 4 additions & 2 deletions include/pyo3/pyo3-build-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyo3-build-config"
version = "0.23.3"
version = "0.25.1"
description = "Build configuration for the PyO3 ecosystem"
authors = ["PyO3 Project and Contributors <https://github.com/PyO3>"]
keywords = ["pyo3", "python", "cpython", "ffi"]
Expand Down Expand Up @@ -36,7 +36,9 @@ abi3-py38 = ["abi3-py39"]
abi3-py39 = ["abi3-py310"]
abi3-py310 = ["abi3-py311"]
abi3-py311 = ["abi3-py312"]
abi3-py312 = ["abi3"]
abi3-py312 = ["abi3-py313"]
abi3-py313 = ["abi3-py314"]
abi3-py314 = ["abi3"]

[package.metadata.docs.rs]
features = ["resolve-config"]
2 changes: 1 addition & 1 deletion include/pyo3/pyo3-build-config/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl std::fmt::Display for ErrorReport<'_> {
writeln!(f, "\ncaused by:")?;
let mut index = 0;
while let Some(some_source) = source {
writeln!(f, " - {}: {}", index, some_source)?;
writeln!(f, " - {index}: {some_source}")?;
source = some_source.source();
index += 1;
}
Expand Down
41 changes: 22 additions & 19 deletions include/pyo3/pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const MINIMUM_SUPPORTED_VERSION_GRAALPY: PythonVersion = PythonVersion {
};

/// Maximum Python version that can be used as minimum required Python version with abi3.
pub(crate) const ABI3_MAX_MINOR: u8 = 12;
pub(crate) const ABI3_MAX_MINOR: u8 = 13;

#[cfg(test)]
thread_local! {
Expand All @@ -58,7 +58,7 @@ pub fn cargo_env_var(var: &str) -> Option<String> {
/// the variable changes.
pub fn env_var(var: &str) -> Option<OsString> {
if cfg!(feature = "resolve-config") {
println!("cargo:rerun-if-env-changed={}", var);
println!("cargo:rerun-if-env-changed={var}");
}
#[cfg(test)]
{
Expand Down Expand Up @@ -180,9 +180,8 @@ impl InterpreterConfig {
let mut out = vec![];

for i in MINIMUM_SUPPORTED_VERSION.minor..=self.version.minor {
out.push(format!("cargo:rustc-cfg=Py_3_{}", i));
out.push(format!("cargo:rustc-cfg=Py_3_{i}"));
}
println!("cargo::rustc-check-cfg=cfg(Py_3_14)");

match self.implementation {
PythonImplementation::CPython => {}
Expand All @@ -200,7 +199,7 @@ impl InterpreterConfig {
BuildFlag::Py_GIL_DISABLED => {
out.push("cargo:rustc-cfg=Py_GIL_DISABLED".to_owned())
}
flag => out.push(format!("cargo:rustc-cfg=py_sys_config=\"{}\"", flag)),
flag => out.push(format!("cargo:rustc-cfg=py_sys_config=\"{flag}\"")),
}
}

Expand Down Expand Up @@ -339,7 +338,7 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))

let lib_dir = if cfg!(windows) {
map.get("base_prefix")
.map(|base_prefix| format!("{}\\libs", base_prefix))
.map(|base_prefix| format!("{base_prefix}\\libs"))
} else {
map.get("libdir").cloned()
};
Expand Down Expand Up @@ -667,7 +666,7 @@ print("gil_disabled", get_config_var("Py_GIL_DISABLED"))
write_option_line!(python_framework_prefix)?;
write_line!(suppress_build_script_link_lines)?;
for line in &self.extra_build_script_lines {
writeln!(writer, "extra_build_script_line={}", line)
writeln!(writer, "extra_build_script_line={line}")
.context("failed to write extra_build_script_line")?;
}
Ok(())
Expand Down Expand Up @@ -854,7 +853,7 @@ fn is_abi3() -> bool {
/// Must be called from a PyO3 crate build script.
pub fn get_abi3_version() -> Option<PythonVersion> {
let minor_version = (MINIMUM_SUPPORTED_VERSION.minor..=ABI3_MAX_MINOR)
.find(|i| cargo_env_var(&format!("CARGO_FEATURE_ABI3_PY3{}", i)).is_some());
.find(|i| cargo_env_var(&format!("CARGO_FEATURE_ABI3_PY3{i}")).is_some());
minor_version.map(|minor| PythonVersion { major: 3, minor })
}

Expand Down Expand Up @@ -1122,8 +1121,8 @@ pub enum BuildFlag {
impl Display for BuildFlag {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BuildFlag::Other(flag) => write!(f, "{}", flag),
_ => write!(f, "{:?}", self),
BuildFlag::Other(flag) => write!(f, "{flag}"),
_ => write!(f, "{self:?}"),
}
}
}
Expand All @@ -1147,7 +1146,7 @@ impl FromStr for BuildFlag {
/// PyO3 will pick these up and pass to rustc via `--cfg=py_sys_config={varname}`;
/// this allows using them conditional cfg attributes in the .rs files, so
///
/// ```rust
/// ```rust,no_run
/// #[cfg(py_sys_config="{varname}")]
/// # struct Foo;
/// ```
Expand Down Expand Up @@ -1203,7 +1202,7 @@ impl BuildFlags {

for k in &BuildFlags::ALL {
use std::fmt::Write;
writeln!(&mut script, "print(config.get('{}', '0'))", k).unwrap();
writeln!(&mut script, "print(config.get('{k}', '0'))").unwrap();
}

let stdout = run_python_script(interpreter.as_ref(), &script)?;
Expand Down Expand Up @@ -1241,7 +1240,7 @@ impl Display for BuildFlags {
} else {
write!(f, ",")?;
}
write!(f, "{}", flag)?;
write!(f, "{flag}")?;
}
Ok(())
}
Expand Down Expand Up @@ -1307,6 +1306,10 @@ pub fn parse_sysconfigdata(sysconfigdata_path: impl AsRef<Path>) -> Result<Sysco
})?;
script += r#"
for key, val in build_time_vars.items():
# (ana)conda(-forge) built Pythons are statically linked but ship the shared library with them.
# We detect them based on the magic prefix directory they have encoded in their builds.
if key == "Py_ENABLE_SHARED" and "_h_env_placehold" in build_time_vars.get("prefix"):
val = 1
print(key, val)
"#;

Expand Down Expand Up @@ -1424,7 +1427,7 @@ pub fn find_all_sysconfigdata(cross: &CrossCompileConfig) -> Result<Vec<PathBuf>

fn is_pypy_lib_dir(path: &str, v: &Option<PythonVersion>) -> bool {
let pypy_version_pat = if let Some(v) = v {
format!("pypy{}", v)
format!("pypy{v}")
} else {
"pypy3.".into()
};
Expand All @@ -1433,7 +1436,7 @@ fn is_pypy_lib_dir(path: &str, v: &Option<PythonVersion>) -> bool {

fn is_graalpy_lib_dir(path: &str, v: &Option<PythonVersion>) -> bool {
let graalpy_version_pat = if let Some(v) = v {
format!("graalpy{}", v)
format!("graalpy{v}")
} else {
"graalpy2".into()
};
Expand All @@ -1442,7 +1445,7 @@ fn is_graalpy_lib_dir(path: &str, v: &Option<PythonVersion>) -> bool {

fn is_cpython_lib_dir(path: &str, v: &Option<PythonVersion>) -> bool {
let cpython_version_pat = if let Some(v) = v {
format!("python{}", v)
format!("python{v}")
} else {
"python3.".into()
};
Expand Down Expand Up @@ -1756,7 +1759,7 @@ fn default_lib_name_unix(
) -> Result<String> {
match implementation {
PythonImplementation::CPython => match ld_version {
Some(ld_version) => Ok(format!("python{}", ld_version)),
Some(ld_version) => Ok(format!("python{ld_version}")),
None => {
if version > PythonVersion::PY37 {
// PEP 3149 ABI version tags are finally gone
Expand All @@ -1773,7 +1776,7 @@ fn default_lib_name_unix(
}
},
PythonImplementation::PyPy => match ld_version {
Some(ld_version) => Ok(format!("pypy{}-c", ld_version)),
Some(ld_version) => Ok(format!("pypy{ld_version}-c")),
None => Ok(format!("pypy{}.{}-c", version.major, version.minor)),
},

Expand Down Expand Up @@ -2002,7 +2005,7 @@ fn unescape(escaped: &str) -> Vec<u8> {
}
}

bytes.push(unhex(chunk[0]) << 4 | unhex(chunk[1]));
bytes.push((unhex(chunk[0]) << 4) | unhex(chunk[1]));
}

bytes
Expand Down
63 changes: 24 additions & 39 deletions include/pyo3/pyo3-build-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use target_lexicon::OperatingSystem;
pub fn use_pyo3_cfgs() {
print_expected_cfgs();
for cargo_command in get().build_script_outputs() {
println!("{}", cargo_command)
println!("{cargo_command}")
}
}

Expand Down Expand Up @@ -102,12 +102,7 @@ fn _add_python_framework_link_args(
) {
if matches!(triple.operating_system, OperatingSystem::Darwin(_)) && link_libpython {
if let Some(framework_prefix) = interpreter_config.python_framework_prefix.as_ref() {
writeln!(
writer,
"cargo:rustc-link-arg=-Wl,-rpath,{}",
framework_prefix
)
.unwrap();
writeln!(writer, "cargo:rustc-link-arg=-Wl,-rpath,{framework_prefix}").unwrap();
}
}
}
Expand Down Expand Up @@ -168,40 +163,36 @@ fn resolve_cross_compile_config_path() -> Option<PathBuf> {
})
}

/// Helper to print a feature cfg with a minimum rust version required.
fn print_feature_cfg(minor_version_required: u32, cfg: &str) {
let minor_version = rustc_minor_version().unwrap_or(0);

if minor_version >= minor_version_required {
println!("cargo:rustc-cfg={cfg}");
}

// rustc 1.80.0 stabilized `rustc-check-cfg` feature, don't emit before
if minor_version >= 80 {
println!("cargo:rustc-check-cfg=cfg({cfg})");
}
}

/// Use certain features if we detect the compiler being used supports them.
///
/// Features may be removed or added as MSRV gets bumped or new features become available,
/// so this function is unstable.
#[doc(hidden)]
pub fn print_feature_cfgs() {
let rustc_minor_version = rustc_minor_version().unwrap_or(0);

if rustc_minor_version >= 70 {
println!("cargo:rustc-cfg=rustc_has_once_lock");
}

// invalid_from_utf8 lint was added in Rust 1.74
if rustc_minor_version >= 74 {
println!("cargo:rustc-cfg=invalid_from_utf8_lint");
}

if rustc_minor_version >= 79 {
println!("cargo:rustc-cfg=c_str_lit");
}

print_feature_cfg(70, "rustc_has_once_lock");
print_feature_cfg(70, "cargo_toml_lints");
print_feature_cfg(71, "rustc_has_extern_c_unwind");
print_feature_cfg(74, "invalid_from_utf8_lint");
print_feature_cfg(79, "c_str_lit");
// Actually this is available on 1.78, but we should avoid
// https://github.com/rust-lang/rust/issues/124651 just in case
if rustc_minor_version >= 79 {
println!("cargo:rustc-cfg=diagnostic_namespace");
}

if rustc_minor_version >= 83 {
println!("cargo:rustc-cfg=io_error_more");
}

if rustc_minor_version >= 85 {
println!("cargo:rustc-cfg=fn_ptr_eq");
}
print_feature_cfg(79, "diagnostic_namespace");
print_feature_cfg(83, "io_error_more");
print_feature_cfg(85, "fn_ptr_eq");
}

/// Registers `pyo3`s config names as reachable cfg expressions
Expand All @@ -220,14 +211,8 @@ pub fn print_expected_cfgs() {
println!("cargo:rustc-check-cfg=cfg(PyPy)");
println!("cargo:rustc-check-cfg=cfg(GraalPy)");
println!("cargo:rustc-check-cfg=cfg(py_sys_config, values(\"Py_DEBUG\", \"Py_REF_DEBUG\", \"Py_TRACE_REFS\", \"COUNT_ALLOCS\"))");
println!("cargo:rustc-check-cfg=cfg(invalid_from_utf8_lint)");
println!("cargo:rustc-check-cfg=cfg(pyo3_disable_reference_pool)");
println!("cargo:rustc-check-cfg=cfg(pyo3_leak_on_drop_without_reference_pool)");
println!("cargo:rustc-check-cfg=cfg(diagnostic_namespace)");
println!("cargo:rustc-check-cfg=cfg(c_str_lit)");
println!("cargo:rustc-check-cfg=cfg(rustc_has_once_lock)");
println!("cargo:rustc-check-cfg=cfg(io_error_more)");
println!("cargo:rustc-check-cfg=cfg(fn_ptr_eq)");

// allow `Py_3_*` cfgs from the minimum supported version up to the
// maximum minor version (+1 for development for the next)
Expand Down
2 changes: 1 addition & 1 deletion include/pyo3/pyo3-ffi/ACKNOWLEDGEMENTS
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ for binary compatibility, with additional metadata to support PyPy.

For original implementations please see:
- https://github.com/python/cpython
- https://foss.heptapod.net/pypy/pypy
- https://github.com/pypy/pypy
10 changes: 6 additions & 4 deletions include/pyo3/pyo3-ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyo3-ffi"
version = "0.23.3"
version = "0.25.1"
description = "Python-API bindings for the PyO3 ecosystem"
authors = ["PyO3 Project and Contributors <https://github.com/PyO3>"]
keywords = ["pyo3", "python", "cpython", "ffi"]
Expand All @@ -12,7 +12,7 @@ edition = "2021"
links = "python"

[dependencies]
libc = "0.2"
libc = "0.2.62"

[features]

Expand All @@ -32,7 +32,9 @@ abi3-py38 = ["abi3-py39", "pyo3-build-config/abi3-py38"]
abi3-py39 = ["abi3-py310", "pyo3-build-config/abi3-py39"]
abi3-py310 = ["abi3-py311", "pyo3-build-config/abi3-py310"]
abi3-py311 = ["abi3-py312", "pyo3-build-config/abi3-py311"]
abi3-py312 = ["abi3", "pyo3-build-config/abi3-py312"]
abi3-py312 = ["abi3-py313", "pyo3-build-config/abi3-py312"]
abi3-py313 = ["abi3-py314", "pyo3-build-config/abi3-py313"]
abi3-py314 = ["abi3", "pyo3-build-config/abi3-py314"]

# Automatically generates `python3.dll` import libraries for Windows targets.
generate-import-lib = ["pyo3-build-config/python3-dll-a"]
Expand All @@ -41,4 +43,4 @@ generate-import-lib = ["pyo3-build-config/python3-dll-a"]
paste = "1"

[build-dependencies]
pyo3-build-config = { path = "../pyo3-build-config", features = ["resolve-config"] }
pyo3-build-config = { path = "../pyo3-build-config", version = "=0.25.1", features = ["resolve-config"] }
Loading