Skip to content

[cppyy] Treat long and long long buffer formats as interchangeable - #23580

Open
guitargeek wants to merge 3 commits into
root-project:masterfrom
guitargeek:sofie-fixup
Open

guitargeek wants to merge 3 commits into
root-project:masterfrom
guitargeek:sofie-fixup

Conversation

@guitargeek

@guitargeek guitargeek commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

numpy and other buffer producers canonicalize the PEP 3118 format char of 64-bit integer dtypes (e.g. int64 is always reported as 'l' on 64-bit platforms), but C++ parameters declared as int64_t resolve to 'long long' on macOS and 'long' on Linux. The exact format-char matching in the array converters therefore rejected valid buffers when the resolved type and the canonicalized buffer format differed, breaking e.g. passing numpy int64 arrays to 'const int64_t*' parameters on macOS.

Add Utility::FormatCodeCompatible() and use it where buffer formats are matched: Utility::GetBuffer() (standard buffer protocol), CArraySetArg() (low-level views), and the 2-dimensional branch of the array converter. As before, the item-size check guards against actual size mismatches.

🤖 Done with the help of AI

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Test Results

    24 files      24 suites   3d 22h 0m 51s ⏱️
 3 880 tests  3 877 ✅ 0 💤 3 ❌
83 069 runs  83 066 ✅ 0 💤 3 ❌

For more details on these failures, see this check.

Results for commit ed88e95.

♻️ This comment has been updated with latest results.

numpy and other buffer producers canonicalize the PEP 3118 format char of
64-bit integer dtypes (e.g. int64 is always reported as 'l' on 64-bit
platforms), but C++ parameters declared as int64_t resolve to 'long long'
on macOS and 'long' on Linux. The exact format-char matching in the array
converters therefore rejected valid buffers when the resolved type and the
canonicalized buffer format differed, breaking e.g. passing numpy int64
arrays to 'const int64_t*' parameters on macOS.

Add Utility::FormatCodeCompatible() and use it where buffer formats are
matched: Utility::GetBuffer() (standard buffer protocol), CArraySetArg()
(low-level views), the 2-dimensional branch of the array converter, and
StdSpanConverter (std::span parameters). As before, the item-size check
guards against actual size mismatches.

Ported from the deleted cppyy bindings (CPyCppyy) to the vendored cppjit
cpyrt sources, after PyROOT was rewired from the cppyy stack to cppjit.

🤖 Done with the help of AI
…NN tutorial"

This reverts commit bb5fa27.

The conversion of numpy int64 arrays to 'const int64_t*' parameters is now
fixed in cppyy itself, which treats same-sized 'long' and 'long long'
buffer formats as interchangeable, so the explicit cppyy.ll.cast workaround
is not needed anymore; the tutorial passes the numpy arrays directly again.
Replace the ad-hoc buffer-format matching with a small PEP 3118 parser.
Formats are reduced to their element type (skipping byte-order prefixes
like ctypes' '<q', repeat counts, and the 'Z' complex marker), classified
by kind (signed/unsigned integer, float, complex, ...) and native size,
and accepted when both match the requested type code.

This subsumes all previously scattered special cases:

- int/long equivalence on Windows and 32-bit Linux in GetBuffer()
- long/long long interchange for numpy's canonicalized int64 format
- 'z'/'Zf' complex-float naming
- signed char ('b') as bool, kept as an explicit documented quirk

and generalizes to both 1-dim and 2-dim LowLevelView branches and to
std::span. As side effects, ctypes' explicitly-endian '<q'/'<d' buffers
are now accepted natively, and complex buffers no longer leak into float
parameters through the 'Zd'-contains-'d' substring accident (std::span,
which performs no item-size check, previously read complex128 buffers as
double).

🤖 Done with the help of AI

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant