It would be useful to have a shared API for consuming bytes and bytearrays. At present, I need to write very similar code twice. Some existing codebases only support bytes (perhaps forgetting bytearrays exist). Adding support for bytearray would be trivial if there was a shared API. These are the functions/macros that can have "BytesOrByteArray" equivalents: * PyBytes_Check * PyBytes_CheckExact * PyBytes_Size * PyBytes_GET_SIZE * PyBytes_AsString * PyBytes_AS_STRING * PyBytes_AsStringAndSize Here are some example implementations for the macros: #define PyBytesOrByteArray_Check(ob) (PyBytes_Check(ob) |
If you need to support only bytes and bytearray, but not other bytes-like object, this is a too special case. It is easy to write your own macros or functions that wrap existing C API. Other option -- duplicate the code and replace PyBytes_ with PyByteArray_. In all cases be aware abot differences between bytes and bytearray: bytarray can change its content and size, saved values of PyByteArray_AS_STRING(ob) and PyByteArray_GET_SIZE(self) can not be used after executing arbitrary code in destructors or releasing GIT.
History
Date
User
Action
Args
2022-04-11 14:59:11
admin
set
github: 80246
2019-02-21 16:01:51
serhiy.storchaka
set
status: open -> closedresolution: rejectedmessages: + stage: resolved