blob: 49d1d3883b4c444c1d0a4856433c49a00f958311 [file] [log] [blame]
Guido van Rossum4dfe8a12006-04-22 23:28:04 +00001/* Bytes object interface */
2
3#ifndef Py_BYTESOBJECT_H
4#define Py_BYTESOBJECT_H
5#ifdef __cplusplus
6extern "C" {
7#endif
8
9#include <stdarg.h>
10
11/* Type PyBytesObject represents a mutable array of bytes.
12 * The Python API is that of a sequence;
13 * the bytes are mapped to ints in [0, 256).
14 * Bytes are not characters; they may be used to encode characters.
15 * The only way to go between bytes and str/unicode is via encoding
16 * and decoding.
Neal Norwitz19784702007-08-25 05:22:02 +000017 * For the convenience of C programmers, the bytes type is considered
Guido van Rossum4dfe8a12006-04-22 23:28:04 +000018 * to contain a char pointer, not an unsigned char pointer.
19 */
20
21/* Object layout */
22typedef struct {
23 PyObject_VAR_HEAD
Neal Norwitzfaa54a32007-08-19 04:23:20 +000024 /* XXX(nnorwitz): should ob_exports be Py_ssize_t? */
Travis E. Oliphantb99f7622007-08-18 11:21:56 +000025 int ob_exports; /* how many buffer exports */
Guido van Rossuma0867f72006-05-05 04:34:18 +000026 Py_ssize_t ob_alloc; /* How many bytes allocated */
Guido van Rossumd624f182006-04-24 13:47:05 +000027 char *ob_bytes;
Guido van Rossum4dfe8a12006-04-22 23:28:04 +000028} PyBytesObject;
29
30/* Type object */
31PyAPI_DATA(PyTypeObject) PyBytes_Type;
Christian Heimesa22e8bd2007-11-29 22:35:39 +000032PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
Guido van Rossum4dfe8a12006-04-22 23:28:04 +000033
34/* Type check macros */
35#define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type)
Christian Heimes90aa7642007-12-19 02:45:37 +000036#define PyBytes_CheckExact(self) (Py_TYPE(self) == &PyBytes_Type)
Guido van Rossum4dfe8a12006-04-22 23:28:04 +000037
38/* Direct API functions */
Guido van Rossumd624f182006-04-24 13:47:05 +000039PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *);
Guido van Rossumad7d8d12007-04-13 01:39:34 +000040PyAPI_FUNC(PyObject *) PyBytes_Concat(PyObject *, PyObject *);
Guido van Rossum4dfe8a12006-04-22 23:28:04 +000041PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
42PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *);
43PyAPI_FUNC(char *) PyBytes_AsString(PyObject *);
44PyAPI_FUNC(int) PyBytes_Resize(PyObject *, Py_ssize_t);
45
46/* Macros, trading safety for speed */
Guido van Rossum2d28f592007-06-14 00:31:21 +000047#define PyBytes_AS_STRING(self) (assert(PyBytes_Check(self)),((PyBytesObject *)(self))->ob_bytes)
Christian Heimes90aa7642007-12-19 02:45:37 +000048#define PyBytes_GET_SIZE(self) (assert(PyBytes_Check(self)),Py_SIZE(self))
Guido van Rossum4dfe8a12006-04-22 23:28:04 +000049
50#ifdef __cplusplus
51}
52#endif
53#endif /* !Py_BYTESOBJECT_H */