Basic GraalPy Support (#3247)

* graalpy: recognize graalpy implementation when building

* graalpy: global Ellipse, None, NotImplemented, True, and False are only available as pointers

* graalpy: PyObject struct is opaque, use functions for everything

* graalpy: missing many of the same functions as pypy

* graalpy: do not have 128bit conversion functions

* graalpy: add functions for datetime accessor macros

* graalpy: add implementations for list macro functions

* graalpy: skip tuple macros

* graalpy: always use extern Py_CompileString function

* graalpy: disable assertion that does not apply to graalpy

* graalpy: floatobject structure is opaque on graalpy

* graalpy: ignore gc dependent test

* graalpy: add CI config

* graalpy: run rust fmt

* graalpy: add changelog entry

* graalpy: discover interpreter on PATH

* graalpy: interpreter id is not applicable to graalpy (just like pypy)

* graalpy: skip tests that cannot work on GraalPy

* graalpy: fix constructing normalized Err instances

Co-authored-by: David Hewitt <mail@davidhewitt.dev>

* graalpy: correct capi library name, but skip rust tests due to missing symbols

* graalpy: no support for C extensions on windows in latest release

* graalpy: declare support versions

* graalpy: frame, code, method, and function objects access from C API is mostly missing

* graalpy: take care only to expose C structure that GraalPy allocates

* graalpy: Bail out if graalpy version is less than what we support

---------

Co-authored-by: David Hewitt <mail@davidhewitt.dev>
This commit is contained in:
Tim Felgentreff 2024-03-25 19:54:52 +01:00 committed by GitHub
parent 54ffaecd65
commit 9a38e709bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
66 changed files with 731 additions and 308 deletions

View File

@ -24,6 +24,7 @@ jobs:
build: build:
continue-on-error: ${{ endsWith(inputs.python-version, '-dev') || contains(fromJSON('["3.7", "pypy3.7"]'), inputs.python-version) || inputs.rust == 'beta' || inputs.rust == 'nightly' }} continue-on-error: ${{ endsWith(inputs.python-version, '-dev') || contains(fromJSON('["3.7", "pypy3.7"]'), inputs.python-version) || inputs.rust == 'beta' || inputs.rust == 'nightly' }}
runs-on: ${{ inputs.os }} runs-on: ${{ inputs.os }}
if: ${{ !(startsWith(inputs.python-version, 'graalpy') && startsWith(inputs.os, 'windows')) }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -65,6 +66,7 @@ jobs:
run: nox -s docs run: nox -s docs
- name: Build (no features) - name: Build (no features)
if: ${{ !startsWith(inputs.python-version, 'graalpy') }}
run: cargo build --lib --tests --no-default-features run: cargo build --lib --tests --no-default-features
# --no-default-features when used with `cargo build/test -p` doesn't seem to work! # --no-default-features when used with `cargo build/test -p` doesn't seem to work!
@ -74,7 +76,7 @@ jobs:
cargo build --no-default-features cargo build --no-default-features
# Run tests (except on PyPy, because no embedding API). # Run tests (except on PyPy, because no embedding API).
- if: ${{ !startsWith(inputs.python-version, 'pypy') }} - if: ${{ !startsWith(inputs.python-version, 'pypy') && !startsWith(inputs.python-version, 'graalpy') }}
name: Test (no features) name: Test (no features)
run: cargo test --no-default-features --lib --tests run: cargo test --no-default-features --lib --tests
@ -85,6 +87,7 @@ jobs:
cargo test --no-default-features cargo test --no-default-features
- name: Build (all additive features) - name: Build (all additive features)
if: ${{ !startsWith(inputs.python-version, 'graalpy') }}
run: cargo build --lib --tests --no-default-features --features "full ${{ inputs.extra-features }}" run: cargo build --lib --tests --no-default-features --features "full ${{ inputs.extra-features }}"
- if: ${{ startsWith(inputs.python-version, 'pypy') }} - if: ${{ startsWith(inputs.python-version, 'pypy') }}
@ -92,17 +95,17 @@ jobs:
run: cargo build --lib --tests --no-default-features --features "abi3-py37 full ${{ inputs.extra-features }}" run: cargo build --lib --tests --no-default-features --features "abi3-py37 full ${{ inputs.extra-features }}"
# Run tests (except on PyPy, because no embedding API). # Run tests (except on PyPy, because no embedding API).
- if: ${{ !startsWith(inputs.python-version, 'pypy') }} - if: ${{ !startsWith(inputs.python-version, 'pypy') && !startsWith(inputs.python-version, 'graalpy') }}
name: Test name: Test
run: cargo test --no-default-features --features "full ${{ inputs.extra-features }}" run: cargo test --no-default-features --features "full ${{ inputs.extra-features }}"
# Run tests again, but in abi3 mode # Run tests again, but in abi3 mode
- if: ${{ !startsWith(inputs.python-version, 'pypy') }} - if: ${{ !startsWith(inputs.python-version, 'pypy') && !startsWith(inputs.python-version, 'graalpy') }}
name: Test (abi3) name: Test (abi3)
run: cargo test --no-default-features --features "abi3 full ${{ inputs.extra-features }}" run: cargo test --no-default-features --features "abi3 full ${{ inputs.extra-features }}"
# Run tests again, for abi3-py37 (the minimal Python version) # Run tests again, for abi3-py37 (the minimal Python version)
- if: ${{ (!startsWith(inputs.python-version, 'pypy')) && (inputs.python-version != '3.7') }} - if: ${{ (!startsWith(inputs.python-version, 'pypy') && !startsWith(inputs.python-version, 'graalpy')) && (inputs.python-version != '3.7') }}
name: Test (abi3-py37) name: Test (abi3-py37)
run: cargo test --no-default-features --features "abi3-py37 full ${{ inputs.extra-features }}" run: cargo test --no-default-features --features "abi3-py37 full ${{ inputs.extra-features }}"
@ -120,7 +123,7 @@ jobs:
- uses: dorny/paths-filter@v3 - uses: dorny/paths-filter@v3
# pypy 3.7 and 3.8 are not PEP 3123 compliant so fail checks here # pypy 3.7 and 3.8 are not PEP 3123 compliant so fail checks here
if: ${{ inputs.rust == 'stable' && inputs.python-version != 'pypy3.7' && inputs.python-version != 'pypy3.8' }} if: ${{ inputs.rust == 'stable' && inputs.python-version != 'pypy3.7' && inputs.python-version != 'pypy3.8' && !startsWith(inputs.python-version, 'graalpy') }}
id: ffi-changes id: ffi-changes
with: with:
base: ${{ github.event.pull_request.base.ref || github.event.merge_group.base_ref }} base: ${{ github.event.pull_request.base.ref || github.event.merge_group.base_ref }}
@ -135,7 +138,7 @@ jobs:
- name: Run pyo3-ffi-check - name: Run pyo3-ffi-check
# pypy 3.7 and 3.8 are not PEP 3123 compliant so fail checks here, nor # pypy 3.7 and 3.8 are not PEP 3123 compliant so fail checks here, nor
# is pypy 3.9 on windows # is pypy 3.9 on windows
if: ${{ endsWith(inputs.python-version, '-dev') || (steps.ffi-changes.outputs.changed == 'true' && inputs.rust == 'stable' && inputs.python-version != 'pypy3.7' && inputs.python-version != 'pypy3.8' && !(inputs.python-version == 'pypy3.9' && contains(inputs.os, 'windows'))) }} if: ${{ endsWith(inputs.python-version, '-dev') || (steps.ffi-changes.outputs.changed == 'true' && inputs.rust == 'stable' && inputs.python-version != 'pypy3.7' && inputs.python-version != 'pypy3.8' && !startsWith(inputs.python-version, 'graalpy') && !(inputs.python-version == 'pypy3.9' && contains(inputs.os, 'windows'))) }}
run: nox -s ffi-check run: nox -s ffi-check
env: env:

View File

@ -228,6 +228,7 @@ jobs:
"pypy3.8", "pypy3.8",
"pypy3.9", "pypy3.9",
"pypy3.10", "pypy3.10",
"graalpy24.0",
] ]
platform: platform:
[ [

View File

@ -17,7 +17,7 @@
## Usage ## Usage
PyO3 supports the following software versions: PyO3 supports the following software versions:
- Python 3.7 and up (CPython and PyPy) - Python 3.7 and up (CPython, PyPy, and GraalPy)
- Rust 1.56 and up - Rust 1.56 and up
You can use PyO3 to write a native Python module in Rust, or to embed Python in a Rust binary. The following sections explain each of these in turn. You can use PyO3 to write a native Python module in Rust, or to embed Python in a Rust binary. The following sections explain each of these in turn.

View File

@ -0,0 +1 @@
Added support for running PyO3 extensions on GraalPy.

View File

@ -32,6 +32,12 @@ use crate::{
/// Minimum Python version PyO3 supports. /// Minimum Python version PyO3 supports.
const MINIMUM_SUPPORTED_VERSION: PythonVersion = PythonVersion { major: 3, minor: 7 }; const MINIMUM_SUPPORTED_VERSION: PythonVersion = PythonVersion { major: 3, minor: 7 };
/// GraalPy may implement the same CPython version over multiple releases.
const MINIMUM_SUPPORTED_VERSION_GRAALPY: PythonVersion = PythonVersion {
major: 24,
minor: 0,
};
/// Maximum Python version that can be used as minimum required Python version with abi3. /// Maximum Python version that can be used as minimum required Python version with abi3.
const ABI3_MAX_MINOR: u8 = 12; const ABI3_MAX_MINOR: u8 = 12;
@ -173,6 +179,11 @@ impl InterpreterConfig {
See https://foss.heptapod.net/pypy/pypy/-/issues/3397 for more information." See https://foss.heptapod.net/pypy/pypy/-/issues/3397 for more information."
)); ));
} }
} else if self.implementation.is_graalpy() {
println!("cargo:rustc-cfg=GraalPy");
if self.abi3 {
warn!("GraalPy does not support abi3 so the build artifacts will be version-specific.");
}
} else if self.abi3 { } else if self.abi3 {
out.push("cargo:rustc-cfg=Py_LIMITED_API".to_owned()); out.push("cargo:rustc-cfg=Py_LIMITED_API".to_owned());
} }
@ -197,6 +208,12 @@ import sys
from sysconfig import get_config_var, get_platform from sysconfig import get_config_var, get_platform
PYPY = platform.python_implementation() == "PyPy" PYPY = platform.python_implementation() == "PyPy"
GRAALPY = platform.python_implementation() == "GraalVM"
if GRAALPY:
graalpy_ver = map(int, __graalpython__.get_graalvm_version().split('.'));
print("graalpy_major", next(graalpy_ver))
print("graalpy_minor", next(graalpy_ver))
# sys.base_prefix is missing on Python versions older than 3.3; this allows the script to continue # sys.base_prefix is missing on Python versions older than 3.3; this allows the script to continue
# so that the version mismatch can be reported in a nicer way later. # so that the version mismatch can be reported in a nicer way later.
@ -226,7 +243,7 @@ SHARED = bool(get_config_var("Py_ENABLE_SHARED"))
print("implementation", platform.python_implementation()) print("implementation", platform.python_implementation())
print("version_major", sys.version_info[0]) print("version_major", sys.version_info[0])
print("version_minor", sys.version_info[1]) print("version_minor", sys.version_info[1])
print("shared", PYPY or ANACONDA or WINDOWS or FRAMEWORK or SHARED) print("shared", PYPY or GRAALPY or ANACONDA or WINDOWS or FRAMEWORK or SHARED)
print_if_set("ld_version", get_config_var("LDVERSION")) print_if_set("ld_version", get_config_var("LDVERSION"))
print_if_set("libdir", get_config_var("LIBDIR")) print_if_set("libdir", get_config_var("LIBDIR"))
print_if_set("base_prefix", base_prefix) print_if_set("base_prefix", base_prefix)
@ -244,6 +261,23 @@ print("ext_suffix", get_config_var("EXT_SUFFIX"))
interpreter.as_ref().display() interpreter.as_ref().display()
); );
if let Some(value) = map.get("graalpy_major") {
let graalpy_version = PythonVersion {
major: value
.parse()
.context("failed to parse GraalPy major version")?,
minor: map["graalpy_minor"]
.parse()
.context("failed to parse GraalPy minor version")?,
};
ensure!(
graalpy_version >= MINIMUM_SUPPORTED_VERSION_GRAALPY,
"At least GraalPy version {} needed, got {}",
MINIMUM_SUPPORTED_VERSION_GRAALPY,
graalpy_version
);
};
let shared = map["shared"].as_str() == "True"; let shared = map["shared"].as_str() == "True";
let version = PythonVersion { let version = PythonVersion {
@ -588,7 +622,7 @@ print("ext_suffix", get_config_var("EXT_SUFFIX"))
/// Lowers the configured version to the abi3 version, if set. /// Lowers the configured version to the abi3 version, if set.
fn fixup_for_abi3_version(&mut self, abi3_version: Option<PythonVersion>) -> Result<()> { fn fixup_for_abi3_version(&mut self, abi3_version: Option<PythonVersion>) -> Result<()> {
// PyPy doesn't support abi3; don't adjust the version // PyPy doesn't support abi3; don't adjust the version
if self.implementation.is_pypy() { if self.implementation.is_pypy() || self.implementation.is_graalpy() {
return Ok(()); return Ok(());
} }
@ -647,6 +681,7 @@ impl FromStr for PythonVersion {
pub enum PythonImplementation { pub enum PythonImplementation {
CPython, CPython,
PyPy, PyPy,
GraalPy,
} }
impl PythonImplementation { impl PythonImplementation {
@ -655,12 +690,19 @@ impl PythonImplementation {
self == PythonImplementation::PyPy self == PythonImplementation::PyPy
} }
#[doc(hidden)]
pub fn is_graalpy(self) -> bool {
self == PythonImplementation::GraalPy
}
#[doc(hidden)] #[doc(hidden)]
pub fn from_soabi(soabi: &str) -> Result<Self> { pub fn from_soabi(soabi: &str) -> Result<Self> {
if soabi.starts_with("pypy") { if soabi.starts_with("pypy") {
Ok(PythonImplementation::PyPy) Ok(PythonImplementation::PyPy)
} else if soabi.starts_with("cpython") { } else if soabi.starts_with("cpython") {
Ok(PythonImplementation::CPython) Ok(PythonImplementation::CPython)
} else if soabi.starts_with("graalpy") {
Ok(PythonImplementation::GraalPy)
} else { } else {
bail!("unsupported Python interpreter"); bail!("unsupported Python interpreter");
} }
@ -672,6 +714,7 @@ impl Display for PythonImplementation {
match self { match self {
PythonImplementation::CPython => write!(f, "CPython"), PythonImplementation::CPython => write!(f, "CPython"),
PythonImplementation::PyPy => write!(f, "PyPy"), PythonImplementation::PyPy => write!(f, "PyPy"),
PythonImplementation::GraalPy => write!(f, "GraalVM"),
} }
} }
} }
@ -682,6 +725,7 @@ impl FromStr for PythonImplementation {
match s { match s {
"CPython" => Ok(PythonImplementation::CPython), "CPython" => Ok(PythonImplementation::CPython),
"PyPy" => Ok(PythonImplementation::PyPy), "PyPy" => Ok(PythonImplementation::PyPy),
"GraalVM" => Ok(PythonImplementation::GraalPy),
_ => bail!("unknown interpreter: {}", s), _ => bail!("unknown interpreter: {}", s),
} }
} }
@ -760,7 +804,7 @@ pub struct CrossCompileConfig {
/// The version of the Python library to link against. /// The version of the Python library to link against.
version: Option<PythonVersion>, version: Option<PythonVersion>,
/// The target Python implementation hint (CPython or PyPy) /// The target Python implementation hint (CPython, PyPy, GraalPy, ...)
implementation: Option<PythonImplementation>, implementation: Option<PythonImplementation>,
/// The compile target triple (e.g. aarch64-unknown-linux-gnu) /// The compile target triple (e.g. aarch64-unknown-linux-gnu)
@ -1264,6 +1308,15 @@ fn is_pypy_lib_dir(path: &str, v: &Option<PythonVersion>) -> bool {
path == "lib_pypy" || path.starts_with(&pypy_version_pat) path == "lib_pypy" || path.starts_with(&pypy_version_pat)
} }
fn is_graalpy_lib_dir(path: &str, v: &Option<PythonVersion>) -> bool {
let graalpy_version_pat = if let Some(v) = v {
format!("graalpy{}", v)
} else {
"graalpy2".into()
};
path == "lib_graalpython" || path.starts_with(&graalpy_version_pat)
}
fn is_cpython_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 { let cpython_version_pat = if let Some(v) = v {
format!("python{}", v) format!("python{}", v)
@ -1297,6 +1350,7 @@ fn search_lib_dir(path: impl AsRef<Path>, cross: &CrossCompileConfig) -> Vec<Pat
search_lib_dir(f.path(), cross) search_lib_dir(f.path(), cross)
} else if is_cpython_lib_dir(&file_name, &cross.version) } else if is_cpython_lib_dir(&file_name, &cross.version)
|| is_pypy_lib_dir(&file_name, &cross.version) || is_pypy_lib_dir(&file_name, &cross.version)
|| is_graalpy_lib_dir(&file_name, &cross.version)
{ {
search_lib_dir(f.path(), cross) search_lib_dir(f.path(), cross)
} else { } else {
@ -1418,7 +1472,7 @@ fn default_cross_compile(cross_compile_config: &CrossCompileConfig) -> Result<In
/// ///
/// Must be called from a PyO3 crate build script. /// Must be called from a PyO3 crate build script.
fn default_abi3_config(host: &Triple, version: PythonVersion) -> InterpreterConfig { fn default_abi3_config(host: &Triple, version: PythonVersion) -> InterpreterConfig {
// FIXME: PyPy does not support the Stable ABI yet. // FIXME: PyPy & GraalPy do not support the Stable ABI.
let implementation = PythonImplementation::CPython; let implementation = PythonImplementation::CPython;
let abi3 = true; let abi3 = true;
@ -1524,7 +1578,7 @@ fn default_lib_name_windows(
// CPython bug: linking against python3_d.dll raises error // CPython bug: linking against python3_d.dll raises error
// https://github.com/python/cpython/issues/101614 // https://github.com/python/cpython/issues/101614
format!("python{}{}_d", version.major, version.minor) format!("python{}{}_d", version.major, version.minor)
} else if abi3 && !implementation.is_pypy() { } else if abi3 && !(implementation.is_pypy() || implementation.is_graalpy()) {
WINDOWS_ABI3_LIB_NAME.to_owned() WINDOWS_ABI3_LIB_NAME.to_owned()
} else if mingw { } else if mingw {
// https://packages.msys2.org/base/mingw-w64-python // https://packages.msys2.org/base/mingw-w64-python
@ -1562,6 +1616,7 @@ fn default_lib_name_unix(
format!("pypy{}-c", version.major) format!("pypy{}-c", version.major)
} }
} }
PythonImplementation::GraalPy => "python-native".to_string(),
} }
} }
@ -1662,7 +1717,9 @@ pub fn find_interpreter() -> Result<PathBuf> {
.find(|bin| { .find(|bin| {
if let Ok(out) = Command::new(bin).arg("--version").output() { if let Ok(out) = Command::new(bin).arg("--version").output() {
// begin with `Python 3.X.X :: additional info` // begin with `Python 3.X.X :: additional info`
out.stdout.starts_with(b"Python 3") || out.stderr.starts_with(b"Python 3") out.stdout.starts_with(b"Python 3")
|| out.stderr.starts_with(b"Python 3")
|| out.stdout.starts_with(b"GraalPy 3")
} else { } else {
false false
} }

View File

@ -7,7 +7,7 @@ use python3_dll_a::ImportLibraryGenerator;
use target_lexicon::{Architecture, OperatingSystem, Triple}; use target_lexicon::{Architecture, OperatingSystem, Triple};
use super::{PythonImplementation, PythonVersion}; use super::{PythonImplementation, PythonVersion};
use crate::errors::{Context, Result}; use crate::errors::{Context, Error, Result};
/// Generates the `python3.dll` or `pythonXY.dll` import library for Windows targets. /// Generates the `python3.dll` or `pythonXY.dll` import library for Windows targets.
/// ///
@ -42,6 +42,9 @@ pub(super) fn generate_import_lib(
let implementation = match py_impl { let implementation = match py_impl {
PythonImplementation::CPython => python3_dll_a::PythonImplementation::CPython, PythonImplementation::CPython => python3_dll_a::PythonImplementation::CPython,
PythonImplementation::PyPy => python3_dll_a::PythonImplementation::PyPy, PythonImplementation::PyPy => python3_dll_a::PythonImplementation::PyPy,
PythonImplementation::GraalPy => {
return Err(Error::from("No support for GraalPy on Windows"))
}
}; };
ImportLibraryGenerator::new(&arch, &env) ImportLibraryGenerator::new(&arch, &env)

View File

@ -38,6 +38,7 @@ use target_lexicon::OperatingSystem;
/// | `#[cfg(Py_3_7)]`, `#[cfg(Py_3_8)]`, `#[cfg(Py_3_9)]`, `#[cfg(Py_3_10)]` | These attributes mark code only for a given Python version and up. For example, `#[cfg(Py_3_7)]` marks code which can run on Python 3.7 **and newer**. | /// | `#[cfg(Py_3_7)]`, `#[cfg(Py_3_8)]`, `#[cfg(Py_3_9)]`, `#[cfg(Py_3_10)]` | These attributes mark code only for a given Python version and up. For example, `#[cfg(Py_3_7)]` marks code which can run on Python 3.7 **and newer**. |
/// | `#[cfg(Py_LIMITED_API)]` | This marks code which is run when compiling with PyO3's `abi3` feature enabled. | /// | `#[cfg(Py_LIMITED_API)]` | This marks code which is run when compiling with PyO3's `abi3` feature enabled. |
/// | `#[cfg(PyPy)]` | This marks code which is run when compiling for PyPy. | /// | `#[cfg(PyPy)]` | This marks code which is run when compiling for PyPy. |
/// | `#[cfg(GraalPy)]` | This marks code which is run when compiling for GraalPy. |
/// ///
/// For examples of how to use these attributes, [see PyO3's guide](https://pyo3.rs/latest/building-and-distribution/multiple_python_versions.html). /// For examples of how to use these attributes, [see PyO3's guide](https://pyo3.rs/latest/building-and-distribution/multiple_python_versions.html).
#[cfg(feature = "resolve-config")] #[cfg(feature = "resolve-config")]

View File

@ -29,6 +29,17 @@ const SUPPORTED_VERSIONS_PYPY: SupportedVersions = SupportedVersions {
}, },
}; };
const SUPPORTED_VERSIONS_GRAALPY: SupportedVersions = SupportedVersions {
min: PythonVersion {
major: 3,
minor: 10,
},
max: PythonVersion {
major: 3,
minor: 11,
},
};
fn ensure_python_version(interpreter_config: &InterpreterConfig) -> Result<()> { fn ensure_python_version(interpreter_config: &InterpreterConfig) -> Result<()> {
// This is an undocumented env var which is only really intended to be used in CI / for testing // This is an undocumented env var which is only really intended to be used in CI / for testing
// and development. // and development.
@ -73,6 +84,24 @@ fn ensure_python_version(interpreter_config: &InterpreterConfig) -> Result<()> {
std::env::var("CARGO_PKG_VERSION").unwrap() std::env::var("CARGO_PKG_VERSION").unwrap()
); );
} }
PythonImplementation::GraalPy => {
let versions = SUPPORTED_VERSIONS_GRAALPY;
ensure!(
interpreter_config.version >= versions.min,
"the configured GraalPy interpreter version ({}) is lower than PyO3's minimum supported version ({})",
interpreter_config.version,
versions.min,
);
// GraalPy does not support abi3, so we cannot offer forward compatibility
ensure!(
interpreter_config.version <= versions.max,
"the configured GraalPy interpreter version ({}) is newer than PyO3's maximum supported version ({})\n\
= help: please check if an updated version of PyO3 is available. Current version: {}",
interpreter_config.version,
versions.max,
std::env::var("CARGO_PKG_VERSION").unwrap()
);
}
} }
Ok(()) Ok(())

View File

@ -23,6 +23,7 @@ pub unsafe fn PyObject_DelAttr(o: *mut PyObject, attr_name: *mut PyObject) -> c_
extern "C" { extern "C" {
#[cfg(all( #[cfg(all(
not(PyPy), not(PyPy),
not(GraalPy),
any(Py_3_10, all(not(Py_LIMITED_API), Py_3_9)) // Added to python in 3.9 but to limited API in 3.10 any(Py_3_10, all(not(Py_LIMITED_API), Py_3_9)) // Added to python in 3.9 but to limited API in 3.10
))] ))]
#[cfg_attr(PyPy, link_name = "PyPyObject_CallNoArgs")] #[cfg_attr(PyPy, link_name = "PyPyObject_CallNoArgs")]

View File

@ -1,3 +1,4 @@
#[cfg(not(GraalPy))]
use crate::longobject::PyLongObject; use crate::longobject::PyLongObject;
use crate::object::*; use crate::object::*;
use std::os::raw::{c_int, c_long}; use std::os::raw::{c_int, c_long};
@ -16,20 +17,33 @@ pub unsafe fn PyBool_Check(op: *mut PyObject) -> c_int {
#[cfg_attr(windows, link(name = "pythonXY"))] #[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" { extern "C" {
#[cfg(not(GraalPy))]
#[cfg_attr(PyPy, link_name = "_PyPy_FalseStruct")] #[cfg_attr(PyPy, link_name = "_PyPy_FalseStruct")]
static mut _Py_FalseStruct: PyLongObject; static mut _Py_FalseStruct: PyLongObject;
#[cfg(not(GraalPy))]
#[cfg_attr(PyPy, link_name = "_PyPy_TrueStruct")] #[cfg_attr(PyPy, link_name = "_PyPy_TrueStruct")]
static mut _Py_TrueStruct: PyLongObject; static mut _Py_TrueStruct: PyLongObject;
#[cfg(GraalPy)]
static mut _Py_FalseStructReference: *mut PyObject;
#[cfg(GraalPy)]
static mut _Py_TrueStructReference: *mut PyObject;
} }
#[inline] #[inline]
pub unsafe fn Py_False() -> *mut PyObject { pub unsafe fn Py_False() -> *mut PyObject {
addr_of_mut!(_Py_FalseStruct) as *mut PyObject #[cfg(not(GraalPy))]
return addr_of_mut!(_Py_FalseStruct) as *mut PyObject;
#[cfg(GraalPy)]
return _Py_FalseStructReference;
} }
#[inline] #[inline]
pub unsafe fn Py_True() -> *mut PyObject { pub unsafe fn Py_True() -> *mut PyObject {
addr_of_mut!(_Py_TrueStruct) as *mut PyObject #[cfg(not(GraalPy))]
return addr_of_mut!(_Py_TrueStruct) as *mut PyObject;
#[cfg(GraalPy)]
return _Py_TrueStructReference;
} }
#[inline] #[inline]

View File

@ -3,7 +3,7 @@ use crate::pyport::Py_ssize_t;
use std::os::raw::{c_char, c_int}; use std::os::raw::{c_char, c_int};
use std::ptr::addr_of_mut; use std::ptr::addr_of_mut;
#[cfg(not(any(PyPy, Py_LIMITED_API)))] #[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PyByteArrayObject { pub struct PyByteArrayObject {
@ -17,7 +17,7 @@ pub struct PyByteArrayObject {
pub ob_exports: c_int, pub ob_exports: c_int,
} }
#[cfg(any(PyPy, Py_LIMITED_API))] #[cfg(any(PyPy, GraalPy, Py_LIMITED_API))]
opaque_struct!(PyByteArrayObject); opaque_struct!(PyByteArrayObject);
#[cfg_attr(windows, link(name = "pythonXY"))] #[cfg_attr(windows, link(name = "pythonXY"))]

View File

@ -30,6 +30,7 @@ extern "C" {
// non-limited // non-limited
pub struct PyComplexObject { pub struct PyComplexObject {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(GraalPy))]
pub cval: Py_complex, pub cval: Py_complex,
} }

View File

@ -6,7 +6,7 @@ use crate::Py_buffer;
#[cfg(Py_3_8)] #[cfg(Py_3_8)]
use crate::pyport::PY_SSIZE_T_MAX; use crate::pyport::PY_SSIZE_T_MAX;
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
use crate::{ use crate::{
vectorcallfunc, PyCallable_Check, PyThreadState, PyThreadState_GET, PyTuple_Check, vectorcallfunc, PyCallable_Check, PyThreadState, PyThreadState_GET, PyTuple_Check,
PyType_HasFeature, Py_TPFLAGS_HAVE_VECTORCALL, PyType_HasFeature, Py_TPFLAGS_HAVE_VECTORCALL,
@ -15,15 +15,15 @@ use crate::{
use libc::size_t; use libc::size_t;
extern "C" { extern "C" {
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
pub fn _PyStack_AsDict(values: *const *mut PyObject, kwnames: *mut PyObject) -> *mut PyObject; pub fn _PyStack_AsDict(values: *const *mut PyObject, kwnames: *mut PyObject) -> *mut PyObject;
} }
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
const _PY_FASTCALL_SMALL_STACK: size_t = 5; const _PY_FASTCALL_SMALL_STACK: size_t = 5;
extern "C" { extern "C" {
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
pub fn _Py_CheckFunctionResult( pub fn _Py_CheckFunctionResult(
tstate: *mut PyThreadState, tstate: *mut PyThreadState,
callable: *mut PyObject, callable: *mut PyObject,
@ -31,7 +31,7 @@ extern "C" {
where_: *const c_char, where_: *const c_char,
) -> *mut PyObject; ) -> *mut PyObject;
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
pub fn _PyObject_MakeTpCall( pub fn _PyObject_MakeTpCall(
tstate: *mut PyThreadState, tstate: *mut PyThreadState,
callable: *mut PyObject, callable: *mut PyObject,
@ -52,7 +52,7 @@ pub unsafe fn PyVectorcall_NARGS(n: size_t) -> Py_ssize_t {
(n as Py_ssize_t) & !PY_VECTORCALL_ARGUMENTS_OFFSET (n as Py_ssize_t) & !PY_VECTORCALL_ARGUMENTS_OFFSET
} }
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
#[inline(always)] #[inline(always)]
pub unsafe fn PyVectorcall_Function(callable: *mut PyObject) -> Option<vectorcallfunc> { pub unsafe fn PyVectorcall_Function(callable: *mut PyObject) -> Option<vectorcallfunc> {
assert!(!callable.is_null()); assert!(!callable.is_null());
@ -67,7 +67,7 @@ pub unsafe fn PyVectorcall_Function(callable: *mut PyObject) -> Option<vectorcal
*ptr *ptr
} }
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
#[inline(always)] #[inline(always)]
pub unsafe fn _PyObject_VectorcallTstate( pub unsafe fn _PyObject_VectorcallTstate(
tstate: *mut PyThreadState, tstate: *mut PyThreadState,
@ -91,7 +91,7 @@ pub unsafe fn _PyObject_VectorcallTstate(
} }
} }
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
#[inline(always)] #[inline(always)]
pub unsafe fn PyObject_Vectorcall( pub unsafe fn PyObject_Vectorcall(
callable: *mut PyObject, callable: *mut PyObject,
@ -114,7 +114,10 @@ extern "C" {
) -> *mut PyObject; ) -> *mut PyObject;
#[cfg(Py_3_8)] #[cfg(Py_3_8)]
#[cfg_attr(all(not(PyPy), not(Py_3_9)), link_name = "_PyObject_VectorcallDict")] #[cfg_attr(
all(not(any(PyPy, GraalPy)), not(Py_3_9)),
link_name = "_PyObject_VectorcallDict"
)]
#[cfg_attr(all(PyPy, not(Py_3_9)), link_name = "_PyPyObject_VectorcallDict")] #[cfg_attr(all(PyPy, not(Py_3_9)), link_name = "_PyPyObject_VectorcallDict")]
#[cfg_attr(all(PyPy, Py_3_9), link_name = "PyPyObject_VectorcallDict")] #[cfg_attr(all(PyPy, Py_3_9), link_name = "PyPyObject_VectorcallDict")]
pub fn PyObject_VectorcallDict( pub fn PyObject_VectorcallDict(
@ -134,7 +137,7 @@ extern "C" {
) -> *mut PyObject; ) -> *mut PyObject;
} }
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
#[inline(always)] #[inline(always)]
pub unsafe fn _PyObject_FastCallTstate( pub unsafe fn _PyObject_FastCallTstate(
tstate: *mut PyThreadState, tstate: *mut PyThreadState,
@ -145,7 +148,7 @@ pub unsafe fn _PyObject_FastCallTstate(
_PyObject_VectorcallTstate(tstate, func, args, nargs as size_t, std::ptr::null_mut()) _PyObject_VectorcallTstate(tstate, func, args, nargs as size_t, std::ptr::null_mut())
} }
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
#[inline(always)] #[inline(always)]
pub unsafe fn _PyObject_FastCall( pub unsafe fn _PyObject_FastCall(
func: *mut PyObject, func: *mut PyObject,
@ -155,7 +158,7 @@ pub unsafe fn _PyObject_FastCall(
_PyObject_FastCallTstate(PyThreadState_GET(), func, args, nargs) _PyObject_FastCallTstate(PyThreadState_GET(), func, args, nargs)
} }
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
#[inline(always)] #[inline(always)]
pub unsafe fn _PyObject_CallNoArg(func: *mut PyObject) -> *mut PyObject { pub unsafe fn _PyObject_CallNoArg(func: *mut PyObject) -> *mut PyObject {
_PyObject_VectorcallTstate( _PyObject_VectorcallTstate(
@ -173,7 +176,7 @@ extern "C" {
pub fn _PyObject_CallNoArg(func: *mut PyObject) -> *mut PyObject; pub fn _PyObject_CallNoArg(func: *mut PyObject) -> *mut PyObject;
} }
#[cfg(all(Py_3_8, not(PyPy)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy))))]
#[inline(always)] #[inline(always)]
pub unsafe fn PyObject_CallOneArg(func: *mut PyObject, arg: *mut PyObject) -> *mut PyObject { pub unsafe fn PyObject_CallOneArg(func: *mut PyObject, arg: *mut PyObject) -> *mut PyObject {
assert!(!arg.is_null()); assert!(!arg.is_null());
@ -185,7 +188,7 @@ pub unsafe fn PyObject_CallOneArg(func: *mut PyObject, arg: *mut PyObject) -> *m
} }
extern "C" { extern "C" {
#[cfg(all(Py_3_9, not(PyPy)))] #[cfg(all(Py_3_9, not(any(PyPy, GraalPy))))]
pub fn PyObject_VectorcallMethod( pub fn PyObject_VectorcallMethod(
name: *mut PyObject, name: *mut PyObject,
args: *const *mut PyObject, args: *const *mut PyObject,
@ -194,7 +197,7 @@ extern "C" {
) -> *mut PyObject; ) -> *mut PyObject;
} }
#[cfg(all(Py_3_9, not(PyPy)))] #[cfg(all(Py_3_9, not(any(PyPy, GraalPy))))]
#[inline(always)] #[inline(always)]
pub unsafe fn PyObject_CallMethodNoArgs( pub unsafe fn PyObject_CallMethodNoArgs(
self_: *mut PyObject, self_: *mut PyObject,
@ -208,7 +211,7 @@ pub unsafe fn PyObject_CallMethodNoArgs(
) )
} }
#[cfg(all(Py_3_9, not(PyPy)))] #[cfg(all(Py_3_9, not(any(PyPy, GraalPy))))]
#[inline(always)] #[inline(always)]
pub unsafe fn PyObject_CallMethodOneArg( pub unsafe fn PyObject_CallMethodOneArg(
self_: *mut PyObject, self_: *mut PyObject,
@ -236,7 +239,7 @@ extern "C" {
pub fn PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t; pub fn PyObject_LengthHint(o: *mut PyObject, arg1: Py_ssize_t) -> Py_ssize_t;
#[cfg(not(Py_3_11))] // moved to src/buffer.rs from 3.11 #[cfg(not(Py_3_11))] // moved to src/buffer.rs from 3.11
#[cfg(all(Py_3_9, not(PyPy)))] #[cfg(all(Py_3_9, not(any(PyPy, GraalPy))))]
pub fn PyObject_CheckBuffer(obj: *mut PyObject) -> c_int; pub fn PyObject_CheckBuffer(obj: *mut PyObject) -> c_int;
} }
@ -308,7 +311,7 @@ pub const PY_ITERSEARCH_INDEX: c_int = 2;
pub const PY_ITERSEARCH_CONTAINS: c_int = 3; pub const PY_ITERSEARCH_CONTAINS: c_int = 3;
extern "C" { extern "C" {
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn _PySequence_IterSearch( pub fn _PySequence_IterSearch(
seq: *mut PyObject, seq: *mut PyObject,
obj: *mut PyObject, obj: *mut PyObject,

View File

@ -1,10 +1,10 @@
use crate::object::*; use crate::object::*;
use crate::Py_ssize_t; use crate::Py_ssize_t;
#[cfg(not(any(PyPy, Py_LIMITED_API)))] #[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))]
use std::os::raw::c_char; use std::os::raw::c_char;
use std::os::raw::c_int; use std::os::raw::c_int;
#[cfg(not(any(PyPy, Py_LIMITED_API)))] #[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API)))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PyBytesObject { pub struct PyBytesObject {
@ -13,7 +13,7 @@ pub struct PyBytesObject {
pub ob_sval: [c_char; 1], pub ob_sval: [c_char; 1],
} }
#[cfg(any(PyPy, Py_LIMITED_API))] #[cfg(any(PyPy, GraalPy, Py_LIMITED_API))]
opaque_struct!(PyBytesObject); opaque_struct!(PyBytesObject);
extern "C" { extern "C" {

View File

@ -3,10 +3,10 @@ use crate::pyport::Py_ssize_t;
#[allow(unused_imports)] #[allow(unused_imports)]
use std::os::raw::{c_char, c_int, c_short, c_uchar, c_void}; use std::os::raw::{c_char, c_int, c_short, c_uchar, c_void};
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
use std::ptr::addr_of_mut; use std::ptr::addr_of_mut;
#[cfg(all(Py_3_8, not(PyPy), not(Py_3_11)))] #[cfg(all(Py_3_8, not(any(PyPy, GraalPy)), not(Py_3_11)))]
opaque_struct!(_PyOpcache); opaque_struct!(_PyOpcache);
#[cfg(Py_3_12)] #[cfg(Py_3_12)]
@ -73,10 +73,10 @@ pub struct _PyCoMonitoringData {
pub per_instruction_tools: *mut u8, pub per_instruction_tools: *mut u8,
} }
#[cfg(all(not(PyPy), not(Py_3_7)))] #[cfg(all(not(any(PyPy, GraalPy)), not(Py_3_7)))]
opaque_struct!(PyCodeObject); opaque_struct!(PyCodeObject);
#[cfg(all(not(PyPy), Py_3_7, not(Py_3_8)))] #[cfg(all(not(any(PyPy, GraalPy)), Py_3_7, not(Py_3_8)))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PyCodeObject { pub struct PyCodeObject {
@ -102,7 +102,7 @@ pub struct PyCodeObject {
pub co_extra: *mut c_void, pub co_extra: *mut c_void,
} }
#[cfg(all(not(PyPy), Py_3_8, not(Py_3_11)))] #[cfg(all(not(any(PyPy, GraalPy)), Py_3_8, not(Py_3_11)))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PyCodeObject { pub struct PyCodeObject {
@ -136,7 +136,7 @@ pub struct PyCodeObject {
pub co_opcache_size: c_uchar, pub co_opcache_size: c_uchar,
} }
#[cfg(all(not(PyPy), Py_3_11))] #[cfg(all(not(any(PyPy, GraalPy)), Py_3_11))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PyCodeObject { pub struct PyCodeObject {
@ -230,26 +230,26 @@ pub const CO_FUTURE_GENERATOR_STOP: c_int = 0x8_0000;
pub const CO_MAXBLOCKS: usize = 20; pub const CO_MAXBLOCKS: usize = 20;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[cfg_attr(windows, link(name = "pythonXY"))] #[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" { extern "C" {
pub static mut PyCode_Type: PyTypeObject; pub static mut PyCode_Type: PyTypeObject;
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int { pub unsafe fn PyCode_Check(op: *mut PyObject) -> c_int {
(Py_TYPE(op) == addr_of_mut!(PyCode_Type)) as c_int (Py_TYPE(op) == addr_of_mut!(PyCode_Type)) as c_int
} }
#[inline] #[inline]
#[cfg(all(not(PyPy), Py_3_10, not(Py_3_11)))] #[cfg(all(not(any(PyPy, GraalPy)), Py_3_10, not(Py_3_11)))]
pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t { pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> Py_ssize_t {
crate::PyTuple_GET_SIZE((*op).co_freevars) crate::PyTuple_GET_SIZE((*op).co_freevars)
} }
#[inline] #[inline]
#[cfg(all(not(Py_3_10), Py_3_11, not(PyPy)))] #[cfg(all(not(Py_3_10), Py_3_11, not(any(PyPy, GraalPy))))]
pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> c_int { pub unsafe fn PyCode_GetNumFree(op: *mut PyCodeObject) -> c_int {
(*op).co_nfreevars (*op).co_nfreevars
} }
@ -265,6 +265,7 @@ extern "C" {
} }
extern "C" { extern "C" {
#[cfg(not(GraalPy))]
#[cfg_attr(PyPy, link_name = "PyPyCode_New")] #[cfg_attr(PyPy, link_name = "PyPyCode_New")]
pub fn PyCode_New( pub fn PyCode_New(
argcount: c_int, argcount: c_int,
@ -283,6 +284,7 @@ extern "C" {
firstlineno: c_int, firstlineno: c_int,
lnotab: *mut PyObject, lnotab: *mut PyObject,
) -> *mut PyCodeObject; ) -> *mut PyCodeObject;
#[cfg(not(GraalPy))]
#[cfg(Py_3_8)] #[cfg(Py_3_8)]
pub fn PyCode_NewWithPosOnlyArgs( pub fn PyCode_NewWithPosOnlyArgs(
argcount: c_int, argcount: c_int,
@ -302,12 +304,14 @@ extern "C" {
firstlineno: c_int, firstlineno: c_int,
lnotab: *mut PyObject, lnotab: *mut PyObject,
) -> *mut PyCodeObject; ) -> *mut PyCodeObject;
#[cfg(not(GraalPy))]
#[cfg_attr(PyPy, link_name = "PyPyCode_NewEmpty")] #[cfg_attr(PyPy, link_name = "PyPyCode_NewEmpty")]
pub fn PyCode_NewEmpty( pub fn PyCode_NewEmpty(
filename: *const c_char, filename: *const c_char,
funcname: *const c_char, funcname: *const c_char,
firstlineno: c_int, firstlineno: c_int,
) -> *mut PyCodeObject; ) -> *mut PyCodeObject;
#[cfg(not(GraalPy))]
pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int) -> c_int; pub fn PyCode_Addr2Line(arg1: *mut PyCodeObject, arg2: c_int) -> c_int;
// skipped PyCodeAddressRange "for internal use only" // skipped PyCodeAddressRange "for internal use only"
// skipped _PyCode_CheckLineNumber // skipped _PyCode_CheckLineNumber

View File

@ -30,7 +30,7 @@ pub struct PyCompilerFlags {
// skipped non-limited _PyCompilerFlags_INIT // skipped non-limited _PyCompilerFlags_INIT
#[cfg(all(Py_3_12, not(PyPy)))] #[cfg(all(Py_3_12, not(any(PyPy, GraalPy))))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct _PyCompilerSrcLocation { pub struct _PyCompilerSrcLocation {
@ -42,7 +42,7 @@ pub struct _PyCompilerSrcLocation {
// skipped SRC_LOCATION_FROM_AST // skipped SRC_LOCATION_FROM_AST
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PyFutureFeatures { pub struct PyFutureFeatures {

View File

@ -7,6 +7,7 @@ opaque_struct!(PyDictKeysObject);
#[cfg(Py_3_11)] #[cfg(Py_3_11)]
opaque_struct!(PyDictValues); opaque_struct!(PyDictValues);
#[cfg(not(GraalPy))]
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct PyDictObject { pub struct PyDictObject {

View File

@ -1,9 +1,12 @@
#[cfg(GraalPy)]
use crate::PyFloat_AsDouble;
use crate::{PyFloat_Check, PyObject}; use crate::{PyFloat_Check, PyObject};
use std::os::raw::c_double; use std::os::raw::c_double;
#[repr(C)] #[repr(C)]
pub struct PyFloatObject { pub struct PyFloatObject {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(GraalPy))]
pub ob_fval: c_double, pub ob_fval: c_double,
} }
@ -15,7 +18,10 @@ pub unsafe fn _PyFloat_CAST(op: *mut PyObject) -> *mut PyFloatObject {
#[inline] #[inline]
pub unsafe fn PyFloat_AS_DOUBLE(op: *mut PyObject) -> c_double { pub unsafe fn PyFloat_AS_DOUBLE(op: *mut PyObject) -> c_double {
(*_PyFloat_CAST(op)).ob_fval #[cfg(not(GraalPy))]
return (*_PyFloat_CAST(op)).ob_fval;
#[cfg(GraalPy)]
return PyFloat_AsDouble(op);
} }
// skipped PyFloat_Pack2 // skipped PyFloat_Pack2

View File

@ -1,17 +1,19 @@
#[cfg(not(GraalPy))]
use crate::cpython::code::PyCodeObject; use crate::cpython::code::PyCodeObject;
use crate::object::*; use crate::object::*;
#[cfg(not(GraalPy))]
use crate::pystate::PyThreadState; use crate::pystate::PyThreadState;
#[cfg(not(any(PyPy, Py_3_11)))] #[cfg(not(any(PyPy, GraalPy, Py_3_11)))]
use std::os::raw::c_char; use std::os::raw::c_char;
use std::os::raw::c_int; use std::os::raw::c_int;
use std::ptr::addr_of_mut; use std::ptr::addr_of_mut;
#[cfg(not(any(PyPy, Py_3_11)))] #[cfg(not(any(PyPy, GraalPy, Py_3_11)))]
pub type PyFrameState = c_char; pub type PyFrameState = c_char;
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[cfg(not(any(PyPy, Py_3_11)))] #[cfg(not(any(PyPy, GraalPy, Py_3_11)))]
pub struct PyTryBlock { pub struct PyTryBlock {
pub b_type: c_int, pub b_type: c_int,
pub b_handler: c_int, pub b_handler: c_int,
@ -20,7 +22,7 @@ pub struct PyTryBlock {
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[cfg(not(any(PyPy, Py_3_11)))] #[cfg(not(any(PyPy, GraalPy, Py_3_11)))]
pub struct PyFrameObject { pub struct PyFrameObject {
pub ob_base: PyVarObject, pub ob_base: PyVarObject,
pub f_back: *mut PyFrameObject, pub f_back: *mut PyFrameObject,
@ -51,7 +53,7 @@ pub struct PyFrameObject {
pub f_localsplus: [*mut PyObject; 1], pub f_localsplus: [*mut PyObject; 1],
} }
#[cfg(any(PyPy, Py_3_11))] #[cfg(any(PyPy, GraalPy, Py_3_11))]
opaque_struct!(PyFrameObject); opaque_struct!(PyFrameObject);
// skipped _PyFrame_IsRunnable // skipped _PyFrame_IsRunnable
@ -69,6 +71,7 @@ pub unsafe fn PyFrame_Check(op: *mut PyObject) -> c_int {
} }
extern "C" { extern "C" {
#[cfg(not(GraalPy))]
#[cfg_attr(PyPy, link_name = "PyPyFrame_New")] #[cfg_attr(PyPy, link_name = "PyPyFrame_New")]
pub fn PyFrame_New( pub fn PyFrame_New(
tstate: *mut PyThreadState, tstate: *mut PyThreadState,
@ -79,7 +82,7 @@ extern "C" {
// skipped _PyFrame_New_NoTrack // skipped _PyFrame_New_NoTrack
pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int); pub fn PyFrame_BlockSetup(f: *mut PyFrameObject, _type: c_int, handler: c_int, level: c_int);
#[cfg(not(any(PyPy, Py_3_11)))] #[cfg(not(any(PyPy, GraalPy, Py_3_11)))]
pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock; pub fn PyFrame_BlockPop(f: *mut PyFrameObject) -> *mut PyTryBlock;
pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int); pub fn PyFrame_LocalsToFast(f: *mut PyFrameObject, clear: c_int);

View File

@ -4,7 +4,7 @@ use std::ptr::addr_of_mut;
use crate::PyObject; use crate::PyObject;
#[cfg(all(not(PyPy), not(Py_3_10)))] #[cfg(all(not(any(PyPy, GraalPy)), not(Py_3_10)))]
#[repr(C)] #[repr(C)]
pub struct PyFunctionObject { pub struct PyFunctionObject {
pub ob_base: PyObject, pub ob_base: PyObject,
@ -24,7 +24,7 @@ pub struct PyFunctionObject {
pub vectorcall: Option<crate::vectorcallfunc>, pub vectorcall: Option<crate::vectorcallfunc>,
} }
#[cfg(all(not(PyPy), Py_3_10))] #[cfg(all(not(any(PyPy, GraalPy)), Py_3_10))]
#[repr(C)] #[repr(C)]
pub struct PyFunctionObject { pub struct PyFunctionObject {
pub ob_base: PyObject, pub ob_base: PyObject,
@ -55,6 +55,11 @@ pub struct PyFunctionObject {
pub func_name: *mut PyObject, pub func_name: *mut PyObject,
} }
#[cfg(GraalPy)]
pub struct PyFunctionObject {
pub ob_base: PyObject,
}
#[cfg_attr(windows, link(name = "pythonXY"))] #[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" { extern "C" {
#[cfg(not(all(PyPy, not(Py_3_8))))] #[cfg(not(all(PyPy, not(Py_3_8))))]

View File

@ -1,13 +1,13 @@
use crate::object::*; use crate::object::*;
use crate::PyFrameObject; use crate::PyFrameObject;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
use crate::_PyErr_StackItem; use crate::_PyErr_StackItem;
#[cfg(Py_3_11)] #[cfg(Py_3_11)]
use std::os::raw::c_char; use std::os::raw::c_char;
use std::os::raw::c_int; use std::os::raw::c_int;
use std::ptr::addr_of_mut; use std::ptr::addr_of_mut;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PyGenObject { pub struct PyGenObject {

View File

@ -2,7 +2,7 @@ use crate::object::*;
#[cfg(not(PyPy))] #[cfg(not(PyPy))]
use crate::pyport::Py_ssize_t; use crate::pyport::Py_ssize_t;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PyListObject { pub struct PyListObject {
@ -11,7 +11,7 @@ pub struct PyListObject {
pub allocated: Py_ssize_t, pub allocated: Py_ssize_t,
} }
#[cfg(PyPy)] #[cfg(any(PyPy, GraalPy))]
pub struct PyListObject { pub struct PyListObject {
pub ob_base: PyObject, pub ob_base: PyObject,
} }
@ -22,14 +22,14 @@ pub struct PyListObject {
/// Macro, trading safety for speed /// Macro, trading safety for speed
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub unsafe fn PyList_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { pub unsafe fn PyList_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject {
*(*(op as *mut PyListObject)).ob_item.offset(i) *(*(op as *mut PyListObject)).ob_item.offset(i)
} }
/// Macro, *only* to be used to fill in brand new lists /// Macro, *only* to be used to fill in brand new lists
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub unsafe fn PyList_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) { pub unsafe fn PyList_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) {
*(*(op as *mut PyListObject)).ob_item.offset(i) = v; *(*(op as *mut PyListObject)).ob_item.offset(i) = v;
} }

View File

@ -1,8 +1,10 @@
use crate::object::*; use crate::object::*;
#[cfg(not(GraalPy))]
use crate::{PyCFunctionObject, PyMethodDefPointer, METH_METHOD, METH_STATIC}; use crate::{PyCFunctionObject, PyMethodDefPointer, METH_METHOD, METH_STATIC};
use std::os::raw::c_int; use std::os::raw::c_int;
use std::ptr::addr_of_mut; use std::ptr::addr_of_mut;
#[cfg(not(GraalPy))]
pub struct PyCMethodObject { pub struct PyCMethodObject {
pub func: PyCFunctionObject, pub func: PyCFunctionObject,
pub mm_class: *mut PyTypeObject, pub mm_class: *mut PyTypeObject,
@ -23,6 +25,7 @@ pub unsafe fn PyCMethod_Check(op: *mut PyObject) -> c_int {
PyObject_TypeCheck(op, addr_of_mut!(PyCMethod_Type)) PyObject_TypeCheck(op, addr_of_mut!(PyCMethod_Type))
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyCFunction_GET_FUNCTION(func: *mut PyObject) -> PyMethodDefPointer { pub unsafe fn PyCFunction_GET_FUNCTION(func: *mut PyObject) -> PyMethodDefPointer {
debug_assert_eq!(PyCMethod_Check(func), 1); debug_assert_eq!(PyCMethod_Check(func), 1);
@ -31,6 +34,7 @@ pub unsafe fn PyCFunction_GET_FUNCTION(func: *mut PyObject) -> PyMethodDefPointe
(*(*func).m_ml).ml_meth (*(*func).m_ml).ml_meth
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyCFunction_GET_SELF(func: *mut PyObject) -> *mut PyObject { pub unsafe fn PyCFunction_GET_SELF(func: *mut PyObject) -> *mut PyObject {
debug_assert_eq!(PyCMethod_Check(func), 1); debug_assert_eq!(PyCMethod_Check(func), 1);
@ -43,6 +47,7 @@ pub unsafe fn PyCFunction_GET_SELF(func: *mut PyObject) -> *mut PyObject {
} }
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyCFunction_GET_FLAGS(func: *mut PyObject) -> c_int { pub unsafe fn PyCFunction_GET_FLAGS(func: *mut PyObject) -> c_int {
debug_assert_eq!(PyCMethod_Check(func), 1); debug_assert_eq!(PyCMethod_Check(func), 1);
@ -51,6 +56,7 @@ pub unsafe fn PyCFunction_GET_FLAGS(func: *mut PyObject) -> c_int {
(*(*func).m_ml).ml_flags (*(*func).m_ml).ml_flags
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyCFunction_GET_CLASS(func: *mut PyObject) -> *mut PyTypeObject { pub unsafe fn PyCFunction_GET_CLASS(func: *mut PyObject) -> *mut PyTypeObject {
debug_assert_eq!(PyCMethod_Check(func), 1); debug_assert_eq!(PyCMethod_Check(func), 1);

View File

@ -68,5 +68,5 @@ pub use self::pystate::*;
pub use self::pythonrun::*; pub use self::pythonrun::*;
pub use self::tupleobject::*; pub use self::tupleobject::*;
pub use self::unicodeobject::*; pub use self::unicodeobject::*;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub use self::weakrefobject::*; pub use self::weakrefobject::*;

View File

@ -217,6 +217,8 @@ pub struct PyTypeObject {
pub ob_size: Py_ssize_t, pub ob_size: Py_ssize_t,
#[cfg(not(all(PyPy, not(Py_3_9))))] #[cfg(not(all(PyPy, not(Py_3_9))))]
pub ob_base: object::PyVarObject, pub ob_base: object::PyVarObject,
#[cfg(GraalPy)]
pub ob_size: Py_ssize_t,
pub tp_name: *const c_char, pub tp_name: *const c_char,
pub tp_basicsize: Py_ssize_t, pub tp_basicsize: Py_ssize_t,
pub tp_itemsize: Py_ssize_t, pub tp_itemsize: Py_ssize_t,

View File

@ -1,7 +1,7 @@
use libc::size_t; use libc::size_t;
use std::os::raw::c_int; use std::os::raw::c_int;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
use std::os::raw::c_void; use std::os::raw::c_void;
use crate::object::*; use crate::object::*;
@ -14,7 +14,7 @@ extern "C" {
pub fn _Py_GetAllocatedBlocks() -> crate::Py_ssize_t; pub fn _Py_GetAllocatedBlocks() -> crate::Py_ssize_t;
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PyObjectArenaAllocator { pub struct PyObjectArenaAllocator {
@ -23,7 +23,7 @@ pub struct PyObjectArenaAllocator {
pub free: Option<extern "C" fn(ctx: *mut c_void, ptr: *mut c_void, size: size_t)>, pub free: Option<extern "C" fn(ctx: *mut c_void, ptr: *mut c_void, size: size_t)>,
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
impl Default for PyObjectArenaAllocator { impl Default for PyObjectArenaAllocator {
#[inline] #[inline]
fn default() -> Self { fn default() -> Self {
@ -32,9 +32,9 @@ impl Default for PyObjectArenaAllocator {
} }
extern "C" { extern "C" {
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyObject_GetArenaAllocator(allocator: *mut PyObjectArenaAllocator); pub fn PyObject_GetArenaAllocator(allocator: *mut PyObjectArenaAllocator);
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyObject_SetArenaAllocator(allocator: *mut PyObjectArenaAllocator); pub fn PyObject_SetArenaAllocator(allocator: *mut PyObjectArenaAllocator);
#[cfg(Py_3_9)] #[cfg(Py_3_9)]

View File

@ -1,28 +1,28 @@
use crate::PyObject; use crate::PyObject;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
use crate::Py_ssize_t; use crate::Py_ssize_t;
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct PyBaseExceptionObject { pub struct PyBaseExceptionObject {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub dict: *mut PyObject, pub dict: *mut PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub args: *mut PyObject, pub args: *mut PyObject,
#[cfg(all(Py_3_11, not(PyPy)))] #[cfg(all(Py_3_11, not(any(PyPy, GraalPy))))]
pub notes: *mut PyObject, pub notes: *mut PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub traceback: *mut PyObject, pub traceback: *mut PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub context: *mut PyObject, pub context: *mut PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub cause: *mut PyObject, pub cause: *mut PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub suppress_context: char, pub suppress_context: char,
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct PySyntaxErrorObject { pub struct PySyntaxErrorObject {
@ -48,7 +48,7 @@ pub struct PySyntaxErrorObject {
pub print_file_and_line: *mut PyObject, pub print_file_and_line: *mut PyObject,
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct PyImportErrorObject { pub struct PyImportErrorObject {
@ -69,7 +69,7 @@ pub struct PyImportErrorObject {
pub name_from: *mut PyObject, pub name_from: *mut PyObject,
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct PyUnicodeErrorObject { pub struct PyUnicodeErrorObject {
@ -90,7 +90,7 @@ pub struct PyUnicodeErrorObject {
pub reason: *mut PyObject, pub reason: *mut PyObject,
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct PySystemExitObject { pub struct PySystemExitObject {
@ -107,7 +107,7 @@ pub struct PySystemExitObject {
pub code: *mut PyObject, pub code: *mut PyObject,
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct PyOSErrorObject { pub struct PyOSErrorObject {
@ -134,26 +134,26 @@ pub struct PyOSErrorObject {
#[derive(Debug)] #[derive(Debug)]
pub struct PyStopIterationObject { pub struct PyStopIterationObject {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub dict: *mut PyObject, pub dict: *mut PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub args: *mut PyObject, pub args: *mut PyObject,
#[cfg(all(Py_3_11, not(PyPy)))] #[cfg(all(Py_3_11, not(any(PyPy, GraalPy))))]
pub notes: *mut PyObject, pub notes: *mut PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub traceback: *mut PyObject, pub traceback: *mut PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub context: *mut PyObject, pub context: *mut PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub cause: *mut PyObject, pub cause: *mut PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub suppress_context: char, pub suppress_context: char,
pub value: *mut PyObject, pub value: *mut PyObject,
} }
extern "C" { extern "C" {
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn _PyErr_ChainExceptions(typ: *mut PyObject, val: *mut PyObject, tb: *mut PyObject); pub fn _PyErr_ChainExceptions(typ: *mut PyObject, val: *mut PyObject, tb: *mut PyObject);
} }

View File

@ -26,7 +26,7 @@ pub enum PyMemAllocatorDomain {
} }
// skipped PyMemAllocatorName // skipped PyMemAllocatorName
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PyMemAllocatorEx { pub struct PyMemAllocatorEx {
@ -40,10 +40,10 @@ pub struct PyMemAllocatorEx {
} }
extern "C" { extern "C" {
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyMem_GetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx); pub fn PyMem_GetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx);
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyMem_SetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx); pub fn PyMem_SetAllocator(domain: PyMemAllocatorDomain, allocator: *mut PyMemAllocatorEx);
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyMem_SetupDebugHooks(); pub fn PyMem_SetupDebugHooks();
} }

View File

@ -1,8 +1,8 @@
use crate::object::*; use crate::object::*;
#[cfg(not(any(PyPy, Py_LIMITED_API, Py_3_10)))] #[cfg(not(any(PyPy, GraalPy, Py_LIMITED_API, Py_3_10)))]
use crate::pyarena::PyArena; use crate::pyarena::PyArena;
use crate::PyCompilerFlags; use crate::PyCompilerFlags;
#[cfg(not(any(PyPy, Py_3_10)))] #[cfg(not(any(PyPy, GraalPy, Py_3_10)))]
use crate::{_mod, _node}; use crate::{_mod, _node};
use libc::FILE; use libc::FILE;
use std::os::raw::{c_char, c_int}; use std::os::raw::{c_char, c_int};
@ -54,7 +54,7 @@ extern "C" {
flags: *mut PyCompilerFlags, flags: *mut PyCompilerFlags,
) -> c_int; ) -> c_int;
#[cfg(not(any(PyPy, Py_3_10)))] #[cfg(not(any(PyPy, GraalPy, Py_3_10)))]
pub fn PyParser_ASTFromString( pub fn PyParser_ASTFromString(
s: *const c_char, s: *const c_char,
filename: *const c_char, filename: *const c_char,
@ -62,7 +62,7 @@ extern "C" {
flags: *mut PyCompilerFlags, flags: *mut PyCompilerFlags,
arena: *mut PyArena, arena: *mut PyArena,
) -> *mut _mod; ) -> *mut _mod;
#[cfg(not(any(PyPy, Py_3_10)))] #[cfg(not(any(PyPy, GraalPy, Py_3_10)))]
pub fn PyParser_ASTFromStringObject( pub fn PyParser_ASTFromStringObject(
s: *const c_char, s: *const c_char,
filename: *mut PyObject, filename: *mut PyObject,
@ -70,7 +70,7 @@ extern "C" {
flags: *mut PyCompilerFlags, flags: *mut PyCompilerFlags,
arena: *mut PyArena, arena: *mut PyArena,
) -> *mut _mod; ) -> *mut _mod;
#[cfg(not(any(PyPy, Py_3_10)))] #[cfg(not(any(PyPy, GraalPy, Py_3_10)))]
pub fn PyParser_ASTFromFile( pub fn PyParser_ASTFromFile(
fp: *mut FILE, fp: *mut FILE,
filename: *const c_char, filename: *const c_char,
@ -82,7 +82,7 @@ extern "C" {
errcode: *mut c_int, errcode: *mut c_int,
arena: *mut PyArena, arena: *mut PyArena,
) -> *mut _mod; ) -> *mut _mod;
#[cfg(not(any(PyPy, Py_3_10)))] #[cfg(not(any(PyPy, GraalPy, Py_3_10)))]
pub fn PyParser_ASTFromFileObject( pub fn PyParser_ASTFromFileObject(
fp: *mut FILE, fp: *mut FILE,
filename: *mut PyObject, filename: *mut PyObject,
@ -105,7 +105,7 @@ extern "C" {
arg4: *mut PyObject, arg4: *mut PyObject,
arg5: *mut PyCompilerFlags, arg5: *mut PyCompilerFlags,
) -> *mut PyObject; ) -> *mut PyObject;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyRun_FileExFlags( pub fn PyRun_FileExFlags(
fp: *mut FILE, fp: *mut FILE,
filename: *const c_char, filename: *const c_char,
@ -116,7 +116,7 @@ extern "C" {
flags: *mut PyCompilerFlags, flags: *mut PyCompilerFlags,
) -> *mut PyObject; ) -> *mut PyObject;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn Py_CompileStringExFlags( pub fn Py_CompileStringExFlags(
str: *const c_char, str: *const c_char,
filename: *const c_char, filename: *const c_char,
@ -135,6 +135,7 @@ extern "C" {
} }
#[inline] #[inline]
#[cfg(not(GraalPy))]
pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject { pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject {
#[cfg(not(PyPy))] #[cfg(not(PyPy))]
return Py_CompileStringExFlags(string, p, s, std::ptr::null_mut(), -1); return Py_CompileStringExFlags(string, p, s, std::ptr::null_mut(), -1);
@ -144,7 +145,7 @@ pub unsafe fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub unsafe fn Py_CompileStringFlags( pub unsafe fn Py_CompileStringFlags(
string: *const c_char, string: *const c_char,
p: *const c_char, p: *const c_char,
@ -164,11 +165,11 @@ extern "C" {
g: *mut PyObject, g: *mut PyObject,
l: *mut PyObject, l: *mut PyObject,
) -> *mut PyObject; ) -> *mut PyObject;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyRun_AnyFile(fp: *mut FILE, name: *const c_char) -> c_int; pub fn PyRun_AnyFile(fp: *mut FILE, name: *const c_char) -> c_int;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyRun_AnyFileEx(fp: *mut FILE, name: *const c_char, closeit: c_int) -> c_int; pub fn PyRun_AnyFileEx(fp: *mut FILE, name: *const c_char, closeit: c_int) -> c_int;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyRun_AnyFileFlags( pub fn PyRun_AnyFileFlags(
arg1: *mut FILE, arg1: *mut FILE,
arg2: *const c_char, arg2: *const c_char,
@ -176,13 +177,13 @@ extern "C" {
) -> c_int; ) -> c_int;
#[cfg_attr(PyPy, link_name = "PyPyRun_SimpleString")] #[cfg_attr(PyPy, link_name = "PyPyRun_SimpleString")]
pub fn PyRun_SimpleString(s: *const c_char) -> c_int; pub fn PyRun_SimpleString(s: *const c_char) -> c_int;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyRun_SimpleFile(f: *mut FILE, p: *const c_char) -> c_int; pub fn PyRun_SimpleFile(f: *mut FILE, p: *const c_char) -> c_int;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyRun_SimpleFileEx(f: *mut FILE, p: *const c_char, c: c_int) -> c_int; pub fn PyRun_SimpleFileEx(f: *mut FILE, p: *const c_char, c: c_int) -> c_int;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyRun_InteractiveOne(f: *mut FILE, p: *const c_char) -> c_int; pub fn PyRun_InteractiveOne(f: *mut FILE, p: *const c_char) -> c_int;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyRun_InteractiveLoop(f: *mut FILE, p: *const c_char) -> c_int; pub fn PyRun_InteractiveLoop(f: *mut FILE, p: *const c_char) -> c_int;
#[cfg_attr(PyPy, link_name = "PyPyRun_File")] #[cfg_attr(PyPy, link_name = "PyPyRun_File")]
pub fn PyRun_File( pub fn PyRun_File(
@ -192,7 +193,7 @@ extern "C" {
g: *mut PyObject, g: *mut PyObject,
l: *mut PyObject, l: *mut PyObject,
) -> *mut PyObject; ) -> *mut PyObject;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyRun_FileEx( pub fn PyRun_FileEx(
fp: *mut FILE, fp: *mut FILE,
p: *const c_char, p: *const c_char,
@ -201,7 +202,7 @@ extern "C" {
l: *mut PyObject, l: *mut PyObject,
c: c_int, c: c_int,
) -> *mut PyObject; ) -> *mut PyObject;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn PyRun_FileFlags( pub fn PyRun_FileFlags(
fp: *mut FILE, fp: *mut FILE,
p: *const c_char, p: *const c_char,
@ -218,14 +219,14 @@ extern "C" {
// skipped macro PyRun_AnyFileFlags // skipped macro PyRun_AnyFileFlags
extern "C" { extern "C" {
#[cfg(not(any(PyPy, Py_3_10)))] #[cfg(not(any(PyPy, GraalPy, Py_3_10)))]
#[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))] #[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))]
pub fn PyParser_SimpleParseStringFlags( pub fn PyParser_SimpleParseStringFlags(
arg1: *const c_char, arg1: *const c_char,
arg2: c_int, arg2: c_int,
arg3: c_int, arg3: c_int,
) -> *mut _node; ) -> *mut _node;
#[cfg(not(any(PyPy, Py_3_10)))] #[cfg(not(any(PyPy, GraalPy, Py_3_10)))]
#[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))] #[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))]
pub fn PyParser_SimpleParseStringFlagsFilename( pub fn PyParser_SimpleParseStringFlagsFilename(
arg1: *const c_char, arg1: *const c_char,
@ -233,7 +234,7 @@ extern "C" {
arg3: c_int, arg3: c_int,
arg4: c_int, arg4: c_int,
) -> *mut _node; ) -> *mut _node;
#[cfg(not(any(PyPy, Py_3_10)))] #[cfg(not(any(PyPy, GraalPy, Py_3_10)))]
#[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))] #[cfg_attr(Py_3_9, deprecated(note = "Python 3.9"))]
pub fn PyParser_SimpleParseFileFlags( pub fn PyParser_SimpleParseFileFlags(
arg1: *mut FILE, arg1: *mut FILE,

View File

@ -5,6 +5,7 @@ use crate::pyport::Py_ssize_t;
#[repr(C)] #[repr(C)]
pub struct PyTupleObject { pub struct PyTupleObject {
pub ob_base: PyVarObject, pub ob_base: PyVarObject,
#[cfg(not(GraalPy))]
pub ob_item: [*mut PyObject; 1], pub ob_item: [*mut PyObject; 1],
} }
@ -22,14 +23,14 @@ pub unsafe fn PyTuple_GET_SIZE(op: *mut PyObject) -> Py_ssize_t {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub unsafe fn PyTuple_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { pub unsafe fn PyTuple_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject {
*(*(op as *mut PyTupleObject)).ob_item.as_ptr().offset(i) *(*(op as *mut PyTupleObject)).ob_item.as_ptr().offset(i)
} }
/// Macro, *only* to be used to fill in brand new tuples /// Macro, *only* to be used to fill in brand new tuples
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub unsafe fn PyTuple_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) { pub unsafe fn PyTuple_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) {
*(*(op as *mut PyTupleObject)).ob_item.as_mut_ptr().offset(i) = v; *(*(op as *mut PyTupleObject)).ob_item.as_mut_ptr().offset(i) = v;
} }

View File

@ -1,7 +1,7 @@
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
use crate::Py_hash_t; use crate::Py_hash_t;
use crate::{PyObject, Py_UCS1, Py_UCS2, Py_UCS4, Py_UNICODE, Py_ssize_t}; use crate::{PyObject, Py_UCS1, Py_UCS2, Py_UCS4, Py_UNICODE, Py_ssize_t};
#[cfg(not(Py_3_12))] #[cfg(not(any(Py_3_12, GraalPy)))]
use libc::wchar_t; use libc::wchar_t;
use std::os::raw::{c_char, c_int, c_uint, c_void}; use std::os::raw::{c_char, c_int, c_uint, c_void};
@ -44,6 +44,7 @@ impl<Storage> BitfieldUnit<Storage> {
} }
} }
#[cfg(not(GraalPy))]
impl<Storage> BitfieldUnit<Storage> impl<Storage> BitfieldUnit<Storage>
where where
Storage: AsRef<[u8]> + AsMut<[u8]>, Storage: AsRef<[u8]> + AsMut<[u8]>,
@ -117,23 +118,31 @@ where
} }
} }
#[cfg(not(GraalPy))]
const STATE_INTERNED_INDEX: usize = 0; const STATE_INTERNED_INDEX: usize = 0;
#[cfg(not(GraalPy))]
const STATE_INTERNED_WIDTH: u8 = 2; const STATE_INTERNED_WIDTH: u8 = 2;
#[cfg(not(GraalPy))]
const STATE_KIND_INDEX: usize = STATE_INTERNED_WIDTH as usize; const STATE_KIND_INDEX: usize = STATE_INTERNED_WIDTH as usize;
#[cfg(not(GraalPy))]
const STATE_KIND_WIDTH: u8 = 3; const STATE_KIND_WIDTH: u8 = 3;
#[cfg(not(GraalPy))]
const STATE_COMPACT_INDEX: usize = (STATE_INTERNED_WIDTH + STATE_KIND_WIDTH) as usize; const STATE_COMPACT_INDEX: usize = (STATE_INTERNED_WIDTH + STATE_KIND_WIDTH) as usize;
#[cfg(not(GraalPy))]
const STATE_COMPACT_WIDTH: u8 = 1; const STATE_COMPACT_WIDTH: u8 = 1;
#[cfg(not(GraalPy))]
const STATE_ASCII_INDEX: usize = const STATE_ASCII_INDEX: usize =
(STATE_INTERNED_WIDTH + STATE_KIND_WIDTH + STATE_COMPACT_WIDTH) as usize; (STATE_INTERNED_WIDTH + STATE_KIND_WIDTH + STATE_COMPACT_WIDTH) as usize;
#[cfg(not(GraalPy))]
const STATE_ASCII_WIDTH: u8 = 1; const STATE_ASCII_WIDTH: u8 = 1;
#[cfg(not(Py_3_12))] #[cfg(not(any(Py_3_12, GraalPy)))]
const STATE_READY_INDEX: usize = const STATE_READY_INDEX: usize =
(STATE_INTERNED_WIDTH + STATE_KIND_WIDTH + STATE_COMPACT_WIDTH + STATE_ASCII_WIDTH) as usize; (STATE_INTERNED_WIDTH + STATE_KIND_WIDTH + STATE_COMPACT_WIDTH + STATE_ASCII_WIDTH) as usize;
#[cfg(not(Py_3_12))] #[cfg(not(any(Py_3_12, GraalPy)))]
const STATE_READY_WIDTH: u8 = 1; const STATE_READY_WIDTH: u8 = 1;
// generated by bindgen v0.63.0 (with small adaptations) // generated by bindgen v0.63.0 (with small adaptations)
@ -153,6 +162,7 @@ struct PyASCIIObjectState {
} }
// c_uint and u32 are not necessarily the same type on all targets / architectures // c_uint and u32 are not necessarily the same type on all targets / architectures
#[cfg(not(GraalPy))]
#[allow(clippy::useless_transmute)] #[allow(clippy::useless_transmute)]
impl PyASCIIObjectState { impl PyASCIIObjectState {
#[inline] #[inline]
@ -241,8 +251,9 @@ impl From<PyASCIIObjectState> for u32 {
#[repr(C)] #[repr(C)]
pub struct PyASCIIObject { pub struct PyASCIIObject {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(GraalPy))]
pub length: Py_ssize_t, pub length: Py_ssize_t,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub hash: Py_hash_t, pub hash: Py_hash_t,
/// A bit field with various properties. /// A bit field with various properties.
/// ///
@ -255,12 +266,14 @@ pub struct PyASCIIObject {
/// unsigned int ascii:1; /// unsigned int ascii:1;
/// unsigned int ready:1; /// unsigned int ready:1;
/// unsigned int :24; /// unsigned int :24;
#[cfg(not(GraalPy))]
pub state: u32, pub state: u32,
#[cfg(not(Py_3_12))] #[cfg(not(any(Py_3_12, GraalPy)))]
pub wstr: *mut wchar_t, pub wstr: *mut wchar_t,
} }
/// Interacting with the bitfield is not actually well-defined, so we mark these APIs unsafe. /// Interacting with the bitfield is not actually well-defined, so we mark these APIs unsafe.
#[cfg(not(GraalPy))]
impl PyASCIIObject { impl PyASCIIObject {
#[cfg_attr(not(Py_3_12), allow(rustdoc::broken_intra_doc_links))] // SSTATE_INTERNED_IMMORTAL_STATIC requires 3.12 #[cfg_attr(not(Py_3_12), allow(rustdoc::broken_intra_doc_links))] // SSTATE_INTERNED_IMMORTAL_STATIC requires 3.12
/// Get the `interned` field of the [`PyASCIIObject`] state bitfield. /// Get the `interned` field of the [`PyASCIIObject`] state bitfield.
@ -367,9 +380,11 @@ impl PyASCIIObject {
#[repr(C)] #[repr(C)]
pub struct PyCompactUnicodeObject { pub struct PyCompactUnicodeObject {
pub _base: PyASCIIObject, pub _base: PyASCIIObject,
#[cfg(not(GraalPy))]
pub utf8_length: Py_ssize_t, pub utf8_length: Py_ssize_t,
#[cfg(not(GraalPy))]
pub utf8: *mut c_char, pub utf8: *mut c_char,
#[cfg(not(Py_3_12))] #[cfg(not(any(Py_3_12, GraalPy)))]
pub wstr_length: Py_ssize_t, pub wstr_length: Py_ssize_t,
} }
@ -384,11 +399,12 @@ pub union PyUnicodeObjectData {
#[repr(C)] #[repr(C)]
pub struct PyUnicodeObject { pub struct PyUnicodeObject {
pub _base: PyCompactUnicodeObject, pub _base: PyCompactUnicodeObject,
#[cfg(not(GraalPy))]
pub data: PyUnicodeObjectData, pub data: PyUnicodeObjectData,
} }
extern "C" { extern "C" {
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn _PyUnicode_CheckConsistency(op: *mut PyObject, check_content: c_int) -> c_int; pub fn _PyUnicode_CheckConsistency(op: *mut PyObject, check_content: c_int) -> c_int;
} }
@ -403,6 +419,7 @@ pub const SSTATE_INTERNED_IMMORTAL: c_uint = 2;
#[cfg(Py_3_12)] #[cfg(Py_3_12)]
pub const SSTATE_INTERNED_IMMORTAL_STATIC: c_uint = 3; pub const SSTATE_INTERNED_IMMORTAL_STATIC: c_uint = 3;
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyUnicode_IS_ASCII(op: *mut PyObject) -> c_uint { pub unsafe fn PyUnicode_IS_ASCII(op: *mut PyObject) -> c_uint {
debug_assert!(crate::PyUnicode_Check(op) != 0); debug_assert!(crate::PyUnicode_Check(op) != 0);
@ -412,11 +429,13 @@ pub unsafe fn PyUnicode_IS_ASCII(op: *mut PyObject) -> c_uint {
(*(op as *mut PyASCIIObject)).ascii() (*(op as *mut PyASCIIObject)).ascii()
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyUnicode_IS_COMPACT(op: *mut PyObject) -> c_uint { pub unsafe fn PyUnicode_IS_COMPACT(op: *mut PyObject) -> c_uint {
(*(op as *mut PyASCIIObject)).compact() (*(op as *mut PyASCIIObject)).compact()
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyUnicode_IS_COMPACT_ASCII(op: *mut PyObject) -> c_uint { pub unsafe fn PyUnicode_IS_COMPACT_ASCII(op: *mut PyObject) -> c_uint {
((*(op as *mut PyASCIIObject)).ascii() != 0 && PyUnicode_IS_COMPACT(op) != 0).into() ((*(op as *mut PyASCIIObject)).ascii() != 0 && PyUnicode_IS_COMPACT(op) != 0).into()
@ -430,21 +449,25 @@ pub const PyUnicode_1BYTE_KIND: c_uint = 1;
pub const PyUnicode_2BYTE_KIND: c_uint = 2; pub const PyUnicode_2BYTE_KIND: c_uint = 2;
pub const PyUnicode_4BYTE_KIND: c_uint = 4; pub const PyUnicode_4BYTE_KIND: c_uint = 4;
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyUnicode_1BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS1 { pub unsafe fn PyUnicode_1BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS1 {
PyUnicode_DATA(op) as *mut Py_UCS1 PyUnicode_DATA(op) as *mut Py_UCS1
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyUnicode_2BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS2 { pub unsafe fn PyUnicode_2BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS2 {
PyUnicode_DATA(op) as *mut Py_UCS2 PyUnicode_DATA(op) as *mut Py_UCS2
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyUnicode_4BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS4 { pub unsafe fn PyUnicode_4BYTE_DATA(op: *mut PyObject) -> *mut Py_UCS4 {
PyUnicode_DATA(op) as *mut Py_UCS4 PyUnicode_DATA(op) as *mut Py_UCS4
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyUnicode_KIND(op: *mut PyObject) -> c_uint { pub unsafe fn PyUnicode_KIND(op: *mut PyObject) -> c_uint {
debug_assert!(crate::PyUnicode_Check(op) != 0); debug_assert!(crate::PyUnicode_Check(op) != 0);
@ -454,6 +477,7 @@ pub unsafe fn PyUnicode_KIND(op: *mut PyObject) -> c_uint {
(*(op as *mut PyASCIIObject)).kind() (*(op as *mut PyASCIIObject)).kind()
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn _PyUnicode_COMPACT_DATA(op: *mut PyObject) -> *mut c_void { pub unsafe fn _PyUnicode_COMPACT_DATA(op: *mut PyObject) -> *mut c_void {
if PyUnicode_IS_ASCII(op) != 0 { if PyUnicode_IS_ASCII(op) != 0 {
@ -463,6 +487,7 @@ pub unsafe fn _PyUnicode_COMPACT_DATA(op: *mut PyObject) -> *mut c_void {
} }
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn _PyUnicode_NONCOMPACT_DATA(op: *mut PyObject) -> *mut c_void { pub unsafe fn _PyUnicode_NONCOMPACT_DATA(op: *mut PyObject) -> *mut c_void {
debug_assert!(!(*(op as *mut PyUnicodeObject)).data.any.is_null()); debug_assert!(!(*(op as *mut PyUnicodeObject)).data.any.is_null());
@ -470,6 +495,7 @@ pub unsafe fn _PyUnicode_NONCOMPACT_DATA(op: *mut PyObject) -> *mut c_void {
(*(op as *mut PyUnicodeObject)).data.any (*(op as *mut PyUnicodeObject)).data.any
} }
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyUnicode_DATA(op: *mut PyObject) -> *mut c_void { pub unsafe fn PyUnicode_DATA(op: *mut PyObject) -> *mut c_void {
debug_assert!(crate::PyUnicode_Check(op) != 0); debug_assert!(crate::PyUnicode_Check(op) != 0);
@ -485,6 +511,7 @@ pub unsafe fn PyUnicode_DATA(op: *mut PyObject) -> *mut c_void {
// skipped PyUnicode_READ // skipped PyUnicode_READ
// skipped PyUnicode_READ_CHAR // skipped PyUnicode_READ_CHAR
#[cfg(not(GraalPy))]
#[inline] #[inline]
pub unsafe fn PyUnicode_GET_LENGTH(op: *mut PyObject) -> Py_ssize_t { pub unsafe fn PyUnicode_GET_LENGTH(op: *mut PyObject) -> Py_ssize_t {
debug_assert!(crate::PyUnicode_Check(op) != 0); debug_assert!(crate::PyUnicode_Check(op) != 0);
@ -494,26 +521,26 @@ pub unsafe fn PyUnicode_GET_LENGTH(op: *mut PyObject) -> Py_ssize_t {
(*(op as *mut PyASCIIObject)).length (*(op as *mut PyASCIIObject)).length
} }
#[cfg(Py_3_12)] #[cfg(any(Py_3_12, GraalPy))]
#[inline] #[inline]
pub unsafe fn PyUnicode_IS_READY(_op: *mut PyObject) -> c_uint { pub unsafe fn PyUnicode_IS_READY(_op: *mut PyObject) -> c_uint {
// kept in CPython for backwards compatibility // kept in CPython for backwards compatibility
1 1
} }
#[cfg(not(Py_3_12))] #[cfg(not(any(GraalPy, Py_3_12)))]
#[inline] #[inline]
pub unsafe fn PyUnicode_IS_READY(op: *mut PyObject) -> c_uint { pub unsafe fn PyUnicode_IS_READY(op: *mut PyObject) -> c_uint {
(*(op as *mut PyASCIIObject)).ready() (*(op as *mut PyASCIIObject)).ready()
} }
#[cfg(Py_3_12)] #[cfg(any(Py_3_12, GraalPy))]
#[inline] #[inline]
pub unsafe fn PyUnicode_READY(_op: *mut PyObject) -> c_int { pub unsafe fn PyUnicode_READY(_op: *mut PyObject) -> c_int {
0 0
} }
#[cfg(not(Py_3_12))] #[cfg(not(any(Py_3_12, GraalPy)))]
#[inline] #[inline]
pub unsafe fn PyUnicode_READY(op: *mut PyObject) -> c_int { pub unsafe fn PyUnicode_READY(op: *mut PyObject) -> c_int {
debug_assert!(crate::PyUnicode_Check(op) != 0); debug_assert!(crate::PyUnicode_Check(op) != 0);

View File

@ -1,4 +1,4 @@
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub struct _PyWeakReference { pub struct _PyWeakReference {
pub ob_base: crate::PyObject, pub ob_base: crate::PyObject,
pub wr_object: *mut crate::PyObject, pub wr_object: *mut crate::PyObject,

View File

@ -9,17 +9,16 @@
//! Support for `PyDateTime_CAPI` is limited as of PyPy 7.0.0. //! Support for `PyDateTime_CAPI` is limited as of PyPy 7.0.0.
//! `DateTime_FromTimestamp` and `Date_FromTimestamp` are currently not supported. //! `DateTime_FromTimestamp` and `Date_FromTimestamp` are currently not supported.
#[cfg(GraalPy)]
use crate::{PyLong_AsLong, PyLong_Check, PyObject_GetAttrString, Py_DecRef};
use crate::{PyObject, PyObject_TypeCheck, PyTypeObject, Py_TYPE}; use crate::{PyObject, PyObject_TypeCheck, PyTypeObject, Py_TYPE};
use std::cell::UnsafeCell; use std::cell::UnsafeCell;
use std::os::raw::{c_char, c_int}; use std::os::raw::{c_char, c_int};
use std::ptr; use std::ptr;
#[cfg(not(PyPy))] #[cfg(not(PyPy))]
use { use {crate::PyCapsule_Import, std::ffi::CString};
crate::{PyCapsule_Import, Py_hash_t}, #[cfg(not(any(PyPy, GraalPy)))]
std::ffi::CString, use {crate::Py_hash_t, std::os::raw::c_uchar};
std::os::raw::c_uchar,
};
// Type struct wrappers // Type struct wrappers
const _PyDateTime_DATE_DATASIZE: usize = 4; const _PyDateTime_DATE_DATASIZE: usize = 4;
const _PyDateTime_TIME_DATASIZE: usize = 6; const _PyDateTime_TIME_DATASIZE: usize = 6;
@ -30,26 +29,27 @@ const _PyDateTime_DATETIME_DATASIZE: usize = 10;
/// Structure representing a `datetime.timedelta`. /// Structure representing a `datetime.timedelta`.
pub struct PyDateTime_Delta { pub struct PyDateTime_Delta {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub hashcode: Py_hash_t, pub hashcode: Py_hash_t,
#[cfg(not(GraalPy))]
pub days: c_int, pub days: c_int,
#[cfg(not(GraalPy))]
pub seconds: c_int, pub seconds: c_int,
#[cfg(not(GraalPy))]
pub microseconds: c_int, pub microseconds: c_int,
} }
// skipped non-limited PyDateTime_TZInfo // skipped non-limited PyDateTime_TZInfo
// skipped non-limited _PyDateTime_BaseTZInfo // skipped non-limited _PyDateTime_BaseTZInfo
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
/// Structure representing a `datetime.time` without a `tzinfo` member. /// Structure representing a `datetime.time` without a `tzinfo` member.
pub struct _PyDateTime_BaseTime { pub struct _PyDateTime_BaseTime {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(PyPy))]
pub hashcode: Py_hash_t, pub hashcode: Py_hash_t,
pub hastzinfo: c_char, pub hastzinfo: c_char,
#[cfg(not(PyPy))]
pub data: [c_uchar; _PyDateTime_TIME_DATASIZE], pub data: [c_uchar; _PyDateTime_TIME_DATASIZE],
} }
@ -58,17 +58,19 @@ pub struct _PyDateTime_BaseTime {
/// Structure representing a `datetime.time`. /// Structure representing a `datetime.time`.
pub struct PyDateTime_Time { pub struct PyDateTime_Time {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub hashcode: Py_hash_t, pub hashcode: Py_hash_t,
#[cfg(not(GraalPy))]
pub hastzinfo: c_char, pub hastzinfo: c_char,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub data: [c_uchar; _PyDateTime_TIME_DATASIZE], pub data: [c_uchar; _PyDateTime_TIME_DATASIZE],
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fold: c_uchar, pub fold: c_uchar,
/// # Safety /// # Safety
/// ///
/// Care should be taken when reading this field. If the time does not have a /// Care should be taken when reading this field. If the time does not have a
/// tzinfo then CPython may allocate as a `_PyDateTime_BaseTime` without this field. /// tzinfo then CPython may allocate as a `_PyDateTime_BaseTime` without this field.
#[cfg(not(GraalPy))]
pub tzinfo: *mut PyObject, pub tzinfo: *mut PyObject,
} }
@ -77,24 +79,22 @@ pub struct PyDateTime_Time {
/// Structure representing a `datetime.date` /// Structure representing a `datetime.date`
pub struct PyDateTime_Date { pub struct PyDateTime_Date {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub hashcode: Py_hash_t, pub hashcode: Py_hash_t,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub hastzinfo: c_char, pub hastzinfo: c_char,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub data: [c_uchar; _PyDateTime_DATE_DATASIZE], pub data: [c_uchar; _PyDateTime_DATE_DATASIZE],
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
/// Structure representing a `datetime.datetime` without a `tzinfo` member. /// Structure representing a `datetime.datetime` without a `tzinfo` member.
pub struct _PyDateTime_BaseDateTime { pub struct _PyDateTime_BaseDateTime {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(PyPy))]
pub hashcode: Py_hash_t, pub hashcode: Py_hash_t,
pub hastzinfo: c_char, pub hastzinfo: c_char,
#[cfg(not(PyPy))]
pub data: [c_uchar; _PyDateTime_DATETIME_DATASIZE], pub data: [c_uchar; _PyDateTime_DATETIME_DATASIZE],
} }
@ -103,17 +103,19 @@ pub struct _PyDateTime_BaseDateTime {
/// Structure representing a `datetime.datetime`. /// Structure representing a `datetime.datetime`.
pub struct PyDateTime_DateTime { pub struct PyDateTime_DateTime {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub hashcode: Py_hash_t, pub hashcode: Py_hash_t,
#[cfg(not(GraalPy))]
pub hastzinfo: c_char, pub hastzinfo: c_char,
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub data: [c_uchar; _PyDateTime_DATETIME_DATASIZE], pub data: [c_uchar; _PyDateTime_DATETIME_DATASIZE],
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fold: c_uchar, pub fold: c_uchar,
/// # Safety /// # Safety
/// ///
/// Care should be taken when reading this field. If the time does not have a /// Care should be taken when reading this field. If the time does not have a
/// tzinfo then CPython may allocate as a `_PyDateTime_BaseDateTime` without this field. /// tzinfo then CPython may allocate as a `_PyDateTime_BaseDateTime` without this field.
#[cfg(not(GraalPy))]
pub tzinfo: *mut PyObject, pub tzinfo: *mut PyObject,
} }
@ -121,7 +123,7 @@ pub struct PyDateTime_DateTime {
// Accessor functions for PyDateTime_Date and PyDateTime_DateTime // Accessor functions for PyDateTime_Date and PyDateTime_DateTime
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the year component of a `PyDateTime_Date` or `PyDateTime_DateTime`. /// Retrieve the year component of a `PyDateTime_Date` or `PyDateTime_DateTime`.
/// Returns a signed integer greater than 0. /// Returns a signed integer greater than 0.
pub unsafe fn PyDateTime_GET_YEAR(o: *mut PyObject) -> c_int { pub unsafe fn PyDateTime_GET_YEAR(o: *mut PyObject) -> c_int {
@ -131,7 +133,7 @@ pub unsafe fn PyDateTime_GET_YEAR(o: *mut PyObject) -> c_int {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the month component of a `PyDateTime_Date` or `PyDateTime_DateTime`. /// Retrieve the month component of a `PyDateTime_Date` or `PyDateTime_DateTime`.
/// Returns a signed integer in the range `[1, 12]`. /// Returns a signed integer in the range `[1, 12]`.
pub unsafe fn PyDateTime_GET_MONTH(o: *mut PyObject) -> c_int { pub unsafe fn PyDateTime_GET_MONTH(o: *mut PyObject) -> c_int {
@ -140,7 +142,7 @@ pub unsafe fn PyDateTime_GET_MONTH(o: *mut PyObject) -> c_int {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the day component of a `PyDateTime_Date` or `PyDateTime_DateTime`. /// Retrieve the day component of a `PyDateTime_Date` or `PyDateTime_DateTime`.
/// Returns a signed integer in the interval `[1, 31]`. /// Returns a signed integer in the interval `[1, 31]`.
pub unsafe fn PyDateTime_GET_DAY(o: *mut PyObject) -> c_int { pub unsafe fn PyDateTime_GET_DAY(o: *mut PyObject) -> c_int {
@ -149,28 +151,28 @@ pub unsafe fn PyDateTime_GET_DAY(o: *mut PyObject) -> c_int {
} }
// Accessor macros for times // Accessor macros for times
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
macro_rules! _PyDateTime_GET_HOUR { macro_rules! _PyDateTime_GET_HOUR {
($o: expr, $offset:expr) => { ($o: expr, $offset:expr) => {
c_int::from((*$o).data[$offset + 0]) c_int::from((*$o).data[$offset + 0])
}; };
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
macro_rules! _PyDateTime_GET_MINUTE { macro_rules! _PyDateTime_GET_MINUTE {
($o: expr, $offset:expr) => { ($o: expr, $offset:expr) => {
c_int::from((*$o).data[$offset + 1]) c_int::from((*$o).data[$offset + 1])
}; };
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
macro_rules! _PyDateTime_GET_SECOND { macro_rules! _PyDateTime_GET_SECOND {
($o: expr, $offset:expr) => { ($o: expr, $offset:expr) => {
c_int::from((*$o).data[$offset + 2]) c_int::from((*$o).data[$offset + 2])
}; };
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
macro_rules! _PyDateTime_GET_MICROSECOND { macro_rules! _PyDateTime_GET_MICROSECOND {
($o: expr, $offset:expr) => { ($o: expr, $offset:expr) => {
(c_int::from((*$o).data[$offset + 3]) << 16) (c_int::from((*$o).data[$offset + 3]) << 16)
@ -179,14 +181,14 @@ macro_rules! _PyDateTime_GET_MICROSECOND {
}; };
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
macro_rules! _PyDateTime_GET_FOLD { macro_rules! _PyDateTime_GET_FOLD {
($o: expr) => { ($o: expr) => {
(*$o).fold (*$o).fold
}; };
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
macro_rules! _PyDateTime_GET_TZINFO { macro_rules! _PyDateTime_GET_TZINFO {
($o: expr) => { ($o: expr) => {
if (*$o).hastzinfo != 0 { if (*$o).hastzinfo != 0 {
@ -199,7 +201,7 @@ macro_rules! _PyDateTime_GET_TZINFO {
// Accessor functions for DateTime // Accessor functions for DateTime
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the hour component of a `PyDateTime_DateTime`. /// Retrieve the hour component of a `PyDateTime_DateTime`.
/// Returns a signed integer in the interval `[0, 23]` /// Returns a signed integer in the interval `[0, 23]`
pub unsafe fn PyDateTime_DATE_GET_HOUR(o: *mut PyObject) -> c_int { pub unsafe fn PyDateTime_DATE_GET_HOUR(o: *mut PyObject) -> c_int {
@ -207,7 +209,7 @@ pub unsafe fn PyDateTime_DATE_GET_HOUR(o: *mut PyObject) -> c_int {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the minute component of a `PyDateTime_DateTime`. /// Retrieve the minute component of a `PyDateTime_DateTime`.
/// Returns a signed integer in the interval `[0, 59]` /// Returns a signed integer in the interval `[0, 59]`
pub unsafe fn PyDateTime_DATE_GET_MINUTE(o: *mut PyObject) -> c_int { pub unsafe fn PyDateTime_DATE_GET_MINUTE(o: *mut PyObject) -> c_int {
@ -215,7 +217,7 @@ pub unsafe fn PyDateTime_DATE_GET_MINUTE(o: *mut PyObject) -> c_int {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the second component of a `PyDateTime_DateTime`. /// Retrieve the second component of a `PyDateTime_DateTime`.
/// Returns a signed integer in the interval `[0, 59]` /// Returns a signed integer in the interval `[0, 59]`
pub unsafe fn PyDateTime_DATE_GET_SECOND(o: *mut PyObject) -> c_int { pub unsafe fn PyDateTime_DATE_GET_SECOND(o: *mut PyObject) -> c_int {
@ -223,7 +225,7 @@ pub unsafe fn PyDateTime_DATE_GET_SECOND(o: *mut PyObject) -> c_int {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the microsecond component of a `PyDateTime_DateTime`. /// Retrieve the microsecond component of a `PyDateTime_DateTime`.
/// Returns a signed integer in the interval `[0, 999999]` /// Returns a signed integer in the interval `[0, 999999]`
pub unsafe fn PyDateTime_DATE_GET_MICROSECOND(o: *mut PyObject) -> c_int { pub unsafe fn PyDateTime_DATE_GET_MICROSECOND(o: *mut PyObject) -> c_int {
@ -231,7 +233,7 @@ pub unsafe fn PyDateTime_DATE_GET_MICROSECOND(o: *mut PyObject) -> c_int {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the fold component of a `PyDateTime_DateTime`. /// Retrieve the fold component of a `PyDateTime_DateTime`.
/// Returns a signed integer in the interval `[0, 1]` /// Returns a signed integer in the interval `[0, 1]`
pub unsafe fn PyDateTime_DATE_GET_FOLD(o: *mut PyObject) -> c_uchar { pub unsafe fn PyDateTime_DATE_GET_FOLD(o: *mut PyObject) -> c_uchar {
@ -239,7 +241,7 @@ pub unsafe fn PyDateTime_DATE_GET_FOLD(o: *mut PyObject) -> c_uchar {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the tzinfo component of a `PyDateTime_DateTime`. /// Retrieve the tzinfo component of a `PyDateTime_DateTime`.
/// Returns a pointer to a `PyObject` that should be either NULL or an instance /// Returns a pointer to a `PyObject` that should be either NULL or an instance
/// of a `datetime.tzinfo` subclass. /// of a `datetime.tzinfo` subclass.
@ -249,7 +251,7 @@ pub unsafe fn PyDateTime_DATE_GET_TZINFO(o: *mut PyObject) -> *mut PyObject {
// Accessor functions for Time // Accessor functions for Time
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the hour component of a `PyDateTime_Time`. /// Retrieve the hour component of a `PyDateTime_Time`.
/// Returns a signed integer in the interval `[0, 23]` /// Returns a signed integer in the interval `[0, 23]`
pub unsafe fn PyDateTime_TIME_GET_HOUR(o: *mut PyObject) -> c_int { pub unsafe fn PyDateTime_TIME_GET_HOUR(o: *mut PyObject) -> c_int {
@ -257,7 +259,7 @@ pub unsafe fn PyDateTime_TIME_GET_HOUR(o: *mut PyObject) -> c_int {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the minute component of a `PyDateTime_Time`. /// Retrieve the minute component of a `PyDateTime_Time`.
/// Returns a signed integer in the interval `[0, 59]` /// Returns a signed integer in the interval `[0, 59]`
pub unsafe fn PyDateTime_TIME_GET_MINUTE(o: *mut PyObject) -> c_int { pub unsafe fn PyDateTime_TIME_GET_MINUTE(o: *mut PyObject) -> c_int {
@ -265,7 +267,7 @@ pub unsafe fn PyDateTime_TIME_GET_MINUTE(o: *mut PyObject) -> c_int {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the second component of a `PyDateTime_DateTime`. /// Retrieve the second component of a `PyDateTime_DateTime`.
/// Returns a signed integer in the interval `[0, 59]` /// Returns a signed integer in the interval `[0, 59]`
pub unsafe fn PyDateTime_TIME_GET_SECOND(o: *mut PyObject) -> c_int { pub unsafe fn PyDateTime_TIME_GET_SECOND(o: *mut PyObject) -> c_int {
@ -273,14 +275,14 @@ pub unsafe fn PyDateTime_TIME_GET_SECOND(o: *mut PyObject) -> c_int {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the microsecond component of a `PyDateTime_DateTime`. /// Retrieve the microsecond component of a `PyDateTime_DateTime`.
/// Returns a signed integer in the interval `[0, 999999]` /// Returns a signed integer in the interval `[0, 999999]`
pub unsafe fn PyDateTime_TIME_GET_MICROSECOND(o: *mut PyObject) -> c_int { pub unsafe fn PyDateTime_TIME_GET_MICROSECOND(o: *mut PyObject) -> c_int {
_PyDateTime_GET_MICROSECOND!((o as *mut PyDateTime_Time), 0) _PyDateTime_GET_MICROSECOND!((o as *mut PyDateTime_Time), 0)
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[inline] #[inline]
/// Retrieve the fold component of a `PyDateTime_Time`. /// Retrieve the fold component of a `PyDateTime_Time`.
/// Returns a signed integer in the interval `[0, 1]` /// Returns a signed integer in the interval `[0, 1]`
@ -289,7 +291,7 @@ pub unsafe fn PyDateTime_TIME_GET_FOLD(o: *mut PyObject) -> c_uchar {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the tzinfo component of a `PyDateTime_Time`. /// Retrieve the tzinfo component of a `PyDateTime_Time`.
/// Returns a pointer to a `PyObject` that should be either NULL or an instance /// Returns a pointer to a `PyObject` that should be either NULL or an instance
/// of a `datetime.tzinfo` subclass. /// of a `datetime.tzinfo` subclass.
@ -298,7 +300,7 @@ pub unsafe fn PyDateTime_TIME_GET_TZINFO(o: *mut PyObject) -> *mut PyObject {
} }
// Accessor functions // Accessor functions
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
macro_rules! _access_field { macro_rules! _access_field {
($obj:expr, $type: ident, $field:ident) => { ($obj:expr, $type: ident, $field:ident) => {
(*($obj as *mut $type)).$field (*($obj as *mut $type)).$field
@ -306,7 +308,7 @@ macro_rules! _access_field {
} }
// Accessor functions for PyDateTime_Delta // Accessor functions for PyDateTime_Delta
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
macro_rules! _access_delta_field { macro_rules! _access_delta_field {
($obj:expr, $field:ident) => { ($obj:expr, $field:ident) => {
_access_field!($obj, PyDateTime_Delta, $field) _access_field!($obj, PyDateTime_Delta, $field)
@ -314,7 +316,7 @@ macro_rules! _access_delta_field {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the days component of a `PyDateTime_Delta`. /// Retrieve the days component of a `PyDateTime_Delta`.
/// ///
/// Returns a signed integer in the interval [-999999999, 999999999]. /// Returns a signed integer in the interval [-999999999, 999999999].
@ -326,7 +328,7 @@ pub unsafe fn PyDateTime_DELTA_GET_DAYS(o: *mut PyObject) -> c_int {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the seconds component of a `PyDateTime_Delta`. /// Retrieve the seconds component of a `PyDateTime_Delta`.
/// ///
/// Returns a signed integer in the interval [0, 86399]. /// Returns a signed integer in the interval [0, 86399].
@ -338,7 +340,7 @@ pub unsafe fn PyDateTime_DELTA_GET_SECONDS(o: *mut PyObject) -> c_int {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
/// Retrieve the seconds component of a `PyDateTime_Delta`. /// Retrieve the seconds component of a `PyDateTime_Delta`.
/// ///
/// Returns a signed integer in the interval [0, 999999]. /// Returns a signed integer in the interval [0, 999999].
@ -349,6 +351,132 @@ pub unsafe fn PyDateTime_DELTA_GET_MICROSECONDS(o: *mut PyObject) -> c_int {
_access_delta_field!(o, microseconds) _access_delta_field!(o, microseconds)
} }
// Accessor functions for GraalPy. The macros on GraalPy work differently,
// but copying them seems suboptimal
#[inline]
#[cfg(GraalPy)]
pub unsafe fn _get_attr(obj: *mut PyObject, field: &str) -> c_int {
let result = PyObject_GetAttrString(obj, field.as_ptr() as *const c_char);
Py_DecRef(result); // the original macros are borrowing
if PyLong_Check(result) == 1 {
PyLong_AsLong(result) as c_int
} else {
0
}
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_GET_YEAR(o: *mut PyObject) -> c_int {
_get_attr(o, "year\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_GET_MONTH(o: *mut PyObject) -> c_int {
_get_attr(o, "month\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_GET_DAY(o: *mut PyObject) -> c_int {
_get_attr(o, "day\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_DATE_GET_HOUR(o: *mut PyObject) -> c_int {
_get_attr(o, "hour\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_DATE_GET_MINUTE(o: *mut PyObject) -> c_int {
_get_attr(o, "minute\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_DATE_GET_SECOND(o: *mut PyObject) -> c_int {
_get_attr(o, "second\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_DATE_GET_MICROSECOND(o: *mut PyObject) -> c_int {
_get_attr(o, "microsecond\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_DATE_GET_FOLD(o: *mut PyObject) -> c_int {
_get_attr(o, "fold\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_DATE_GET_TZINFO(o: *mut PyObject) -> *mut PyObject {
let res = PyObject_GetAttrString(o, "tzinfo\0".as_ptr() as *const c_char);
Py_DecRef(res); // the original macros are borrowing
res
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_TIME_GET_HOUR(o: *mut PyObject) -> c_int {
_get_attr(o, "hour\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_TIME_GET_MINUTE(o: *mut PyObject) -> c_int {
_get_attr(o, "minute\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_TIME_GET_SECOND(o: *mut PyObject) -> c_int {
_get_attr(o, "second\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_TIME_GET_MICROSECOND(o: *mut PyObject) -> c_int {
_get_attr(o, "microsecond\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_TIME_GET_FOLD(o: *mut PyObject) -> c_int {
_get_attr(o, "fold\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_TIME_GET_TZINFO(o: *mut PyObject) -> *mut PyObject {
let res = PyObject_GetAttrString(o, "tzinfo\0".as_ptr() as *const c_char);
Py_DecRef(res); // the original macros are borrowing
res
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_DELTA_GET_DAYS(o: *mut PyObject) -> c_int {
_get_attr(o, "days\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_DELTA_GET_SECONDS(o: *mut PyObject) -> c_int {
_get_attr(o, "seconds\0")
}
#[inline]
#[cfg(GraalPy)]
pub unsafe fn PyDateTime_DELTA_GET_MICROSECONDS(o: *mut PyObject) -> c_int {
_get_attr(o, "microseconds\0")
}
#[cfg(PyPy)] #[cfg(PyPy)]
extern "C" { extern "C" {
// skipped _PyDateTime_HAS_TZINFO (not in PyPy) // skipped _PyDateTime_HAS_TZINFO (not in PyPy)

View File

@ -109,6 +109,6 @@ extern "C" {
pub static mut PyDictRevIterItem_Type: PyTypeObject; pub static mut PyDictRevIterItem_Type: PyTypeObject;
} }
#[cfg(any(PyPy, Py_LIMITED_API))] #[cfg(any(PyPy, GraalPy, Py_LIMITED_API))]
// TODO: remove (see https://github.com/PyO3/pyo3/pull/1341#issuecomment-751515985) // TODO: remove (see https://github.com/PyO3/pyo3/pull/1341#issuecomment-751515985)
opaque_struct!(PyDictObject); opaque_struct!(PyDictObject);

View File

@ -54,14 +54,16 @@ extern "C" {
#[cfg_attr(PyPy, link_name = "PyPyList_AsTuple")] #[cfg_attr(PyPy, link_name = "PyPyList_AsTuple")]
pub fn PyList_AsTuple(arg1: *mut PyObject) -> *mut PyObject; pub fn PyList_AsTuple(arg1: *mut PyObject) -> *mut PyObject;
// CPython macros exported as functions on PyPy // CPython macros exported as functions on PyPy or GraalPy
#[cfg(PyPy)] #[cfg(any(PyPy, GraalPy))]
#[cfg_attr(PyPy, link_name = "PyPyList_GET_ITEM")] #[cfg_attr(PyPy, link_name = "PyPyList_GET_ITEM")]
#[cfg_attr(GraalPy, link_name = "PyList_GetItem")]
pub fn PyList_GET_ITEM(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject; pub fn PyList_GET_ITEM(arg1: *mut PyObject, arg2: Py_ssize_t) -> *mut PyObject;
#[cfg(PyPy)] #[cfg(PyPy)]
#[cfg_attr(PyPy, link_name = "PyPyList_GET_SIZE")] #[cfg_attr(PyPy, link_name = "PyPyList_GET_SIZE")]
pub fn PyList_GET_SIZE(arg1: *mut PyObject) -> Py_ssize_t; pub fn PyList_GET_SIZE(arg1: *mut PyObject) -> Py_ssize_t;
#[cfg(PyPy)] #[cfg(any(PyPy, GraalPy))]
#[cfg_attr(PyPy, link_name = "PyPyList_SET_ITEM")] #[cfg_attr(PyPy, link_name = "PyPyList_SET_ITEM")]
#[cfg_attr(GraalPy, link_name = "_PyList_SET_ITEM")]
pub fn PyList_SET_ITEM(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject); pub fn PyList_SET_ITEM(arg1: *mut PyObject, arg2: Py_ssize_t, arg3: *mut PyObject);
} }

View File

@ -4,7 +4,7 @@ use crate::PyObject_TypeCheck;
use std::os::raw::{c_char, c_int, c_void}; use std::os::raw::{c_char, c_int, c_void};
use std::{mem, ptr}; use std::{mem, ptr};
#[cfg(all(Py_3_9, not(Py_LIMITED_API)))] #[cfg(all(Py_3_9, not(Py_LIMITED_API), not(GraalPy)))]
pub struct PyCFunctionObject { pub struct PyCFunctionObject {
pub ob_base: PyObject, pub ob_base: PyObject,
pub m_ml: *mut PyMethodDef, pub m_ml: *mut PyMethodDef,

View File

@ -79,6 +79,7 @@ pub struct PyObject {
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub struct PyVarObject { pub struct PyVarObject {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(GraalPy))]
pub ob_size: Py_ssize_t, pub ob_size: Py_ssize_t,
} }
@ -98,12 +99,18 @@ pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t {
#[inline] #[inline]
#[cfg(not(Py_3_12))] #[cfg(not(Py_3_12))]
pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t { pub unsafe fn Py_REFCNT(ob: *mut PyObject) -> Py_ssize_t {
(*ob).ob_refcnt #[cfg(not(GraalPy))]
return (*ob).ob_refcnt;
#[cfg(GraalPy)]
return _Py_REFCNT(ob);
} }
#[inline] #[inline]
pub unsafe fn Py_TYPE(ob: *mut PyObject) -> *mut PyTypeObject { pub unsafe fn Py_TYPE(ob: *mut PyObject) -> *mut PyTypeObject {
(*ob).ob_type #[cfg(not(GraalPy))]
return (*ob).ob_type;
#[cfg(GraalPy)]
return _Py_TYPE(ob);
} }
// PyLong_Type defined in longobject.rs // PyLong_Type defined in longobject.rs
@ -111,9 +118,14 @@ pub unsafe fn Py_TYPE(ob: *mut PyObject) -> *mut PyTypeObject {
#[inline] #[inline]
pub unsafe fn Py_SIZE(ob: *mut PyObject) -> Py_ssize_t { pub unsafe fn Py_SIZE(ob: *mut PyObject) -> Py_ssize_t {
debug_assert_ne!((*ob).ob_type, std::ptr::addr_of_mut!(crate::PyLong_Type)); #[cfg(not(GraalPy))]
debug_assert_ne!((*ob).ob_type, std::ptr::addr_of_mut!(crate::PyBool_Type)); {
(*ob.cast::<PyVarObject>()).ob_size debug_assert_ne!((*ob).ob_type, std::ptr::addr_of_mut!(crate::PyLong_Type));
debug_assert_ne!((*ob).ob_type, std::ptr::addr_of_mut!(crate::PyBool_Type));
(*ob.cast::<PyVarObject>()).ob_size
}
#[cfg(GraalPy)]
_Py_SIZE(ob)
} }
#[inline] #[inline]
@ -464,8 +476,10 @@ extern "C" {
pub fn _Py_Dealloc(arg1: *mut PyObject); pub fn _Py_Dealloc(arg1: *mut PyObject);
#[cfg_attr(PyPy, link_name = "PyPy_IncRef")] #[cfg_attr(PyPy, link_name = "PyPy_IncRef")]
#[cfg_attr(GraalPy, link_name = "_Py_IncRef")]
pub fn Py_IncRef(o: *mut PyObject); pub fn Py_IncRef(o: *mut PyObject);
#[cfg_attr(PyPy, link_name = "PyPy_DecRef")] #[cfg_attr(PyPy, link_name = "PyPy_DecRef")]
#[cfg_attr(GraalPy, link_name = "_Py_DecRef")]
pub fn Py_DecRef(o: *mut PyObject); pub fn Py_DecRef(o: *mut PyObject);
#[cfg(Py_3_10)] #[cfg(Py_3_10)]
@ -474,11 +488,21 @@ extern "C" {
#[cfg(Py_3_10)] #[cfg(Py_3_10)]
#[cfg_attr(PyPy, link_name = "_PyPy_DecRef")] #[cfg_attr(PyPy, link_name = "_PyPy_DecRef")]
pub fn _Py_DecRef(o: *mut PyObject); pub fn _Py_DecRef(o: *mut PyObject);
#[cfg(GraalPy)]
pub fn _Py_REFCNT(arg1: *const PyObject) -> Py_ssize_t;
#[cfg(GraalPy)]
pub fn _Py_TYPE(arg1: *const PyObject) -> *mut PyTypeObject;
#[cfg(GraalPy)]
pub fn _Py_SIZE(arg1: *const PyObject) -> Py_ssize_t;
} }
#[inline(always)] #[inline(always)]
pub unsafe fn Py_INCREF(op: *mut PyObject) { pub unsafe fn Py_INCREF(op: *mut PyObject) {
#[cfg(any( #[cfg(any(
GraalPy,
all(Py_LIMITED_API, Py_3_12), all(Py_LIMITED_API, Py_3_12),
all( all(
py_sys_config = "Py_REF_DEBUG", py_sys_config = "Py_REF_DEBUG",
@ -499,6 +523,7 @@ pub unsafe fn Py_INCREF(op: *mut PyObject) {
all(Py_LIMITED_API, not(Py_3_12)), all(Py_LIMITED_API, not(Py_3_12)),
all( all(
not(Py_LIMITED_API), not(Py_LIMITED_API),
not(GraalPy),
any( any(
not(py_sys_config = "Py_REF_DEBUG"), not(py_sys_config = "Py_REF_DEBUG"),
all(py_sys_config = "Py_REF_DEBUG", Py_3_12), all(py_sys_config = "Py_REF_DEBUG", Py_3_12),
@ -544,6 +569,7 @@ pub unsafe fn Py_INCREF(op: *mut PyObject) {
)] )]
pub unsafe fn Py_DECREF(op: *mut PyObject) { pub unsafe fn Py_DECREF(op: *mut PyObject) {
#[cfg(any( #[cfg(any(
GraalPy,
all(Py_LIMITED_API, Py_3_12), all(Py_LIMITED_API, Py_3_12),
all( all(
py_sys_config = "Py_REF_DEBUG", py_sys_config = "Py_REF_DEBUG",
@ -564,6 +590,7 @@ pub unsafe fn Py_DECREF(op: *mut PyObject) {
all(Py_LIMITED_API, not(Py_3_12)), all(Py_LIMITED_API, not(Py_3_12)),
all( all(
not(Py_LIMITED_API), not(Py_LIMITED_API),
not(GraalPy),
any( any(
not(py_sys_config = "Py_REF_DEBUG"), not(py_sys_config = "Py_REF_DEBUG"),
all(py_sys_config = "Py_REF_DEBUG", Py_3_12), all(py_sys_config = "Py_REF_DEBUG", Py_3_12),
@ -669,13 +696,20 @@ pub unsafe fn Py_XNewRef(obj: *mut PyObject) -> *mut PyObject {
#[cfg_attr(windows, link(name = "pythonXY"))] #[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" { extern "C" {
#[cfg(not(GraalPy))]
#[cfg_attr(PyPy, link_name = "_PyPy_NoneStruct")] #[cfg_attr(PyPy, link_name = "_PyPy_NoneStruct")]
static mut _Py_NoneStruct: PyObject; static mut _Py_NoneStruct: PyObject;
#[cfg(GraalPy)]
static mut _Py_NoneStructReference: *mut PyObject;
} }
#[inline] #[inline]
pub unsafe fn Py_None() -> *mut PyObject { pub unsafe fn Py_None() -> *mut PyObject {
ptr::addr_of_mut!(_Py_NoneStruct) #[cfg(not(GraalPy))]
return ptr::addr_of_mut!(_Py_NoneStruct);
#[cfg(GraalPy)]
return _Py_NoneStructReference;
} }
#[inline] #[inline]
@ -687,13 +721,20 @@ pub unsafe fn Py_IsNone(x: *mut PyObject) -> c_int {
#[cfg_attr(windows, link(name = "pythonXY"))] #[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" { extern "C" {
#[cfg(not(GraalPy))]
#[cfg_attr(PyPy, link_name = "_PyPy_NotImplementedStruct")] #[cfg_attr(PyPy, link_name = "_PyPy_NotImplementedStruct")]
static mut _Py_NotImplementedStruct: PyObject; static mut _Py_NotImplementedStruct: PyObject;
#[cfg(GraalPy)]
static mut _Py_NotImplementedStructReference: *mut PyObject;
} }
#[inline] #[inline]
pub unsafe fn Py_NotImplemented() -> *mut PyObject { pub unsafe fn Py_NotImplemented() -> *mut PyObject {
ptr::addr_of_mut!(_Py_NotImplementedStruct) #[cfg(not(GraalPy))]
return ptr::addr_of_mut!(_Py_NotImplementedStruct);
#[cfg(GraalPy)]
return _Py_NotImplementedStructReference;
} }
// skipped Py_RETURN_NOTIMPLEMENTED // skipped Py_RETURN_NOTIMPLEMENTED

View File

@ -1,3 +1,4 @@
#[cfg(not(GraalPy))]
#[cfg(any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))] #[cfg(any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))]
use crate::PyCodeObject; use crate::PyCodeObject;
#[cfg(not(Py_LIMITED_API))] #[cfg(not(Py_LIMITED_API))]
@ -9,6 +10,7 @@ opaque_struct!(PyFrameObject);
extern "C" { extern "C" {
pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int; pub fn PyFrame_GetLineNumber(f: *mut PyFrameObject) -> c_int;
#[cfg(not(GraalPy))]
#[cfg(any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))] #[cfg(any(Py_3_10, all(Py_3_9, not(Py_LIMITED_API))))]
pub fn PyFrame_GetCode(f: *mut PyFrameObject) -> *mut PyCodeObject; pub fn PyFrame_GetCode(f: *mut PyFrameObject) -> *mut PyCodeObject;
} }

View File

@ -1,6 +1,6 @@
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
use crate::pyport::{Py_hash_t, Py_ssize_t}; use crate::pyport::{Py_hash_t, Py_ssize_t};
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
use std::os::raw::{c_char, c_void}; use std::os::raw::{c_char, c_void};
use std::os::raw::{c_int, c_ulong}; use std::os::raw::{c_int, c_ulong};
@ -10,7 +10,7 @@ extern "C" {
// skipped non-limited _Py_HashPointer // skipped non-limited _Py_HashPointer
// skipped non-limited _Py_HashPointerRaw // skipped non-limited _Py_HashPointerRaw
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
pub fn _Py_HashBytes(src: *const c_void, len: Py_ssize_t) -> Py_hash_t; pub fn _Py_HashBytes(src: *const c_void, len: Py_ssize_t) -> Py_hash_t;
} }
@ -20,7 +20,7 @@ pub const _PyHASH_MULTIPLIER: c_ulong = 1000003;
// skipped non-limited _Py_HashSecret_t // skipped non-limited _Py_HashSecret_t
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct PyHash_FuncDef { pub struct PyHash_FuncDef {
@ -30,7 +30,7 @@ pub struct PyHash_FuncDef {
pub seed_bits: c_int, pub seed_bits: c_int,
} }
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
impl Default for PyHash_FuncDef { impl Default for PyHash_FuncDef {
#[inline] #[inline]
fn default() -> Self { fn default() -> Self {
@ -39,7 +39,7 @@ impl Default for PyHash_FuncDef {
} }
extern "C" { extern "C" {
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
pub fn PyHash_GetFuncDef() -> *mut PyHash_FuncDef; pub fn PyHash_GetFuncDef() -> *mut PyHash_FuncDef;
} }

View File

@ -1,12 +1,12 @@
use crate::object::*; use crate::object::*;
#[cfg(not(any(PyPy, Py_LIMITED_API, Py_3_10)))] #[cfg(not(any(PyPy, Py_LIMITED_API, Py_3_10)))]
use libc::FILE; use libc::FILE;
#[cfg(all(not(PyPy), any(Py_LIMITED_API, not(Py_3_10))))] #[cfg(all(not(PyPy), any(Py_LIMITED_API, not(Py_3_10), GraalPy)))]
use std::os::raw::c_char; use std::os::raw::c_char;
use std::os::raw::c_int; use std::os::raw::c_int;
extern "C" { extern "C" {
#[cfg(all(Py_LIMITED_API, not(PyPy)))] #[cfg(any(all(Py_LIMITED_API, not(PyPy)), GraalPy))]
pub fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject; pub fn Py_CompileString(string: *const c_char, p: *const c_char, s: c_int) -> *mut PyObject;
#[cfg_attr(PyPy, link_name = "PyPyErr_Print")] #[cfg_attr(PyPy, link_name = "PyPyErr_Print")]

View File

@ -1,5 +1,5 @@
use crate::object::*; use crate::object::*;
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
use crate::pyport::Py_hash_t; use crate::pyport::Py_hash_t;
use crate::pyport::Py_ssize_t; use crate::pyport::Py_ssize_t;
use std::os::raw::c_int; use std::os::raw::c_int;
@ -7,7 +7,7 @@ use std::ptr::addr_of_mut;
pub const PySet_MINSIZE: usize = 8; pub const PySet_MINSIZE: usize = 8;
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct setentry { pub struct setentry {
@ -15,7 +15,7 @@ pub struct setentry {
pub hash: Py_hash_t, pub hash: Py_hash_t,
} }
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct PySetObject { pub struct PySetObject {
@ -32,7 +32,7 @@ pub struct PySetObject {
// skipped // skipped
#[inline] #[inline]
#[cfg(all(not(PyPy), not(Py_LIMITED_API)))] #[cfg(all(not(any(PyPy, GraalPy)), not(Py_LIMITED_API)))]
pub unsafe fn PySet_GET_SIZE(so: *mut PyObject) -> Py_ssize_t { pub unsafe fn PySet_GET_SIZE(so: *mut PyObject) -> Py_ssize_t {
debug_assert_eq!(PyAnySet_Check(so), 1); debug_assert_eq!(PyAnySet_Check(so), 1);
let so = so.cast::<PySetObject>(); let so = so.cast::<PySetObject>();
@ -92,7 +92,7 @@ extern "C" {
} }
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub unsafe fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int { pub unsafe fn PyFrozenSet_CheckExact(ob: *mut PyObject) -> c_int {
(Py_TYPE(ob) == addr_of_mut!(PyFrozenSet_Type)) as c_int (Py_TYPE(ob) == addr_of_mut!(PyFrozenSet_Type)) as c_int
} }

View File

@ -5,21 +5,31 @@ use std::ptr::addr_of_mut;
#[cfg_attr(windows, link(name = "pythonXY"))] #[cfg_attr(windows, link(name = "pythonXY"))]
extern "C" { extern "C" {
#[cfg(not(GraalPy))]
#[cfg_attr(PyPy, link_name = "_PyPy_EllipsisObject")] #[cfg_attr(PyPy, link_name = "_PyPy_EllipsisObject")]
static mut _Py_EllipsisObject: PyObject; static mut _Py_EllipsisObject: PyObject;
#[cfg(GraalPy)]
static mut _Py_EllipsisObjectReference: *mut PyObject;
} }
#[inline] #[inline]
pub unsafe fn Py_Ellipsis() -> *mut PyObject { pub unsafe fn Py_Ellipsis() -> *mut PyObject {
addr_of_mut!(_Py_EllipsisObject) #[cfg(not(GraalPy))]
return addr_of_mut!(_Py_EllipsisObject);
#[cfg(GraalPy)]
return _Py_EllipsisObjectReference;
} }
#[cfg(not(Py_LIMITED_API))] #[cfg(not(Py_LIMITED_API))]
#[repr(C)] #[repr(C)]
pub struct PySliceObject { pub struct PySliceObject {
pub ob_base: PyObject, pub ob_base: PyObject,
#[cfg(not(GraalPy))]
pub start: *mut PyObject, pub start: *mut PyObject,
#[cfg(not(GraalPy))]
pub stop: *mut PyObject, pub stop: *mut PyObject,
#[cfg(not(GraalPy))]
pub step: *mut PyObject, pub step: *mut PyObject,
} }

View File

@ -42,13 +42,13 @@ extern "C" {
#[cfg(not(Py_LIMITED_API))] #[cfg(not(Py_LIMITED_API))]
pub type PyStructSequence = crate::PyTupleObject; pub type PyStructSequence = crate::PyTupleObject;
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
#[inline] #[inline]
pub unsafe fn PyStructSequence_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) { pub unsafe fn PyStructSequence_SET_ITEM(op: *mut PyObject, i: Py_ssize_t, v: *mut PyObject) {
crate::PyTuple_SET_ITEM(op, i, v) crate::PyTuple_SET_ITEM(op, i, v)
} }
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
#[inline] #[inline]
pub unsafe fn PyStructSequence_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject { pub unsafe fn PyStructSequence_GET_ITEM(op: *mut PyObject, i: Py_ssize_t) -> *mut PyObject {
crate::PyTuple_GET_ITEM(op, i) crate::PyTuple_GET_ITEM(op, i)

View File

@ -3,10 +3,10 @@ use std::os::raw::c_int;
#[cfg(not(PyPy))] #[cfg(not(PyPy))]
use std::ptr::addr_of_mut; use std::ptr::addr_of_mut;
#[cfg(all(not(PyPy), Py_LIMITED_API))] #[cfg(all(not(PyPy), Py_LIMITED_API, not(GraalPy)))]
opaque_struct!(PyWeakReference); opaque_struct!(PyWeakReference);
#[cfg(all(not(PyPy), not(Py_LIMITED_API)))] #[cfg(all(not(PyPy), not(Py_LIMITED_API), not(GraalPy)))]
pub use crate::_PyWeakReference as PyWeakReference; pub use crate::_PyWeakReference as PyWeakReference;
#[cfg_attr(windows, link(name = "pythonXY"))] #[cfg_attr(windows, link(name = "pythonXY"))]

View File

@ -1,13 +1,22 @@
import pytest import pytest
import sys
from pyo3_pytests.awaitable import IterAwaitable, FutureAwaitable from pyo3_pytests.awaitable import IterAwaitable, FutureAwaitable
@pytest.mark.skipif(
sys.implementation.name == "graalpy",
reason="GraalPy's asyncio module has a bug with native classes, see oracle/graalpython#365",
)
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_iter_awaitable(): async def test_iter_awaitable():
assert await IterAwaitable(5) == 5 assert await IterAwaitable(5) == 5
@pytest.mark.skipif(
sys.implementation.name == "graalpy",
reason="GraalPy's asyncio module has a bug with native classes, see oracle/graalpython#365",
)
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_future_awaitable(): async def test_future_awaitable():
assert await FutureAwaitable(5) == 5 assert await FutureAwaitable(5) == 5

View File

@ -27,8 +27,8 @@ def test_multiple_imports_same_interpreter_ok():
reason="Cannot identify subinterpreters on Python older than 3.9", reason="Cannot identify subinterpreters on Python older than 3.9",
) )
@pytest.mark.skipif( @pytest.mark.skipif(
platform.python_implementation() == "PyPy", platform.python_implementation() in ("PyPy", "GraalVM"),
reason="PyPy does not support subinterpreters", reason="PyPy and GraalPy do not support subinterpreters",
) )
def test_import_in_subinterpreter_forbidden(): def test_import_in_subinterpreter_forbidden():
import _xxsubinterpreters import _xxsubinterpreters

View File

@ -12,6 +12,11 @@ def test_objstore_doesnot_leak_memory():
# check refcount on PyPy # check refcount on PyPy
getrefcount = getattr(sys, "getrefcount", lambda obj: 0) getrefcount = getattr(sys, "getrefcount", lambda obj: 0)
if sys.implementation.name == "graalpy":
# GraalPy has an incomplete sys.getrefcount implementation
def getrefcount(obj):
return 0
before = getrefcount(message) before = getrefcount(message)
store = ObjStore() store = ObjStore()
for _ in range(N): for _ in range(N):

View File

@ -175,7 +175,7 @@ int_convert_u64_or_i64!(
true true
); );
#[cfg(not(Py_LIMITED_API))] #[cfg(all(not(Py_LIMITED_API), not(GraalPy)))]
mod fast_128bit_int_conversion { mod fast_128bit_int_conversion {
use super::*; use super::*;
@ -242,7 +242,7 @@ mod fast_128bit_int_conversion {
} }
// For ABI3 we implement the conversion manually. // For ABI3 we implement the conversion manually.
#[cfg(Py_LIMITED_API)] #[cfg(any(Py_LIMITED_API, GraalPy))]
mod slow_128bit_int_conversion { mod slow_128bit_int_conversion {
use super::*; use super::*;
const SHIFT: usize = 64; const SHIFT: usize = 64;

View File

@ -863,8 +863,17 @@ impl PyErr {
/// associated with the exception, as accessible from Python through `__cause__`. /// associated with the exception, as accessible from Python through `__cause__`.
pub fn cause(&self, py: Python<'_>) -> Option<PyErr> { pub fn cause(&self, py: Python<'_>) -> Option<PyErr> {
use crate::ffi_ptr_ext::FfiPtrExt; use crate::ffi_ptr_ext::FfiPtrExt;
unsafe { ffi::PyException_GetCause(self.value_bound(py).as_ptr()).assume_owned_or_opt(py) } let obj = unsafe {
.map(Self::from_value_bound) ffi::PyException_GetCause(self.value_bound(py).as_ptr()).assume_owned_or_opt(py)
};
// PyException_GetCause is documented as potentially returning PyNone, but only GraalPy seems to actually do that
#[cfg(GraalPy)]
if let Some(cause) = &obj {
if cause.is_none() {
return None;
}
}
obj.map(Self::from_value_bound)
} }
/// Set the cause associated with the exception, pass `None` to clear it. /// Set the cause associated with the exception, pass `None` to clear it.

View File

@ -409,14 +409,14 @@ impl_native_exception!(
PyExc_FloatingPointError, PyExc_FloatingPointError,
native_doc!("FloatingPointError") native_doc!("FloatingPointError")
); );
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
impl_native_exception!( impl_native_exception!(
PyOSError, PyOSError,
PyExc_OSError, PyExc_OSError,
native_doc!("OSError"), native_doc!("OSError"),
ffi::PyOSErrorObject ffi::PyOSErrorObject
); );
#[cfg(PyPy)] #[cfg(any(PyPy, GraalPy))]
impl_native_exception!(PyOSError, PyExc_OSError, native_doc!("OSError")); impl_native_exception!(PyOSError, PyExc_OSError, native_doc!("OSError"));
impl_native_exception!(PyImportError, PyExc_ImportError, native_doc!("ImportError")); impl_native_exception!(PyImportError, PyExc_ImportError, native_doc!("ImportError"));
@ -455,14 +455,14 @@ impl_native_exception!(
PyExc_NotImplementedError, PyExc_NotImplementedError,
native_doc!("NotImplementedError") native_doc!("NotImplementedError")
); );
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
impl_native_exception!( impl_native_exception!(
PySyntaxError, PySyntaxError,
PyExc_SyntaxError, PyExc_SyntaxError,
native_doc!("SyntaxError"), native_doc!("SyntaxError"),
ffi::PySyntaxErrorObject ffi::PySyntaxErrorObject
); );
#[cfg(PyPy)] #[cfg(any(PyPy, GraalPy))]
impl_native_exception!(PySyntaxError, PyExc_SyntaxError, native_doc!("SyntaxError")); impl_native_exception!(PySyntaxError, PyExc_SyntaxError, native_doc!("SyntaxError"));
impl_native_exception!( impl_native_exception!(
PyReferenceError, PyReferenceError,
@ -470,14 +470,14 @@ impl_native_exception!(
native_doc!("ReferenceError") native_doc!("ReferenceError")
); );
impl_native_exception!(PySystemError, PyExc_SystemError, native_doc!("SystemError")); impl_native_exception!(PySystemError, PyExc_SystemError, native_doc!("SystemError"));
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
impl_native_exception!( impl_native_exception!(
PySystemExit, PySystemExit,
PyExc_SystemExit, PyExc_SystemExit,
native_doc!("SystemExit"), native_doc!("SystemExit"),
ffi::PySystemExitObject ffi::PySystemExitObject
); );
#[cfg(PyPy)] #[cfg(any(PyPy, GraalPy))]
impl_native_exception!(PySystemExit, PyExc_SystemExit, native_doc!("SystemExit")); impl_native_exception!(PySystemExit, PyExc_SystemExit, native_doc!("SystemExit"));
impl_native_exception!(PyTypeError, PyExc_TypeError, native_doc!("TypeError")); impl_native_exception!(PyTypeError, PyExc_TypeError, native_doc!("TypeError"));
impl_native_exception!( impl_native_exception!(
@ -485,14 +485,14 @@ impl_native_exception!(
PyExc_UnboundLocalError, PyExc_UnboundLocalError,
native_doc!("UnboundLocalError") native_doc!("UnboundLocalError")
); );
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
impl_native_exception!( impl_native_exception!(
PyUnicodeError, PyUnicodeError,
PyExc_UnicodeError, PyExc_UnicodeError,
native_doc!("UnicodeError"), native_doc!("UnicodeError"),
ffi::PyUnicodeErrorObject ffi::PyUnicodeErrorObject
); );
#[cfg(PyPy)] #[cfg(any(PyPy, GraalPy))]
impl_native_exception!( impl_native_exception!(
PyUnicodeError, PyUnicodeError,
PyExc_UnicodeError, PyExc_UnicodeError,

View File

@ -78,7 +78,7 @@ fn gil_is_acquired() -> bool {
/// Python::with_gil(|py| py.run_bound("print('Hello World')", None, None)) /// Python::with_gil(|py| py.run_bound("print('Hello World')", None, None))
/// # } /// # }
/// ``` /// ```
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn prepare_freethreaded_python() { pub fn prepare_freethreaded_python() {
// Protect against race conditions when Python is not yet initialized and multiple threads // Protect against race conditions when Python is not yet initialized and multiple threads
// concurrently call 'prepare_freethreaded_python()'. Note that we do not protect against // concurrently call 'prepare_freethreaded_python()'. Note that we do not protect against
@ -125,7 +125,7 @@ pub fn prepare_freethreaded_python() {
/// }); /// });
/// } /// }
/// ``` /// ```
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub unsafe fn with_embedded_python_interpreter<F, R>(f: F) -> R pub unsafe fn with_embedded_python_interpreter<F, R>(f: F) -> R
where where
F: for<'p> FnOnce(Python<'p>) -> R, F: for<'p> FnOnce(Python<'p>) -> R,
@ -182,14 +182,14 @@ impl GILGuard {
// auto-initialize so this avoids breaking existing builds. // auto-initialize so this avoids breaking existing builds.
// - Otherwise, just check the GIL is initialized. // - Otherwise, just check the GIL is initialized.
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(all(feature = "auto-initialize", not(PyPy)))] { if #[cfg(all(feature = "auto-initialize", not(any(PyPy, GraalPy))))] {
prepare_freethreaded_python(); prepare_freethreaded_python();
} else { } else {
// This is a "hack" to make running `cargo test` for PyO3 convenient (i.e. no need // This is a "hack" to make running `cargo test` for PyO3 convenient (i.e. no need
// to specify `--features auto-initialize` manually. Tests within the crate itself // to specify `--features auto-initialize` manually. Tests within the crate itself
// all depend on the auto-initialize feature for conciseness but Cargo does not // all depend on the auto-initialize feature for conciseness but Cargo does not
// provide a mechanism to specify required features for tests. // provide a mechanism to specify required features for tests.
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
if option_env!("CARGO_PRIMARY_PACKAGE").is_some() { if option_env!("CARGO_PRIMARY_PACKAGE").is_some() {
prepare_freethreaded_python(); prepare_freethreaded_python();
} }

View File

@ -2,10 +2,14 @@
use std::cell::UnsafeCell; use std::cell::UnsafeCell;
#[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))] #[cfg(all(
not(any(PyPy, GraalPy)),
Py_3_9,
not(all(windows, Py_LIMITED_API, not(Py_3_10)))
))]
use portable_atomic::{AtomicI64, Ordering}; use portable_atomic::{AtomicI64, Ordering};
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
use crate::exceptions::PyImportError; use crate::exceptions::PyImportError;
use crate::{ffi, sync::GILOnceCell, types::PyModule, Bound, Py, PyResult, Python}; use crate::{ffi, sync::GILOnceCell, types::PyModule, Bound, Py, PyResult, Python};
@ -15,7 +19,11 @@ pub struct ModuleDef {
ffi_def: UnsafeCell<ffi::PyModuleDef>, ffi_def: UnsafeCell<ffi::PyModuleDef>,
initializer: ModuleInitializer, initializer: ModuleInitializer,
/// Interpreter ID where module was initialized (not applicable on PyPy). /// Interpreter ID where module was initialized (not applicable on PyPy).
#[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))] #[cfg(all(
not(any(PyPy, GraalPy)),
Py_3_9,
not(all(windows, Py_LIMITED_API, not(Py_3_10)))
))]
interpreter: AtomicI64, interpreter: AtomicI64,
/// Initialized module object, cached to avoid reinitialization. /// Initialized module object, cached to avoid reinitialization.
module: GILOnceCell<Py<PyModule>>, module: GILOnceCell<Py<PyModule>>,
@ -58,7 +66,11 @@ impl ModuleDef {
ffi_def, ffi_def,
initializer, initializer,
// -1 is never expected to be a valid interpreter ID // -1 is never expected to be a valid interpreter ID
#[cfg(all(not(PyPy), Py_3_9, not(all(windows, Py_LIMITED_API, not(Py_3_10)))))] #[cfg(all(
not(any(PyPy, GraalPy)),
Py_3_9,
not(all(windows, Py_LIMITED_API, not(Py_3_10)))
))]
interpreter: AtomicI64::new(-1), interpreter: AtomicI64::new(-1),
module: GILOnceCell::new(), module: GILOnceCell::new(),
} }
@ -85,7 +97,7 @@ impl ModuleDef {
// that static data is not reused across interpreters. // that static data is not reused across interpreters.
// //
// PyPy does not have subinterpreters, so no need to check interpreter ID. // PyPy does not have subinterpreters, so no need to check interpreter ID.
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
{ {
// PyInterpreterState_Get is only available on 3.9 and later, but is missing // PyInterpreterState_Get is only available on 3.9 and later, but is missing
// from python3.dll for Windows stable API on 3.9 // from python3.dll for Windows stable API on 3.9

View File

@ -24,12 +24,14 @@ pub unsafe fn module_init(
} }
#[inline] #[inline]
#[allow(clippy::used_underscore_binding)]
pub unsafe fn noargs( pub unsafe fn noargs(
slf: *mut ffi::PyObject, slf: *mut ffi::PyObject,
args: *mut ffi::PyObject, _args: *mut ffi::PyObject,
f: for<'py> unsafe fn(Python<'py>, *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>, f: for<'py> unsafe fn(Python<'py>, *mut ffi::PyObject) -> PyResult<*mut ffi::PyObject>,
) -> *mut ffi::PyObject { ) -> *mut ffi::PyObject {
debug_assert!(args.is_null()); #[cfg(not(GraalPy))] // this is not specified and GraalPy does not pass null here
debug_assert!(_args.is_null());
trampoline(|py| f(py, slf)) trampoline(|py| f(py, slf))
} }

View File

@ -321,7 +321,7 @@ pub use crate::err::{
}; };
#[allow(deprecated)] #[allow(deprecated)]
pub use crate::gil::GILPool; pub use crate::gil::GILPool;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub use crate::gil::{prepare_freethreaded_python, with_embedded_python_interpreter}; pub use crate::gil::{prepare_freethreaded_python, with_embedded_python_interpreter};
pub use crate::instance::{Borrowed, Bound, Py, PyNativeType, PyObject}; pub use crate::instance::{Borrowed, Bound, Py, PyNativeType, PyObject};
pub use crate::marker::Python; pub use crate::marker::Python;

View File

@ -201,7 +201,7 @@ macro_rules! wrap_pymodule {
/// ///
/// Use it before [`prepare_freethreaded_python`](crate::prepare_freethreaded_python) and /// Use it before [`prepare_freethreaded_python`](crate::prepare_freethreaded_python) and
/// leave feature `auto-initialize` off /// leave feature `auto-initialize` off
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[macro_export] #[macro_export]
macro_rules! append_to_inittab { macro_rules! append_to_inittab {
($module:ident) => { ($module:ident) => {

View File

@ -400,7 +400,7 @@ impl Python<'_> {
/// If the [`auto-initialize`] feature is enabled and the Python runtime is not already /// If the [`auto-initialize`] feature is enabled and the Python runtime is not already
/// initialized, this function will initialize it. See /// initialized, this function will initialize it. See
#[cfg_attr( #[cfg_attr(
not(PyPy), not(any(PyPy, GraalPy)),
doc = "[`prepare_freethreaded_python`](crate::prepare_freethreaded_python)" doc = "[`prepare_freethreaded_python`](crate::prepare_freethreaded_python)"
)] )]
#[cfg_attr(PyPy, doc = "`prepare_freethreaded_python`")] #[cfg_attr(PyPy, doc = "`prepare_freethreaded_python`")]

View File

@ -6,7 +6,7 @@ use crate::ffi_ptr_ext::FfiPtrExt;
use crate::instance::Bound; use crate::instance::Bound;
use crate::py_result_ext::PyResultExt; use crate::py_result_ext::PyResultExt;
use crate::type_object::{HasPyGilRef, PyTypeCheck, PyTypeInfo}; use crate::type_object::{HasPyGilRef, PyTypeCheck, PyTypeInfo};
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
use crate::types::PySuper; use crate::types::PySuper;
use crate::types::{PyDict, PyIterator, PyList, PyString, PyTuple, PyType}; use crate::types::{PyDict, PyIterator, PyList, PyString, PyTuple, PyType};
use crate::{err, ffi, Py, PyNativeType, Python}; use crate::{err, ffi, Py, PyNativeType, Python};
@ -929,7 +929,7 @@ impl PyAny {
/// Return a proxy object that delegates method calls to a parent or sibling class of type. /// Return a proxy object that delegates method calls to a parent or sibling class of type.
/// ///
/// This is equivalent to the Python expression `super()` /// This is equivalent to the Python expression `super()`
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn py_super(&self) -> PyResult<&PySuper> { pub fn py_super(&self) -> PyResult<&PySuper> {
self.as_borrowed().py_super().map(Bound::into_gil_ref) self.as_borrowed().py_super().map(Bound::into_gil_ref)
} }
@ -1708,7 +1708,7 @@ pub trait PyAnyMethods<'py>: crate::sealed::Sealed {
/// Return a proxy object that delegates method calls to a parent or sibling class of type. /// Return a proxy object that delegates method calls to a parent or sibling class of type.
/// ///
/// This is equivalent to the Python expression `super()` /// This is equivalent to the Python expression `super()`
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
fn py_super(&self) -> PyResult<Bound<'py, PySuper>>; fn py_super(&self) -> PyResult<Bound<'py, PySuper>>;
} }
@ -1975,6 +1975,7 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(all( if #[cfg(all(
not(PyPy), not(PyPy),
not(GraalPy),
any(Py_3_10, all(not(Py_LIMITED_API), Py_3_9)) // PyObject_CallNoArgs was added to python in 3.9 but to limited API in 3.10 any(Py_3_10, all(not(Py_LIMITED_API), Py_3_9)) // PyObject_CallNoArgs was added to python in 3.9 but to limited API in 3.10
))] { ))] {
// Optimized path on python 3.9+ // Optimized path on python 3.9+
@ -2010,7 +2011,7 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> {
N: IntoPy<Py<PyString>>, N: IntoPy<Py<PyString>>,
{ {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(all(Py_3_9, not(any(Py_LIMITED_API, PyPy))))] { if #[cfg(all(Py_3_9, not(any(Py_LIMITED_API, PyPy, GraalPy))))] {
let py = self.py(); let py = self.py();
// Optimized path on python 3.9+ // Optimized path on python 3.9+
@ -2265,7 +2266,7 @@ impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny> {
inner(self, value.to_object(py).into_bound(py)) inner(self, value.to_object(py).into_bound(py))
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
fn py_super(&self) -> PyResult<Bound<'py, PySuper>> { fn py_super(&self) -> PyResult<Bound<'py, PySuper>> {
PySuper::new_bound(&self.get_type(), self) PySuper::new_bound(&self.get_type(), self)
} }

View File

@ -53,7 +53,7 @@ impl PyComplex {
} }
} }
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
mod not_limited_impls { mod not_limited_impls {
use crate::ffi_ptr_ext::FfiPtrExt; use crate::ffi_ptr_ext::FfiPtrExt;
use crate::Borrowed; use crate::Borrowed;
@ -264,10 +264,10 @@ pub trait PyComplexMethods<'py>: crate::sealed::Sealed {
/// Returns the imaginary part of the complex number. /// Returns the imaginary part of the complex number.
fn imag(&self) -> c_double; fn imag(&self) -> c_double;
/// Returns `|self|`. /// Returns `|self|`.
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
fn abs(&self) -> c_double; fn abs(&self) -> c_double;
/// Returns `self` raised to the power of `other`. /// Returns `self` raised to the power of `other`.
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
fn pow(&self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex>; fn pow(&self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex>;
} }
@ -280,7 +280,7 @@ impl<'py> PyComplexMethods<'py> for Bound<'py, PyComplex> {
unsafe { ffi::PyComplex_ImagAsDouble(self.as_ptr()) } unsafe { ffi::PyComplex_ImagAsDouble(self.as_ptr()) }
} }
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
fn abs(&self) -> c_double { fn abs(&self) -> c_double {
unsafe { unsafe {
let val = (*self.as_ptr().cast::<ffi::PyComplexObject>()).cval; let val = (*self.as_ptr().cast::<ffi::PyComplexObject>()).cval;
@ -288,7 +288,7 @@ impl<'py> PyComplexMethods<'py> for Bound<'py, PyComplex> {
} }
} }
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
fn pow(&self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex> { fn pow(&self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex> {
use crate::ffi_ptr_ext::FfiPtrExt; use crate::ffi_ptr_ext::FfiPtrExt;
unsafe { unsafe {

View File

@ -11,6 +11,8 @@ use crate::ffi::{
PyDateTime_DATE_GET_FOLD, PyDateTime_DATE_GET_HOUR, PyDateTime_DATE_GET_MICROSECOND, PyDateTime_DATE_GET_FOLD, PyDateTime_DATE_GET_HOUR, PyDateTime_DATE_GET_MICROSECOND,
PyDateTime_DATE_GET_MINUTE, PyDateTime_DATE_GET_SECOND, PyDateTime_DATE_GET_MINUTE, PyDateTime_DATE_GET_SECOND,
}; };
#[cfg(GraalPy)]
use crate::ffi::{PyDateTime_DATE_GET_TZINFO, PyDateTime_TIME_GET_TZINFO, Py_IsNone};
use crate::ffi::{ use crate::ffi::{
PyDateTime_DELTA_GET_DAYS, PyDateTime_DELTA_GET_MICROSECONDS, PyDateTime_DELTA_GET_SECONDS, PyDateTime_DELTA_GET_DAYS, PyDateTime_DELTA_GET_MICROSECONDS, PyDateTime_DELTA_GET_SECONDS,
}; };
@ -552,6 +554,7 @@ impl<'py> PyTzInfoAccess<'py> for &'py PyDateTime {
impl<'py> PyTzInfoAccess<'py> for Bound<'py, PyDateTime> { impl<'py> PyTzInfoAccess<'py> for Bound<'py, PyDateTime> {
fn get_tzinfo_bound(&self) -> Option<Bound<'py, PyTzInfo>> { fn get_tzinfo_bound(&self) -> Option<Bound<'py, PyTzInfo>> {
let ptr = self.as_ptr() as *mut ffi::PyDateTime_DateTime; let ptr = self.as_ptr() as *mut ffi::PyDateTime_DateTime;
#[cfg(not(GraalPy))]
unsafe { unsafe {
if (*ptr).hastzinfo != 0 { if (*ptr).hastzinfo != 0 {
Some( Some(
@ -565,6 +568,20 @@ impl<'py> PyTzInfoAccess<'py> for Bound<'py, PyDateTime> {
None None
} }
} }
#[cfg(GraalPy)]
unsafe {
let res = PyDateTime_DATE_GET_TZINFO(ptr as *mut ffi::PyObject);
if Py_IsNone(res) == 1 {
None
} else {
Some(
res.assume_borrowed(self.py())
.to_owned()
.downcast_into_unchecked(),
)
}
}
} }
} }
@ -740,6 +757,7 @@ impl<'py> PyTzInfoAccess<'py> for &'py PyTime {
impl<'py> PyTzInfoAccess<'py> for Bound<'py, PyTime> { impl<'py> PyTzInfoAccess<'py> for Bound<'py, PyTime> {
fn get_tzinfo_bound(&self) -> Option<Bound<'py, PyTzInfo>> { fn get_tzinfo_bound(&self) -> Option<Bound<'py, PyTzInfo>> {
let ptr = self.as_ptr() as *mut ffi::PyDateTime_Time; let ptr = self.as_ptr() as *mut ffi::PyDateTime_Time;
#[cfg(not(GraalPy))]
unsafe { unsafe {
if (*ptr).hastzinfo != 0 { if (*ptr).hastzinfo != 0 {
Some( Some(
@ -753,6 +771,20 @@ impl<'py> PyTzInfoAccess<'py> for Bound<'py, PyTime> {
None None
} }
} }
#[cfg(GraalPy)]
unsafe {
let res = PyDateTime_TIME_GET_TZINFO(ptr as *mut ffi::PyObject);
if Py_IsNone(res) == 1 {
None
} else {
Some(
res.assume_borrowed(self.py())
.to_owned()
.downcast_into_unchecked(),
)
}
}
} }
} }

View File

@ -20,11 +20,11 @@ pyobject_native_type!(
); );
/// Represents a Python `dict_keys`. /// Represents a Python `dict_keys`.
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(transparent)] #[repr(transparent)]
pub struct PyDictKeys(PyAny); pub struct PyDictKeys(PyAny);
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pyobject_native_type_core!( pyobject_native_type_core!(
PyDictKeys, PyDictKeys,
pyobject_native_static_type_object!(ffi::PyDictKeys_Type), pyobject_native_static_type_object!(ffi::PyDictKeys_Type),
@ -32,11 +32,11 @@ pyobject_native_type_core!(
); );
/// Represents a Python `dict_values`. /// Represents a Python `dict_values`.
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(transparent)] #[repr(transparent)]
pub struct PyDictValues(PyAny); pub struct PyDictValues(PyAny);
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pyobject_native_type_core!( pyobject_native_type_core!(
PyDictValues, PyDictValues,
pyobject_native_static_type_object!(ffi::PyDictValues_Type), pyobject_native_static_type_object!(ffi::PyDictValues_Type),
@ -44,11 +44,11 @@ pyobject_native_type_core!(
); );
/// Represents a Python `dict_items`. /// Represents a Python `dict_items`.
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
#[repr(transparent)] #[repr(transparent)]
pub struct PyDictItems(PyAny); pub struct PyDictItems(PyAny);
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pyobject_native_type_core!( pyobject_native_type_core!(
PyDictItems, PyDictItems,
pyobject_native_static_type_object!(ffi::PyDictItems_Type), pyobject_native_static_type_object!(ffi::PyDictItems_Type),
@ -76,14 +76,14 @@ impl PyDict {
/// Deprecated form of [`from_sequence_bound`][PyDict::from_sequence_bound]. /// Deprecated form of [`from_sequence_bound`][PyDict::from_sequence_bound].
#[cfg_attr( #[cfg_attr(
all(not(PyPy), not(feature = "gil-refs")), all(not(any(PyPy, GraalPy)), not(feature = "gil-refs")),
deprecated( deprecated(
since = "0.21.0", since = "0.21.0",
note = "`PyDict::from_sequence` will be replaced by `PyDict::from_sequence_bound` in a future PyO3 version" note = "`PyDict::from_sequence` will be replaced by `PyDict::from_sequence_bound` in a future PyO3 version"
) )
)] )]
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn from_sequence(seq: &PyAny) -> PyResult<&PyDict> { pub fn from_sequence(seq: &PyAny) -> PyResult<&PyDict> {
Self::from_sequence_bound(&seq.as_borrowed()).map(Bound::into_gil_ref) Self::from_sequence_bound(&seq.as_borrowed()).map(Bound::into_gil_ref)
} }
@ -95,7 +95,7 @@ impl PyDict {
/// ///
/// Returns an error on invalid input. In the case of key collisions, /// Returns an error on invalid input. In the case of key collisions,
/// this keeps the last entry seen. /// this keeps the last entry seen.
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn from_sequence_bound<'py>(seq: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyDict>> { pub fn from_sequence_bound<'py>(seq: &Bound<'py, PyAny>) -> PyResult<Bound<'py, PyDict>> {
let py = seq.py(); let py = seq.py();
let dict = Self::new_bound(py); let dict = Self::new_bound(py);
@ -542,12 +542,12 @@ impl<'a, 'py> Borrowed<'a, 'py, PyDict> {
} }
fn dict_len(dict: &Bound<'_, PyDict>) -> Py_ssize_t { fn dict_len(dict: &Bound<'_, PyDict>) -> Py_ssize_t {
#[cfg(any(not(Py_3_8), PyPy, Py_LIMITED_API))] #[cfg(any(not(Py_3_8), PyPy, GraalPy, Py_LIMITED_API))]
unsafe { unsafe {
ffi::PyDict_Size(dict.as_ptr()) ffi::PyDict_Size(dict.as_ptr())
} }
#[cfg(all(Py_3_8, not(PyPy), not(Py_LIMITED_API)))] #[cfg(all(Py_3_8, not(PyPy), not(GraalPy), not(Py_LIMITED_API)))]
unsafe { unsafe {
(*dict.as_ptr().cast::<ffi::PyDictObject>()).ma_used (*dict.as_ptr().cast::<ffi::PyDictObject>()).ma_used
} }
@ -824,7 +824,7 @@ where
#[cfg_attr(not(feature = "gil-refs"), allow(deprecated))] #[cfg_attr(not(feature = "gil-refs"), allow(deprecated))]
mod tests { mod tests {
use super::*; use super::*;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
use crate::exceptions; use crate::exceptions;
use crate::types::PyTuple; use crate::types::PyTuple;
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap};
@ -850,7 +850,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
fn test_from_sequence() { fn test_from_sequence() {
Python::with_gil(|py| { Python::with_gil(|py| {
let items = PyList::new(py, &vec![("a", 1), ("b", 2)]); let items = PyList::new(py, &vec![("a", 1), ("b", 2)]);
@ -881,7 +881,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
fn test_from_sequence_err() { fn test_from_sequence_err() {
Python::with_gil(|py| { Python::with_gil(|py| {
let items = PyList::new(py, &vec!["a", "b"]); let items = PyList::new(py, &vec!["a", "b"]);
@ -955,7 +955,7 @@ mod tests {
#[test] #[test]
#[allow(deprecated)] #[allow(deprecated)]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
fn test_get_item_with_error() { fn test_get_item_with_error() {
Python::with_gil(|py| { Python::with_gil(|py| {
let mut v = HashMap::new(); let mut v = HashMap::new();
@ -1388,7 +1388,7 @@ mod tests {
}); });
} }
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
fn abc_dict(py: Python<'_>) -> Bound<'_, PyDict> { fn abc_dict(py: Python<'_>) -> Bound<'_, PyDict> {
let mut map = HashMap::<&'static str, i32>::new(); let mut map = HashMap::<&'static str, i32>::new();
map.insert("a", 1); map.insert("a", 1);
@ -1398,7 +1398,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
fn dict_keys_view() { fn dict_keys_view() {
Python::with_gil(|py| { Python::with_gil(|py| {
let dict = abc_dict(py); let dict = abc_dict(py);
@ -1410,7 +1410,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
fn dict_values_view() { fn dict_values_view() {
Python::with_gil(|py| { Python::with_gil(|py| {
let dict = abc_dict(py); let dict = abc_dict(py);
@ -1422,7 +1422,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
fn dict_items_view() { fn dict_items_view() {
Python::with_gil(|py| { Python::with_gil(|py| {
let dict = abc_dict(py); let dict = abc_dict(py);

View File

@ -60,7 +60,7 @@ impl<'py> PyFrozenSetBuilder<'py> {
#[repr(transparent)] #[repr(transparent)]
pub struct PyFrozenSet(PyAny); pub struct PyFrozenSet(PyAny);
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pyobject_native_type!( pyobject_native_type!(
PyFrozenSet, PyFrozenSet,
ffi::PySetObject, ffi::PySetObject,
@ -68,7 +68,7 @@ pyobject_native_type!(
#checkfunction=ffi::PyFrozenSet_Check #checkfunction=ffi::PyFrozenSet_Check
); );
#[cfg(PyPy)] #[cfg(any(PyPy, GraalPy))]
pyobject_native_type_core!( pyobject_native_type_core!(
PyFrozenSet, PyFrozenSet,
pyobject_native_static_type_object!(ffi::PyFrozenSet_Type), pyobject_native_static_type_object!(ffi::PyFrozenSet_Type),

View File

@ -5,7 +5,7 @@ pub use self::boolobject::{PyBool, PyBoolMethods};
pub use self::bytearray::{PyByteArray, PyByteArrayMethods}; pub use self::bytearray::{PyByteArray, PyByteArrayMethods};
pub use self::bytes::{PyBytes, PyBytesMethods}; pub use self::bytes::{PyBytes, PyBytesMethods};
pub use self::capsule::{PyCapsule, PyCapsuleMethods}; pub use self::capsule::{PyCapsule, PyCapsuleMethods};
#[cfg(all(not(Py_LIMITED_API), not(PyPy)))] #[cfg(all(not(Py_LIMITED_API), not(PyPy), not(GraalPy)))]
pub use self::code::PyCode; pub use self::code::PyCode;
pub use self::complex::{PyComplex, PyComplexMethods}; pub use self::complex::{PyComplex, PyComplexMethods};
#[allow(deprecated)] #[allow(deprecated)]
@ -17,15 +17,15 @@ pub use self::datetime::{
PyTimeAccess, PyTzInfo, PyTzInfoAccess, PyTimeAccess, PyTzInfo, PyTzInfoAccess,
}; };
pub use self::dict::{IntoPyDict, PyDict, PyDictMethods}; pub use self::dict::{IntoPyDict, PyDict, PyDictMethods};
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub use self::dict::{PyDictItems, PyDictKeys, PyDictValues}; pub use self::dict::{PyDictItems, PyDictKeys, PyDictValues};
pub use self::ellipsis::PyEllipsis; pub use self::ellipsis::PyEllipsis;
pub use self::float::{PyFloat, PyFloatMethods}; pub use self::float::{PyFloat, PyFloatMethods};
#[cfg(all(not(Py_LIMITED_API), not(PyPy)))] #[cfg(all(not(Py_LIMITED_API), not(PyPy), not(GraalPy)))]
pub use self::frame::PyFrame; pub use self::frame::PyFrame;
pub use self::frozenset::{PyFrozenSet, PyFrozenSetBuilder, PyFrozenSetMethods}; pub use self::frozenset::{PyFrozenSet, PyFrozenSetBuilder, PyFrozenSetMethods};
pub use self::function::PyCFunction; pub use self::function::PyCFunction;
#[cfg(all(not(Py_LIMITED_API), not(PyPy)))] #[cfg(all(not(Py_LIMITED_API), not(PyPy), not(GraalPy)))]
pub use self::function::PyFunction; pub use self::function::PyFunction;
pub use self::iterator::PyIterator; pub use self::iterator::PyIterator;
pub use self::list::{PyList, PyListMethods}; pub use self::list::{PyList, PyListMethods};
@ -36,7 +36,7 @@ pub use self::none::PyNone;
pub use self::notimplemented::PyNotImplemented; pub use self::notimplemented::PyNotImplemented;
pub use self::num::PyLong; pub use self::num::PyLong;
pub use self::num::PyLong as PyInt; pub use self::num::PyLong as PyInt;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub use self::pysuper::PySuper; pub use self::pysuper::PySuper;
pub use self::sequence::{PySequence, PySequenceMethods}; pub use self::sequence::{PySequence, PySequenceMethods};
pub use self::set::{PySet, PySetMethods}; pub use self::set::{PySet, PySetMethods};
@ -328,7 +328,7 @@ pub(crate) mod boolobject;
pub(crate) mod bytearray; pub(crate) mod bytearray;
pub(crate) mod bytes; pub(crate) mod bytes;
pub(crate) mod capsule; pub(crate) mod capsule;
#[cfg(all(not(Py_LIMITED_API), not(PyPy)))] #[cfg(all(not(Py_LIMITED_API), not(PyPy), not(GraalPy)))]
mod code; mod code;
pub(crate) mod complex; pub(crate) mod complex;
#[cfg(not(Py_LIMITED_API))] #[cfg(not(Py_LIMITED_API))]
@ -336,7 +336,7 @@ pub(crate) mod datetime;
pub(crate) mod dict; pub(crate) mod dict;
mod ellipsis; mod ellipsis;
pub(crate) mod float; pub(crate) mod float;
#[cfg(all(not(Py_LIMITED_API), not(PyPy)))] #[cfg(all(not(Py_LIMITED_API), not(PyPy), not(GraalPy)))]
mod frame; mod frame;
pub(crate) mod frozenset; pub(crate) mod frozenset;
mod function; mod function;
@ -348,7 +348,7 @@ pub(crate) mod module;
mod none; mod none;
mod notimplemented; mod notimplemented;
mod num; mod num;
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
mod pysuper; mod pysuper;
pub(crate) mod sequence; pub(crate) mod sequence;
pub(crate) mod set; pub(crate) mod set;

View File

@ -134,7 +134,7 @@ impl PySequence {
/// Returns the number of occurrences of `value` in self, that is, return the /// Returns the number of occurrences of `value` in self, that is, return the
/// number of keys for which `self[key] == value`. /// number of keys for which `self[key] == value`.
#[inline] #[inline]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pub fn count<V>(&self, value: V) -> PyResult<usize> pub fn count<V>(&self, value: V) -> PyResult<usize>
where where
V: ToPyObject, V: ToPyObject,
@ -870,7 +870,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
fn test_seq_count() { fn test_seq_count() {
Python::with_gil(|py| { Python::with_gil(|py| {
let v: Vec<i32> = vec![1, 1, 2, 3, 5, 8]; let v: Vec<i32> = vec![1, 1, 2, 3, 5, 8];

View File

@ -14,7 +14,7 @@ use std::ptr;
#[repr(transparent)] #[repr(transparent)]
pub struct PySet(PyAny); pub struct PySet(PyAny);
#[cfg(not(PyPy))] #[cfg(not(any(PyPy, GraalPy)))]
pyobject_native_type!( pyobject_native_type!(
PySet, PySet,
ffi::PySetObject, ffi::PySetObject,
@ -22,7 +22,7 @@ pyobject_native_type!(
#checkfunction=ffi::PySet_Check #checkfunction=ffi::PySet_Check
); );
#[cfg(PyPy)] #[cfg(any(PyPy, GraalPy))]
pyobject_native_type_core!( pyobject_native_type_core!(
PySet, PySet,
pyobject_native_static_type_object!(ffi::PySet_Type), pyobject_native_static_type_object!(ffi::PySet_Type),

View File

@ -270,7 +270,7 @@ impl PyString {
/// ///
/// By using this API, you accept responsibility for testing that PyStringData behaves as /// By using this API, you accept responsibility for testing that PyStringData behaves as
/// expected on the targets where you plan to distribute your software. /// expected on the targets where you plan to distribute your software.
#[cfg(not(Py_LIMITED_API))] #[cfg(not(any(Py_LIMITED_API, GraalPy)))]
pub unsafe fn data(&self) -> PyResult<PyStringData<'_>> { pub unsafe fn data(&self) -> PyResult<PyStringData<'_>> {
self.as_borrowed().data() self.as_borrowed().data()
} }
@ -319,7 +319,7 @@ pub trait PyStringMethods<'py>: crate::sealed::Sealed {
/// ///
/// By using this API, you accept responsibility for testing that PyStringData behaves as /// By using this API, you accept responsibility for testing that PyStringData behaves as
/// expected on the targets where you plan to distribute your software. /// expected on the targets where you plan to distribute your software.
#[cfg(not(Py_LIMITED_API))] #[cfg(not(any(Py_LIMITED_API, GraalPy)))]
unsafe fn data(&self) -> PyResult<PyStringData<'_>>; unsafe fn data(&self) -> PyResult<PyStringData<'_>>;
} }
@ -345,7 +345,7 @@ impl<'py> PyStringMethods<'py> for Bound<'py, PyString> {
} }
} }
#[cfg(not(Py_LIMITED_API))] #[cfg(not(any(Py_LIMITED_API, GraalPy)))]
unsafe fn data(&self) -> PyResult<PyStringData<'_>> { unsafe fn data(&self) -> PyResult<PyStringData<'_>> {
self.as_borrowed().data() self.as_borrowed().data()
} }
@ -408,7 +408,7 @@ impl<'a> Borrowed<'a, '_, PyString> {
Cow::Owned(String::from_utf8_lossy(bytes.as_bytes()).into_owned()) Cow::Owned(String::from_utf8_lossy(bytes.as_bytes()).into_owned())
} }
#[cfg(not(Py_LIMITED_API))] #[cfg(not(any(Py_LIMITED_API, GraalPy)))]
unsafe fn data(self) -> PyResult<PyStringData<'a>> { unsafe fn data(self) -> PyResult<PyStringData<'a>> {
let ptr = self.as_ptr(); let ptr = self.as_ptr();

View File

@ -34,9 +34,9 @@ fn new_from_iter<'py>(
let mut counter: Py_ssize_t = 0; let mut counter: Py_ssize_t = 0;
for obj in elements.take(len as usize) { for obj in elements.take(len as usize) {
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
ffi::PyTuple_SET_ITEM(ptr, counter, obj.into_ptr()); ffi::PyTuple_SET_ITEM(ptr, counter, obj.into_ptr());
#[cfg(any(Py_LIMITED_API, PyPy))] #[cfg(any(Py_LIMITED_API, PyPy, GraalPy))]
ffi::PyTuple_SetItem(ptr, counter, obj.into_ptr()); ffi::PyTuple_SetItem(ptr, counter, obj.into_ptr());
counter += 1; counter += 1;
} }
@ -186,7 +186,7 @@ impl PyTuple {
/// # Safety /// # Safety
/// ///
/// Caller must verify that the index is within the bounds of the tuple. /// Caller must verify that the index is within the bounds of the tuple.
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
pub unsafe fn get_item_unchecked(&self, index: usize) -> &PyAny { pub unsafe fn get_item_unchecked(&self, index: usize) -> &PyAny {
self.as_borrowed() self.as_borrowed()
.get_borrowed_item_unchecked(index) .get_borrowed_item_unchecked(index)
@ -194,7 +194,7 @@ impl PyTuple {
} }
/// Returns `self` as a slice of objects. /// Returns `self` as a slice of objects.
#[cfg(not(Py_LIMITED_API))] #[cfg(not(any(Py_LIMITED_API, GraalPy)))]
pub fn as_slice(&self) -> &[&PyAny] { pub fn as_slice(&self) -> &[&PyAny] {
// This is safe because &PyAny has the same memory layout as *mut ffi::PyObject, // This is safe because &PyAny has the same memory layout as *mut ffi::PyObject,
// and because tuples are immutable. // and because tuples are immutable.
@ -293,7 +293,7 @@ pub trait PyTupleMethods<'py>: crate::sealed::Sealed {
/// # Safety /// # Safety
/// ///
/// Caller must verify that the index is within the bounds of the tuple. /// Caller must verify that the index is within the bounds of the tuple.
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
unsafe fn get_item_unchecked(&self, index: usize) -> Bound<'py, PyAny>; unsafe fn get_item_unchecked(&self, index: usize) -> Bound<'py, PyAny>;
/// Like [`get_item_unchecked`][PyTupleMethods::get_item_unchecked], but returns a borrowed object, /// Like [`get_item_unchecked`][PyTupleMethods::get_item_unchecked], but returns a borrowed object,
@ -302,11 +302,11 @@ pub trait PyTupleMethods<'py>: crate::sealed::Sealed {
/// # Safety /// # Safety
/// ///
/// Caller must verify that the index is within the bounds of the tuple. /// Caller must verify that the index is within the bounds of the tuple.
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
unsafe fn get_borrowed_item_unchecked<'a>(&'a self, index: usize) -> Borrowed<'a, 'py, PyAny>; unsafe fn get_borrowed_item_unchecked<'a>(&'a self, index: usize) -> Borrowed<'a, 'py, PyAny>;
/// Returns `self` as a slice of objects. /// Returns `self` as a slice of objects.
#[cfg(not(Py_LIMITED_API))] #[cfg(not(any(Py_LIMITED_API, GraalPy)))]
fn as_slice(&self) -> &[Bound<'py, PyAny>]; fn as_slice(&self) -> &[Bound<'py, PyAny>];
/// Determines if self contains `value`. /// Determines if self contains `value`.
@ -339,9 +339,9 @@ pub trait PyTupleMethods<'py>: crate::sealed::Sealed {
impl<'py> PyTupleMethods<'py> for Bound<'py, PyTuple> { impl<'py> PyTupleMethods<'py> for Bound<'py, PyTuple> {
fn len(&self) -> usize { fn len(&self) -> usize {
unsafe { unsafe {
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
let size = ffi::PyTuple_GET_SIZE(self.as_ptr()); let size = ffi::PyTuple_GET_SIZE(self.as_ptr());
#[cfg(any(Py_LIMITED_API, PyPy))] #[cfg(any(Py_LIMITED_API, PyPy, GraalPy))]
let size = ffi::PyTuple_Size(self.as_ptr()); let size = ffi::PyTuple_Size(self.as_ptr());
// non-negative Py_ssize_t should always fit into Rust uint // non-negative Py_ssize_t should always fit into Rust uint
size as usize size as usize
@ -376,17 +376,17 @@ impl<'py> PyTupleMethods<'py> for Bound<'py, PyTuple> {
self.as_borrowed().get_borrowed_item(index) self.as_borrowed().get_borrowed_item(index)
} }
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
unsafe fn get_item_unchecked(&self, index: usize) -> Bound<'py, PyAny> { unsafe fn get_item_unchecked(&self, index: usize) -> Bound<'py, PyAny> {
self.get_borrowed_item_unchecked(index).to_owned() self.get_borrowed_item_unchecked(index).to_owned()
} }
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
unsafe fn get_borrowed_item_unchecked<'a>(&'a self, index: usize) -> Borrowed<'a, 'py, PyAny> { unsafe fn get_borrowed_item_unchecked<'a>(&'a self, index: usize) -> Borrowed<'a, 'py, PyAny> {
self.as_borrowed().get_borrowed_item_unchecked(index) self.as_borrowed().get_borrowed_item_unchecked(index)
} }
#[cfg(not(Py_LIMITED_API))] #[cfg(not(any(Py_LIMITED_API, GraalPy)))]
fn as_slice(&self) -> &[Bound<'py, PyAny>] { fn as_slice(&self) -> &[Bound<'py, PyAny>] {
// This is safe because Bound<'py, PyAny> has the same memory layout as *mut ffi::PyObject, // This is safe because Bound<'py, PyAny> has the same memory layout as *mut ffi::PyObject,
// and because tuples are immutable. // and because tuples are immutable.
@ -436,7 +436,7 @@ impl<'a, 'py> Borrowed<'a, 'py, PyTuple> {
} }
} }
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
unsafe fn get_borrowed_item_unchecked(self, index: usize) -> Borrowed<'a, 'py, PyAny> { unsafe fn get_borrowed_item_unchecked(self, index: usize) -> Borrowed<'a, 'py, PyAny> {
ffi::PyTuple_GET_ITEM(self.as_ptr(), index as Py_ssize_t).assume_borrowed(self.py()) ffi::PyTuple_GET_ITEM(self.as_ptr(), index as Py_ssize_t).assume_borrowed(self.py())
} }
@ -591,9 +591,9 @@ impl<'a, 'py> BorrowedTupleIterator<'a, 'py> {
tuple: Borrowed<'a, 'py, PyTuple>, tuple: Borrowed<'a, 'py, PyTuple>,
index: usize, index: usize,
) -> Borrowed<'a, 'py, PyAny> { ) -> Borrowed<'a, 'py, PyAny> {
#[cfg(any(Py_LIMITED_API, PyPy))] #[cfg(any(Py_LIMITED_API, PyPy, GraalPy))]
let item = tuple.get_borrowed_item(index).expect("tuple.get failed"); let item = tuple.get_borrowed_item(index).expect("tuple.get failed");
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
let item = tuple.get_borrowed_item_unchecked(index); let item = tuple.get_borrowed_item_unchecked(index);
item item
} }
@ -696,10 +696,10 @@ fn type_output() -> TypeInfo {
{ {
let t = obj.downcast::<PyTuple>()?; let t = obj.downcast::<PyTuple>()?;
if t.len() == $length { if t.len() == $length {
#[cfg(any(Py_LIMITED_API, PyPy))] #[cfg(any(Py_LIMITED_API, PyPy, GraalPy))]
return Ok(($(t.get_borrowed_item($n)?.extract::<$T>()?,)+)); return Ok(($(t.get_borrowed_item($n)?.extract::<$T>()?,)+));
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
unsafe {return Ok(($(t.get_borrowed_item_unchecked($n).extract::<$T>()?,)+));} unsafe {return Ok(($(t.get_borrowed_item_unchecked($n).extract::<$T>()?,)+));}
} else { } else {
Err(wrong_tuple_length(t, $length)) Err(wrong_tuple_length(t, $length))
@ -718,9 +718,9 @@ fn array_into_tuple<const N: usize>(py: Python<'_>, array: [PyObject; N]) -> Py<
let ptr = ffi::PyTuple_New(N.try_into().expect("0 < N <= 12")); let ptr = ffi::PyTuple_New(N.try_into().expect("0 < N <= 12"));
let tup = Py::from_owned_ptr(py, ptr); let tup = Py::from_owned_ptr(py, ptr);
for (index, obj) in array.into_iter().enumerate() { for (index, obj) in array.into_iter().enumerate() {
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
ffi::PyTuple_SET_ITEM(ptr, index as ffi::Py_ssize_t, obj.into_ptr()); ffi::PyTuple_SET_ITEM(ptr, index as ffi::Py_ssize_t, obj.into_ptr());
#[cfg(any(Py_LIMITED_API, PyPy))] #[cfg(any(Py_LIMITED_API, PyPy, GraalPy))]
ffi::PyTuple_SetItem(ptr, index as ffi::Py_ssize_t, obj.into_ptr()); ffi::PyTuple_SetItem(ptr, index as ffi::Py_ssize_t, obj.into_ptr());
} }
tup tup
@ -1010,7 +1010,7 @@ mod tests {
} }
#[test] #[test]
#[cfg(not(Py_LIMITED_API))] #[cfg(not(any(Py_LIMITED_API, GraalPy)))]
fn test_as_slice() { fn test_as_slice() {
Python::with_gil(|py| { Python::with_gil(|py| {
let ob = (1, 2, 3).to_object(py); let ob = (1, 2, 3).to_object(py);
@ -1112,7 +1112,7 @@ mod tests {
}); });
} }
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
#[test] #[test]
fn test_tuple_get_item_unchecked_sanity() { fn test_tuple_get_item_unchecked_sanity() {
Python::with_gil(|py| { Python::with_gil(|py| {
@ -1457,7 +1457,7 @@ mod tests {
.unwrap(), .unwrap(),
2 2
); );
#[cfg(not(any(Py_LIMITED_API, PyPy)))] #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
{ {
assert_eq!( assert_eq!(
unsafe { tuple.get_item_unchecked(2) } unsafe { tuple.get_item_unchecked(2) }