This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author salty-horse
Recipients salty-horse
Date 2019-02-21.14:20:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1550758808.61.0.471799213148.issue36065@roundup.psfhosted.org>
In-reply-to
Content
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))
History
Date User Action Args
2019-02-21 14:20:08salty-horsesetrecipients: + salty-horse
2019-02-21 14:20:08salty-horsesetmessageid: <1550758808.61.0.471799213148.issue36065@roundup.psfhosted.org>
2019-02-21 14:20:08salty-horselinkissue36065 messages
2019-02-21 14:20:08salty-horsecreate