source: python/trunk/Modules/_io/_iomodule.h

Last change on this file was 391, checked in by dmik, 11 years ago

python: Merge vendor 2.7.6 to trunk.

  • Property svn:eol-style set to native
File size: 5.9 KB
Line 
1/*
2 * Declarations shared between the different parts of the io module
3 */
4
5/* ABCs */
6extern PyTypeObject PyIOBase_Type;
7extern PyTypeObject PyRawIOBase_Type;
8extern PyTypeObject PyBufferedIOBase_Type;
9extern PyTypeObject PyTextIOBase_Type;
10
11/* Concrete classes */
12extern PyTypeObject PyFileIO_Type;
13extern PyTypeObject PyBytesIO_Type;
14extern PyTypeObject PyStringIO_Type;
15extern PyTypeObject PyBufferedReader_Type;
16extern PyTypeObject PyBufferedWriter_Type;
17extern PyTypeObject PyBufferedRWPair_Type;
18extern PyTypeObject PyBufferedRandom_Type;
19extern PyTypeObject PyTextIOWrapper_Type;
20extern PyTypeObject PyIncrementalNewlineDecoder_Type;
21
22
23extern int _PyIO_ConvertSsize_t(PyObject *, void *);
24
25/* These functions are used as METH_NOARGS methods, are normally called
26 * with args=NULL, and return a new reference.
27 * BUT when args=Py_True is passed, they return a borrowed reference.
28 */
29extern PyObject* _PyIOBase_check_readable(PyObject *self, PyObject *args);
30extern PyObject* _PyIOBase_check_writable(PyObject *self, PyObject *args);
31extern PyObject* _PyIOBase_check_seekable(PyObject *self, PyObject *args);
32extern PyObject* _PyIOBase_check_closed(PyObject *self, PyObject *args);
33
34/* Helper for finalization.
35 This function will revive an object ready to be deallocated and try to
36 close() it. It returns 0 if the object can be destroyed, or -1 if it
37 is alive again. */
38extern int _PyIOBase_finalize(PyObject *self);
39
40/* Returns true if the given FileIO object is closed.
41 Doesn't check the argument type, so be careful! */
42extern int _PyFileIO_closed(PyObject *self);
43
44/* Shortcut to the core of the IncrementalNewlineDecoder.decode method */
45extern PyObject *_PyIncrementalNewlineDecoder_decode(
46 PyObject *self, PyObject *input, int final);
47
48/* Finds the first line ending between `start` and `end`.
49 If found, returns the index after the line ending and doesn't touch
50 `*consumed`.
51 If not found, returns -1 and sets `*consumed` to the number of characters
52 which can be safely put aside until another search.
53
54 NOTE: for performance reasons, `end` must point to a NUL character ('\0').
55 Otherwise, the function will scan further and return garbage. */
56extern Py_ssize_t _PyIO_find_line_ending(
57 int translated, int universal, PyObject *readnl,
58 Py_UNICODE *start, Py_UNICODE *end, Py_ssize_t *consumed);
59
60/* Return 1 if an EnvironmentError with errno == EINTR is set (and then
61 clears the error indicator), 0 otherwise.
62 Should only be called when PyErr_Occurred() is true.
63*/
64extern int _PyIO_trap_eintr(void);
65
66#define DEFAULT_BUFFER_SIZE (8 * 1024) /* bytes */
67
68typedef struct {
69 /* This is the equivalent of PyException_HEAD in 3.x */
70 PyObject_HEAD
71 PyObject *dict;
72 PyObject *args;
73 PyObject *message;
74
75 PyObject *myerrno;
76 PyObject *strerror;
77 PyObject *filename; /* Not used, but part of the IOError object */
78 Py_ssize_t written;
79} PyBlockingIOErrorObject;
80extern PyObject *PyExc_BlockingIOError;
81
82/*
83 * Offset type for positioning.
84 */
85
86/* Printing a variable of type off_t (with e.g., PyString_FromFormat)
87 correctly and without producing compiler warnings is surprisingly painful.
88 We identify an integer type whose size matches off_t and then: (1) cast the
89 off_t to that integer type and (2) use the appropriate conversion
90 specification. The cast is necessary: gcc complains about formatting a
91 long with "%lld" even when both long and long long have the same
92 precision. */
93
94#if defined(MS_WIN64) || defined(MS_WINDOWS)
95
96/* Windows uses long long for offsets */
97typedef PY_LONG_LONG Py_off_t;
98# define PyLong_AsOff_t PyLong_AsLongLong
99# define PyLong_FromOff_t PyLong_FromLongLong
100# define PY_OFF_T_MAX PY_LLONG_MAX
101# define PY_OFF_T_MIN PY_LLONG_MIN
102# define PY_OFF_T_COMPAT PY_LONG_LONG /* type compatible with off_t */
103# define PY_PRIdOFF "lld" /* format to use for that type */
104
105#else
106
107/* Other platforms use off_t */
108typedef off_t Py_off_t;
109#if (SIZEOF_OFF_T == SIZEOF_SIZE_T)
110# define PyLong_AsOff_t PyLong_AsSsize_t
111# define PyLong_FromOff_t PyLong_FromSsize_t
112# define PY_OFF_T_MAX PY_SSIZE_T_MAX
113# define PY_OFF_T_MIN PY_SSIZE_T_MIN
114# define PY_OFF_T_COMPAT Py_ssize_t
115# define PY_PRIdOFF "zd"
116#elif (HAVE_LONG_LONG && SIZEOF_OFF_T == SIZEOF_LONG_LONG)
117# define PyLong_AsOff_t PyLong_AsLongLong
118# define PyLong_FromOff_t PyLong_FromLongLong
119# define PY_OFF_T_MAX PY_LLONG_MAX
120# define PY_OFF_T_MIN PY_LLONG_MIN
121# define PY_OFF_T_COMPAT PY_LONG_LONG
122# define PY_PRIdOFF "lld"
123#elif (SIZEOF_OFF_T == SIZEOF_LONG)
124# define PyLong_AsOff_t PyLong_AsLong
125# define PyLong_FromOff_t PyLong_FromLong
126# define PY_OFF_T_MAX LONG_MAX
127# define PY_OFF_T_MIN LONG_MIN
128# define PY_OFF_T_COMPAT long
129# define PY_PRIdOFF "ld"
130#else
131# error off_t does not match either size_t, long, or long long!
132#endif
133
134#endif
135
136extern Py_off_t PyNumber_AsOff_t(PyObject *item, PyObject *err);
137
138/* Implementation details */
139
140extern PyObject *_PyIO_os_module;
141extern PyObject *_PyIO_locale_module;
142extern PyObject *_PyIO_unsupported_operation;
143
144extern PyObject *_PyIO_str_close;
145extern PyObject *_PyIO_str_closed;
146extern PyObject *_PyIO_str_decode;
147extern PyObject *_PyIO_str_encode;
148extern PyObject *_PyIO_str_fileno;
149extern PyObject *_PyIO_str_flush;
150extern PyObject *_PyIO_str_getstate;
151extern PyObject *_PyIO_str_isatty;
152extern PyObject *_PyIO_str_newlines;
153extern PyObject *_PyIO_str_nl;
154extern PyObject *_PyIO_str_read;
155extern PyObject *_PyIO_str_read1;
156extern PyObject *_PyIO_str_readable;
157extern PyObject *_PyIO_str_readinto;
158extern PyObject *_PyIO_str_readline;
159extern PyObject *_PyIO_str_reset;
160extern PyObject *_PyIO_str_seek;
161extern PyObject *_PyIO_str_seekable;
162extern PyObject *_PyIO_str_setstate;
163extern PyObject *_PyIO_str_tell;
164extern PyObject *_PyIO_str_truncate;
165extern PyObject *_PyIO_str_writable;
166extern PyObject *_PyIO_str_write;
167
168extern PyObject *_PyIO_empty_str;
169extern PyObject *_PyIO_empty_bytes;
170extern PyObject *_PyIO_zero;
Note: See TracBrowser for help on using the repository browser.