1 | |
2 | /* Bytes object interface */ |
3 | |
4 | #ifndef Py_BYTESOBJECT_H |
5 | #define Py_BYTESOBJECT_H |
6 | #ifdef __cplusplus |
7 | extern "C" { |
8 | #endif |
9 | |
10 | #include <stdarg.h> |
11 | |
12 | /* |
13 | Type PyBytesObject represents a byte string. An extra zero byte is |
14 | reserved at the end to ensure it is zero-terminated, but a size is |
15 | present so strings with null bytes in them can be represented. This |
16 | is an immutable object type. |
17 | |
18 | There are functions to create new bytes objects, to test |
19 | an object for bytes-ness, and to get the |
20 | byte string value. The latter function returns a null pointer |
21 | if the object is not of the proper type. |
22 | There is a variant that takes an explicit size as well as a |
23 | variant that assumes a zero-terminated string. Note that none of the |
24 | functions should be applied to NULL pointer. |
25 | */ |
26 | |
27 | PyAPI_DATA(PyTypeObject) PyBytes_Type; |
28 | PyAPI_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 | |
34 | PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); |
35 | PyAPI_FUNC(PyObject *) PyBytes_FromString(const char *); |
36 | PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *); |
37 | PyAPI_FUNC(PyObject *) PyBytes_FromFormatV(const char*, va_list) |
38 | Py_GCC_ATTRIBUTE((format(printf, 1, 0))); |
39 | PyAPI_FUNC(PyObject *) PyBytes_FromFormat(const char*, ...) |
40 | Py_GCC_ATTRIBUTE((format(printf, 1, 2))); |
41 | PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *); |
42 | PyAPI_FUNC(char *) PyBytes_AsString(PyObject *); |
43 | PyAPI_FUNC(PyObject *) PyBytes_Repr(PyObject *, int); |
44 | PyAPI_FUNC(void) PyBytes_Concat(PyObject **, PyObject *); |
45 | PyAPI_FUNC(void) PyBytes_ConcatAndDel(PyObject **, PyObject *); |
46 | PyAPI_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). */ |
54 | PyAPI_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 | |