1 // Bytes object interface 2 3 #ifndef Py_BYTESOBJECT_H 4 #define Py_BYTESOBJECT_H 5 #ifdef __cplusplus 6 extern "C" { 7 #endif 8 9 /* 10 Type PyBytesObject represents a byte string. An extra zero byte is 11 reserved at the end to ensure it is zero-terminated, but a size is 12 present so strings with null bytes in them can be represented. This 13 is an immutable object type. 14 15 There are functions to create new bytes objects, to test 16 an object for bytes-ness, and to get the 17 byte string value. The latter function returns a null pointer 18 if the object is not of the proper type. 19 There is a variant that takes an explicit size as well as a 20 variant that assumes a zero-terminated string. Note that none of the 21 functions should be applied to NULL pointer. 22 */ 23 24 PyAPI_DATA(PyTypeObject) PyBytes_Type; 25 PyAPI_DATA(PyTypeObject) PyBytesIter_Type; 26 27 #define PyBytes_Check(op) \ 28 PyType_FastSubclass(Py_TYPE(op), Py_TPFLAGS_BYTES_SUBCLASS) 29 #define PyBytes_CheckExact(op) Py_IS_TYPE((op), &PyBytes_Type) 30 31 PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); 32 PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *); 33 PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *); 34 PyAPI_FUNC(PyObject *) PyBytes_FromFormatV(const char*, va_list) 35 Py_GCC_ATTRIBUTE((format(printf, 1, 0))); 36 PyAPI_FUNC(PyObject *) PyBytes_FromFormat(const char*, ...) 37 Py_GCC_ATTRIBUTE((format(printf, 1, 2))); 38 PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *); 39 PyAPI_FUNC(char *) PyBytes_AsString(PyObject *); 40 PyAPI_FUNC(PyObject *) PyBytes_Repr(PyObject *, int); 41 PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *); 42 PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *); 43 PyAPI_FUNC(PyObject *) PyBytes_DecodeEscape(const char *, Py_ssize_t, 44 const char *, Py_ssize_t, 45 const char *); 46 47 /* Provides access to the internal data buffer and size of a bytes object. 48 Passing NULL as len parameter will force the string buffer to be 49 0-terminated (passing a string with embedded NUL characters will 50 cause an exception). */ 51 PyAPI_FUNC(int) PyBytes_AsStringAndSize( 52 PyObject *obj, /* bytes object */ 53 char **s, /* pointer to buffer variable */ 54 Py_ssize_t *len /* pointer to length variable or NULL */ 55 ); 56 57 #ifndef Py_LIMITED_API 58 # define Py_CPYTHON_BYTESOBJECT_H 59 # include "cpython/bytesobject.h" 60 # undef Py_CPYTHON_BYTESOBJECT_H 61 #endif 62 63 #ifdef __cplusplus 64 } 65 #endif 66 #endif /* !Py_BYTESOBJECT_H */ 67