Message336218
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) || PyByteArray_Check(ob))
#define PyBytesOrByteArray_AS_STRING(ob) (PyBytes_Check(ob) ? PyBytes_AS_STRING(ob) : PyByteArray_AS_STRING(ob))
#define PyBytesOrByteArray_GET_SIZE(ob) #define PyByteArray_GET_SIZE(self) (assert(PyBytesOrByteArray_Check(self)), Py_SIZE(self)) |
|
Date |
User |
Action |
Args |
2019-02-21 14:20:08 | salty-horse | set | recipients:
+ salty-horse |
2019-02-21 14:20:08 | salty-horse | set | messageid: <1550758808.61.0.471799213148.issue36065@roundup.psfhosted.org> |
2019-02-21 14:20:08 | salty-horse | link | issue36065 messages |
2019-02-21 14:20:08 | salty-horse | create | |
|