pybind / pybind/pybind11

compare_buffer_info does not consider <i and i equal on a little-endian machine

Open
#1,787 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

The compare_buffer_info template will reject buffer formats of <i and i as being different.

This can be observed by calling bind_vector on vector<int32_t> with py::buffer_info(), then attempting to construct one as:

arr = (ctypes.c_int32 * 10)()
MyVector(arr)
# TypeError: TypeError: Format mismatch (Python: <i C++: i)

<i means "little endian int", and i means "native int". On a little-endian machine, these should be considered compatible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the compare_buffer_info template and reproduce the mismatch through bind_vector with py::buffer_info, using the ctypes.c_int32 example from the issue. Done means little-endian '<i' and native 'i' formats are accepted as compatible on little-endian machines without rejecting genuinely incompatible formats.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.