diff --git a/include/pocketpy/pocketpy.h b/include/pocketpy/pocketpy.h index 2a35dc85..f2401dc7 100644 --- a/include/pocketpy/pocketpy.h +++ b/include/pocketpy/pocketpy.h @@ -105,6 +105,7 @@ bool py_tobool(const py_Ref); py_Type py_totype(const py_Ref); const char* py_tostr(const py_Ref); const char* py_tostrn(const py_Ref, int* size); +const unsigned char* py_tobytes(const py_Ref, int* size); void* py_touserdata(const py_Ref); diff --git a/src/public/cast.c b/src/public/cast.c index 97668e46..6634d7d1 100644 --- a/src/public/cast.c +++ b/src/public/cast.c @@ -51,6 +51,13 @@ const char* py_tostrn(const py_Ref self, int* size){ return py_Str__data(ud); } +const unsigned char* py_tobytes(const py_Ref self, int* size){ + assert(self->type == tp_bytes); + int* ud = PyObject__value(self->_obj); + *size = *ud; + return (unsigned char*)(ud + 1); +} + void* py_touserdata(const py_Ref self){ assert(self && self->is_ptr); return PyObject__value(self->_obj);