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