annotate Include/bytesobject.h @ 42334:e70cdce0e8b2

Merged revisions 56467-56482 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/p3yk ................ r56477 | martin.v.loewis | 2007-07-21 09:04:38 +0200 (Sa, 21 Jul 2007) | 11 lines Merged revisions 56466-56476 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r56476 | martin.v.loewis | 2007-07-21 08:55:02 +0200 (Sa, 21 Jul 2007) | 4 lines PEP 3123: Provide forward compatibility with Python 3.0, while keeping backwards compatibility. Add Py_Refcnt, Py_Type, Py_Size, and PyVarObject_HEAD_INIT. ........ ................ r56478 | martin.v.loewis | 2007-07-21 09:47:23 +0200 (Sa, 21 Jul 2007) | 2 lines PEP 3123: Use proper C inheritance for PyObject. ................ r56479 | martin.v.loewis | 2007-07-21 10:06:55 +0200 (Sa, 21 Jul 2007) | 3 lines Add longintrepr.h to Python.h, so that the compiler can see that PyFalse is really some kind of PyObject*. ................ r56480 | martin.v.loewis | 2007-07-21 10:47:18 +0200 (Sa, 21 Jul 2007) | 2 lines Qualify SHIFT, MASK, BASE. ................ r56482 | martin.v.loewis | 2007-07-21 19:10:57 +0200 (Sa, 21 Jul 2007) | 2 lines Correctly refer to _ob_next. ................
author Martin v. Löwis <martin@v.loewis.de>
date Sat, 21 Jul 2007 17:22:18 +0000
parents 72fc7d029d3d
children c8b850b5a066
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.
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 * For the concenience of C programmers, the bytes type is considered
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
38115
a6a1359aab84 Optimizations for bytes reallocation.
Guido van Rossum <guido@python.org>
parents: 37960
diff changeset
24 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
25 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
26 } 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
27
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 /* 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
29 PyAPI_DATA(PyTypeObject) PyBytes_Type;
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
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 /* 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
32 #define PyBytes_Check(self) PyObject_TypeCheck(self, &PyBytes_Type)
42334
e70cdce0e8b2 Merged revisions 56467-56482 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents: 42091
diff changeset
33 #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
34
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 /* Direct API functions */
37960
e0b7e34b5971 Added much functionality to the bytes type.
Guido van Rossum <guido@python.org>
parents: 37927
diff changeset
36 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
37 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
38 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
39 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
40 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
41 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
42
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 /* 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
44 #define PyBytes_AS_STRING(self) (assert(PyBytes_Check(self)),((PyBytesObject *)(self))->ob_bytes)
72fc7d029d3d Add asserts to PyBytes_AS_STRING and PyBytes_GET_SIZE.
Guido van Rossum <guido@python.org>
parents: 41450
diff changeset
45 #define PyBytes_GET_SIZE(self) (assert(PyBytes_Check(self)),((PyBytesObject *)(self))->ob_size)
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
46
a7f3765ea464 Here is a bytes type. It's very minimal but it's a start.
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 #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
48 }
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 #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
50 #endif /* !Py_BYTESOBJECT_H */