-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing an array of size zero doesn't work #239
Comments
The segfault should obviously not happen (will fix that); the others are neither here nor there: an empty Python container is not the same as a null pointer. The code fails b/c it looks for a compatible buffer by asking the object for one through the Python buffer interface and doesn't get any. It doesn't know/check the type to figure if it's a compatible one that could have served up a buffer if only the object had a buffer: there's no end to those cases ( To pass a null pointer here, use
|
Interesting, the crash with the
and oddly, it only happens on Linux. I've put in a protection against asking sequences of length 0 for their buffer info. However, this is once more a case where it's clear that an empty container-like object just isn't a |
Thanks. I agree that an empty buffer is not the same thing as
I'm a little confused by this, because I'm pretty sure you do get a buffer interface from an empty buffer object:
The reason empty buffers are not treated as buffers appears to be because Interestingly, wrapping in
And the exception is not limited to the empty case. So I guess The docs say "PyBUF_FORMAT can be |’d to any of the flags except PyBUF_SIMPLE. The latter already implies format B (unsigned bytes)." And (I don't really understand why non-empty |
The crash is gone with the release of cppyy 3.5.0 and its dependencies. Haven't decided yet on what to do with passing empty arrays, so keeping this open. |
Calling a function with a pointer parameter with a Python object implementing the buffer protocol does not appear to work when the object has zero elements. Is this intended behavior?
(My hope was that
f()
would get called, either with a non-null pointer thatf
should not dereference, or withnullptr
.)Furthermore, a
memoryview
of size 0 causes a crash:Full stack trace
(It looks like the same thing gets printed twice.)
This was with Python 3.12.3 from Homebrew, macOS 14, arm64,
cppyy 3.1.2,
cppyy-backend 1.15.2,
cppyy-cling 6.30.0,
CPyCppyy 1.12.16.
I got the same behavior with Python 3.12.2, x86-64, from conda-forge (running on Rosetta 2), same cppyy versions, except that the error printed before crashing was
*** Break *** floating point exception
. The stack trace was essentially identical to the one above except that some frames were omitted. The exit code was 140 (SIGSYS?) instead of 129 (SIGHUP?), FWIW.Passing
bytes()
raisedTypeError
similarly to the zero-lengtharray.array
, and passingnp.frombuffer(bytes(), dtype=np.uint8)
crashed similarly to the zero-lengthmemoryview
.The text was updated successfully, but these errors were encountered: