1 #ifndef Py_CPYTHON_BYTESOBJECT_H 2 # error "this header file must not be included directly" 3 #endif 4 5 typedef struct { 6 PyObject_VAR_HEAD 7 Py_DEPRECATED(3.11) Py_hash_t ob_shash; 8 char ob_sval[1]; 9 10 /* Invariants: 11 * ob_sval contains space for 'ob_size+1' elements. 12 * ob_sval[ob_size] == 0. 13 * ob_shash is the hash of the byte string or -1 if not computed yet. 14 */ 15 } PyBytesObject; 16 17 PyAPI_FUNC(int) _PyBytes_Resize(PyObject **, Py_ssize_t); 18 19 /* Macros and static inline functions, trading safety for speed */ 20 #define _PyBytes_CAST(op) \ 21 (assert(PyBytes_Check(op)), _Py_CAST(PyBytesObject*, op)) 22 PyBytes_AS_STRING(PyObject * op)23static inline char* PyBytes_AS_STRING(PyObject *op) 24 { 25 return _PyBytes_CAST(op)->ob_sval; 26 } 27 #define PyBytes_AS_STRING(op) PyBytes_AS_STRING(_PyObject_CAST(op)) 28 PyBytes_GET_SIZE(PyObject * op)29static inline Py_ssize_t PyBytes_GET_SIZE(PyObject *op) { 30 PyBytesObject *self = _PyBytes_CAST(op); 31 return Py_SIZE(self); 32 } 33 #define PyBytes_GET_SIZE(self) PyBytes_GET_SIZE(_PyObject_CAST(self)) 34 35 /* _PyBytes_Join(sep, x) is like sep.join(x). sep must be PyBytesObject*, 36 x must be an iterable object. */ 37 PyAPI_FUNC(PyObject*) _PyBytes_Join(PyObject *sep, PyObject *x); 38