memoryview(direct ByteBuffer) has incorrect nbytes field
Thrameos opened this issue · comments
There appears to be a bug in the nbytes on some systems when using direct byte buffer. This prevents them from being used with io.readinto
Bug replication
>>> import jpype
>>> import jpype.imports
>>> jpype.startJVM()
>>> from java.nio import ByteBuffer
>>> memoryview(ByteBuffer.allocateDirect(100)).nbytes
25096256
Hi, any plans to make a new release soon? I'm running into what I believe to be this bug when unpickling jpype objects. Causing BufferOverflowException.
File "/opt/project/src/common/stateful_calculations.py", line 41, in get_stored_state_object
loaded = jpype.pickle.JUnpickler(fd).load()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/code/.venv/lib/python3.11/site-packages/jpype/pickle.py", line 161, in __call__
return decoder.unpack(args[0])
^^^^^^^^^^^^^^^^^^^^^^^
java.nio.java.nio.BufferOverflowException: java.nio.BufferOverflowException
Also; this print(memoryview(jpype.java.nio.ByteBuffer.allocateDirect(100)).nbytes)
outputs some varying large numbers like 52175792
Thanks for a great library! 🙂
Until the next release you could just use the a development version as such:
pip install git+https://github.com/jpype-project/jpype
Does that really work? Considering how this library compiles .so files that is distributed along with the package.
Sorry I have been so slow. I was hoping to get a few things addressed before the next release, but I haven't had much time. I will try to wrap them up and get out a release this month.