1 /** 2 * Mirror _bytearrayobject.h 3 * 4 * Type PyByteArrayObject represents a mutable array of bytes. 5 * The Python API is that of a sequence; 6 * the bytes are mapped to ints in [0, 256). 7 * Bytes are not characters; they may be used to encode characters. 8 * The only way to go between bytes and str/unicode is via encoding 9 * and decoding. 10 * For the convenience of C programmers, the bytes type is considered 11 * to contain a char pointer, not an unsigned char pointer. 12 */ 13 module deimos.python.bytearrayobject; 14 15 import deimos.python.pyport; 16 import deimos.python.object; 17 18 extern(C): 19 // Python-header-file: Include/bytearrayobject.h: 20 21 version(Python_2_6_Or_Later) { 22 /// subclass of PyVarObject 23 /// Availability: >= 2.6 24 struct PyByteArrayObject { 25 mixin PyObject_VAR_HEAD!(); 26 /** how many buffer exports */ 27 int ob_exports; 28 /** How many bytes allocated */ 29 Py_ssize_t ob_alloc; 30 /// _ 31 char* ob_bytes; 32 } 33 34 /* Type object */ 35 /// Availability: >= 2.6 36 mixin(PyAPI_DATA!"PyTypeObject PyByteArray_Type"); 37 /// Availability: >= 2.6 38 mixin(PyAPI_DATA!"PyTypeObject PyByteArrayIter_Type"); 39 40 /** Type check macro 41 Availability: >= 2.6 42 */ 43 int PyByteArray_Check()(PyObject* self) { 44 return PyObject_TypeCheck(self, &PyByteArray_Type); 45 } 46 47 /** Type check macro 48 Availability: >= 2.6 49 */ 50 int PyByteArray_CheckExact()(PyObject* self) { 51 return Py_TYPE(self) == &PyByteArray_Type; 52 } 53 54 /* Direct API functions */ 55 /// Availability: >= 2.6 56 PyObject* PyByteArray_FromObject(PyObject*); 57 /// Availability: >= 2.6 58 PyObject* PyByteArray_Concat(PyObject*, PyObject*); 59 /// Availability: >= 2.6 60 PyObject* PyByteArray_FromStringAndSize(const char*, Py_ssize_t); 61 /// Availability: >= 2.6 62 Py_ssize_t PyByteArray_Size(PyObject*); 63 /// Availability: >= 2.6 64 char* PyByteArray_AsString(PyObject*); 65 /// Availability: >= 2.6 66 int PyByteArray_Resize(PyObject*, Py_ssize_t); 67 /// template trading safety for speed 68 /// Availability: >= 2.6 69 char* PyByteArray_AS_STRING()(PyObject* self) { 70 assert(PyByteArray_Check(self)); 71 if(Py_SIZE(self)) { 72 return (cast(PyByteArrayObject*) self).ob_bytes; 73 }else{ 74 return "\0".ptr; 75 } 76 } 77 /// template trading safety for speed 78 /// Availability: >= 2.6 79 auto PyByteArray_GET_SIZE()(PyObject* self) { 80 assert(PyByteArray_Check(self)); 81 return Py_SIZE(cast(PyVarObject*) self); 82 } 83 }