Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 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 | #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. |
| 17 | * For the concenience of C programmers, the bytes type is considered |
| 18 | * to contain a char pointer, not an unsigned char pointer. |
| 19 | */ |
| 20 | |
| 21 | /* Object layout */ |
| 22 | typedef struct { |
| 23 | PyObject_VAR_HEAD |
Guido van Rossum | a0867f7 | 2006-05-05 04:34:18 +0000 | [diff] [blame^] | 24 | Py_ssize_t ob_alloc; /* How many bytes allocated */ |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 25 | char *ob_bytes; |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 26 | } PyBytesObject; |
| 27 | |
| 28 | /* Type object */ |
| 29 | PyAPI_DATA(PyTypeObject) PyBytes_Type; |
| 30 | |
| 31 | /* Type check macros */ |
| 32 | #define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type) |
| 33 | #define PyBytes_CheckExact(self) ((self)->ob_type == &PyBytes_Type) |
| 34 | |
| 35 | /* Direct API functions */ |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 36 | PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *); |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 37 | PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t); |
| 38 | PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *); |
| 39 | PyAPI_FUNC(char *) PyBytes_AsString(PyObject *); |
| 40 | PyAPI_FUNC(int) PyBytes_Resize(PyObject *, Py_ssize_t); |
| 41 | |
| 42 | /* Macros, trading safety for speed */ |
Guido van Rossum | d624f18 | 2006-04-24 13:47:05 +0000 | [diff] [blame] | 43 | #define PyBytes_AS_STRING(self) (((PyBytesObject *)(self))->ob_bytes) |
Guido van Rossum | 4dfe8a1 | 2006-04-22 23:28:04 +0000 | [diff] [blame] | 44 | #define PyBytes_GET_SIZE(self) (((PyBytesObject *)(self))->ob_size) |
| 45 | |
| 46 | #ifdef __cplusplus |
| 47 | } |
| 48 | #endif |
| 49 | #endif /* !Py_BYTESOBJECT_H */ |