{"record":{"id":"93628c5748cbe499","repo":"PyO3/pyo3","slug":"size-t-should-fit-the-flag-bits-93628c","errorCode":null,"errorMessage":"size_t should fit the flag bits","messagePattern":"size_t should fit the flag bits","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-ffi/src/cpython/abstract_.rs","lineNumber":48,"sourceCode":"        callable: *mut PyObject,\n        result: *mut PyObject,\n        where_: *const c_char,\n    ) -> *mut PyObject;\n\n    #[cfg(not(PyPy))]\n    fn _PyObject_MakeTpCall(\n        tstate: *mut PyThreadState,\n        callable: *mut PyObject,\n        args: *const *mut PyObject,\n        nargs: Py_ssize_t,\n        keywords: *mut PyObject,\n    ) -> *mut PyObject;\n}\n\n#[cfg(not(Py_3_12))]\nconst PY_VECTORCALL_ARGUMENTS_OFFSET: size_t = (1 as size_t)\n    .checked_shl((8 * core::mem::size_of::<size_t>() - 1) as u32)\n    .expect(\"size_t should fit the flag bits\");\n\n#[cfg(Py_3_12)] // public API from 3.12\nuse crate::PY_VECTORCALL_ARGUMENTS_OFFSET;\n\n#[inline(always)]\npub unsafe fn PyVectorcall_NARGS(n: size_t) -> Py_ssize_t {\n    let n = n & !PY_VECTORCALL_ARGUMENTS_OFFSET;\n    n.try_into().expect(\"cannot fail due to mask\")\n}\n\n#[cfg(any(PyPy, Py_3_11))]\nextern_libpython! {\n    #[cfg_attr(PyPy, link_name = \"PyPyVectorcall_Function\")]\n    pub fn PyVectorcall_Function(callable: *mut PyObject) -> Option<vectorcallfunc>;\n}\n\n#[cfg(not(any(PyPy, Py_3_11)))]\n#[inline(always)]","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/PyO3/pyo3/blob/ac9b6899d348be4d54614d060dea53a645a12e36/pyo3-ffi/src/cpython/abstract_.rs#L30-L66","documentation":"The CPython <3.12 variant of PY_VECTORCALL_ARGUMENTS_OFFSET is computed as 1 << (size_t bits - 1) and guarded by an expect panicking 'size_t should fit the flag bits'. It's a defensive check that the shift is valid for the platform's size_t; on standard platforms it never fires.","triggerScenarios":"Building for a target where (8 * size_of::<size_t>()) yields an invalid shift amount for size_t — only possible on exotic/nonstandard ABIs.","commonSituations":"Cross-compilation to unusual embedded targets; toolchain misconfiguration giving a bogus size_t size.","solutions":["Use a supported CPython/target combination","Fix the target specification/toolchain so size_t has a standard width","Report to pyo3 if a real-world target triggers this"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// ensure size_t can represent the shifted flag\nassert!(8 * std::mem::size_of::<usize>() >= 16);","tryCatchPattern":null,"preventionTips":["Use mainstream platforms","Test cross-compilation in CI","Avoid nonstandard size_t target specs"],"tags":["rust","pyo3-ffi","const-panic","platform"],"backgroundTag":"const-assertion-panic","analyzedSha":"ac9b6899d348be4d54614d060dea53a645a12e36","analyzedAt":"2026-09-05T09:20:35.319Z","contentChangedAt":"2026-09-05T09:20:35.319Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}