Hi,
I have a C module with a function that handles bytes. I would like it to also transparently handle bytearrays. I can use mp_obj_is_str_or_bytes to determine if an mp_obj_t is of type "bytes", but this does not work if I pass a bytearray value to the function.
How do I find out if an mp_obj_t is of type "bytearray", and how do I get its contents?
Thank you,
Frank
Treating bytearray the same as bytes in C modules
Re: Treating bytearray the same as bytes in C modules
Answering my own question, I guess I can use mp_get_buffer() regardless of whether the mp_obj_t is a string, bytes or bytearray object, right? I still won't know how to test whether an mp_obj_t is a bytearray, but I probably should not care.
Re: Treating bytearray the same as bytes in C modules
Yep, that's exactly right. Just ensure that you only set flags=MP_BUFFER_READ so you support read-only buffers too.