PyO3/pyo3 · error

size_t should fit the flag bits

Error message

size_t should fit the flag bits

What it means

pyo3-ffi computes PY_VECTORCALL_ARGUMENTS_OFFSET as 1 shifted left by (bits of size_t - 1). checked_shl returns None if the shift amount is invalid and the code panics with 'size_t should fit the flag bits'. On any real target where size_t is 8/16/32/64 bits this cannot trigger; it's a compile-time-time guard that the platform's size_t supports the bit math.

Source

Thrown at pyo3-ffi/src/abstract_.rs:90

    ) -> *mut PyObject;

    #[cfg(all(Py_3_12, Py_LIMITED_API))] // is an inline function in cpython/abstract.rs on version-specific ABI
    #[cfg_attr(PyPy, link_name = "PyPyVectorcall_NARGS")]
    pub fn PyVectorcall_NARGS(nargsf: size_t) -> Py_ssize_t;

    #[cfg_attr(not(any(Py_3_12, PyPy)), link_name = "_PyVectorcall_Call")] // symbol made public in 3.12
    #[cfg_attr(PyPy, link_name = "PyPyVectorcall_Call")]
    pub fn PyVectorcall_Call(
        callable: *mut PyObject,
        tuple: *mut PyObject,
        dict: *mut PyObject,
    ) -> *mut PyObject;
}

#[cfg(any(Py_3_12, not(Py_LIMITED_API)))]
pub const PY_VECTORCALL_ARGUMENTS_OFFSET: size_t = (1 as size_t)
    .checked_shl((8 * core::mem::size_of::<size_t>() - 1) as u32)
    .expect("size_t should fit the flag bits");

extern_libpython! {
    #[cfg_attr(PyPy, link_name = "PyPyObject_Vectorcall")]
    #[cfg(any(Py_3_12, all(Py_3_11, not(Py_LIMITED_API))))]
    pub fn PyObject_Vectorcall(
        callable: *mut PyObject,
        args: *const *mut PyObject,
        nargsf: size_t,
        kwnames: *mut PyObject,
    ) -> *mut PyObject;

    #[cfg(any(Py_3_12, not(any(Py_LIMITED_API, PyPy))))]
    pub fn PyObject_VectorcallMethod(
        name: *mut PyObject,
        args: *const *mut PyObject,
        nargsf: size_t,
        kwnames: *mut PyObject,
    ) -> *mut PyObject;

View on GitHub (pinned to ac9b6899d3)

Solutions

  1. Compile for a supported platform where size_t is a standard width
  2. Do not use pyo3 on targets with pathological size_t definitions
  3. File an issue with pyo3 if your legitimate target hits this
Defensive patterns

Strategy: type-guard

Type guard

// Only build pyo3-ffi on targets with standard size_t
target_pointer_width in [16, 32, 64] // verified via cfg in build script

Prevention

When it happens

Trigger: Compilation for a target whose size_t is unusually small or where core::mem::size_of::<size_t>()*8 exceeds the valid shift range for u32 checked_shl (>= 32... actually a shift >= width of size_t). Essentially only exotic/nonstandard targets.

Common situations: Cross-compiling pyo3 to an unsupported embedded target with an unusual size_t width.

Related errors


AI-assisted analysis of PyO3/pyo3@ac9b6899d3 (2026-09-05). Data as JSON: /api/errors/248af369d00f25ac. Report an issue: GitHub.