jpy-consortium / jpy

Apache License 2.0
68 stars 16 forks source link

Make the life-cycle management of byte_buffer()'s result (a Java DirectByteBuffer instance) safe and transparent. #126

Open jmao-denver opened 6 months ago

jmao-denver commented 6 months ago

A follow-up of #111

{"byte_buffer", JPy_byte_buffer, METH_VARARGS,
            "byte_buffer(obj) - Return a new Java direct ByteBuffer sharing the same underlying, contiguous buffer of obj via its implemented Buffer Protocol. The resulting PYObject must live "
            "longer than the Java object to ensure the underlying data remains valid. In most cases, this means that java functions called in this manner must not keep any references"
            " to the ByteBuffer"},

Right now the onus is on the user to heed and respect the warning. There might be a chance in the future to remove that if Java opens the DirectByteBuffer API up some more.