annotate Include/bytesobject.h @ 44351:86a2679dca46

#1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
author Christian Heimes <christian@cheimes.de>
date Wed, 19 Dec 2007 02:45:37 +0000
parents 0cc552ab76bd
children 96b34263e448
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
37927
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /* Bytes object interface */
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 #ifndef Py_BYTESOBJECT_H
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 #define Py_BYTESOBJECT_H
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 #ifdef __cplusplus
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 extern "C" {
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 #endif
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 #include <stdarg.h>
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 /* Type PyBytesObject represents a mutable array of bytes.
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 * The Python API is that of a sequence;
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 * the bytes are mapped to ints in [0, 256).
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 * Bytes are not characters; they may be used to encode characters.
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 * The only way to go between bytes and str/unicode is via encoding
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 * and decoding.
42821
bb288e04b8e5 Fix typo in comment
Neal Norwitz <nnorwitz@gmail.com>
parents: 42669
diff changeset
17 * For the convenience of C programmers, the bytes type is considered
37927
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 * to contain a char pointer, not an unsigned char pointer.
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 */
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 /* Object layout */
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 typedef struct {
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 PyObject_VAR_HEAD
42669
2c51be9904de Code review of the new buffer protocol. Mostly add questions that should
Neal Norwitz <nnorwitz@gmail.com>
parents: 42665
diff changeset
24 /* XXX(nnorwitz): should ob_exports be Py_ssize_t? */
42665
85c22b4d4455 Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents: 42335
diff changeset
25 int ob_exports; /* how many buffer exports */
38115
a6a1359aab84 Optimizations for bytes reallocation.
Guido van Rossum <guido@python.org>
parents: 37960
diff changeset
26 Py_ssize_t ob_alloc; /* How many bytes allocated */
37960
e0b7e34b5971 Added much functionality to the bytes type.
Guido van Rossum <guido@python.org>
parents: 37927
diff changeset
27 char *ob_bytes;
37927
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 } PyBytesObject;
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 /* Type object */
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 PyAPI_DATA(PyTypeObject) PyBytes_Type;
44061
0cc552ab76bd Added all PyTypeObjects to the appropriate header files.
Christian Heimes <christian@cheimes.de>
parents: 42821
diff changeset
32 PyAPI_DATA(PyTypeObject) PyBytesIter_Type;
37927
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 /* Type check macros */
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type)
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44061
diff changeset
36 #define PyBytes_CheckExact(self) (Py_TYPE(self) == &PyBytes_Type)
37927
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 /* Direct API functions */
37960
e0b7e34b5971 Added much functionality to the bytes type.
Guido van Rossum <guido@python.org>
parents: 37927
diff changeset
39 PyAPI_FUNC(PyObject *) PyBytes_FromObject(PyObject *);
41450
d1c3dd184e38 Rough and dirty job -- allow concatenation of bytes and arbitrary
Guido van Rossum <guido@python.org>
parents: 38115
diff changeset
40 PyAPI_FUNC(PyObject *) PyBytes_Concat(PyObject *, PyObject *);
37927
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 PyAPI_FUNC(PyObject *) PyBytes_FromStringAndSize(const char *, Py_ssize_t);
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 PyAPI_FUNC(Py_ssize_t) PyBytes_Size(PyObject *);
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 PyAPI_FUNC(char *) PyBytes_AsString(PyObject *);
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 PyAPI_FUNC(int) PyBytes_Resize(PyObject *, Py_ssize_t);
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
45
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 /* Macros, trading safety for speed */
42091
72fc7d029d3d Add asserts to PyBytes_AS_STRING and PyBytes_GET_SIZE.
Guido van Rossum <guido@python.org>
parents: 41450
diff changeset
47 #define PyBytes_AS_STRING(self) (assert(PyBytes_Check(self)),((PyBytesObject *)(self))->ob_bytes)
44351
86a2679dca46 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT.
Christian Heimes <christian@cheimes.de>
parents: 44061
diff changeset
48 #define PyBytes_GET_SIZE(self) (assert(PyBytes_Check(self)),Py_SIZE(self))
37927
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 #ifdef __cplusplus
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 }
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 #endif
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 #endif /* !Py_BYTESOBJECT_H */