On 2020-06-22 02:30, doodspav@gmail.com wrote:
Can we make
PyLong_AsByteArray(PyLongObject* v, unsigned char* bytes, size_t n, int little_endian, int is_signed);
andPyObject * PyLong_FromByteArray(const unsigned char* bytes, size_t n, int little_endian, int is_signed);
available as publicly documented functions?They're already available internally, as can be seen here (https://github.com/python/cpython/blob/578c3955e0222ec7b3146197467fbb0fcfae1...) so all that would be required (I think) would be exporting the symbols and updating the documentation (https://docs.python.org/3/c-api/long.html).
The benefits would be that we could use this when we want to use fixed width integer types without having to check the width of fundamental integer types (so we could use
int32_t
rather than checkingsizeof(int)
or the corresponding macro). This would also be useful if someone wanted to use compiler extension fixed width types such as__int128_t
(and the corresponding unsigned version).
I don't see a good way to do this with the current API, except calling the Python methods, and any implementation of Python will need this functionality to implement said methods. So, I don't see a reason against adding them.
Do you want to do the change? (See: https://devguide.python.org/pullrequest/)