ariovistus / pyd

Interoperability between Python and D
MIT License
157 stars 32 forks source link

Returning Python3 bytes #146

Open carver opened 3 years ago

carver commented 3 years ago

The bytes type isn't listed here: https://pyd.readthedocs.io/en/latest/conversion.html#d-to-python

What D type should I use to return a bytes value?

string isn't an option, because I need to support arbitrary data, which is often not unicode-valid. I also tried using a function signature that returns a char[]. Either way, the code raises UnicodeDecodeError when invoked in python.

For now, my workaround is to return a ubyte[] and then call bytes(returned_val). But that adds an unnecessary copy (and a 20% slowdown) that I'd rather avoid.

ariovistus commented 3 years ago

there doesn't seem to be a good way to return bytes. can't have that.

https://github.com/ariovistus/pyd/pull/147