blueloveTH 1 anno fa
parent
commit
a9d6242a43
2 ha cambiato i file con 8 aggiunte e 0 eliminazioni
  1. 1 0
      include/pocketpy/pocketpy.h
  2. 7 0
      src/public/cast.c

+ 1 - 0
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);
 

+ 7 - 0
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);