2 * Declarations shared between the different parts of the io module
6 extern PyTypeObject PyIOBase_Type
;
7 extern PyTypeObject PyRawIOBase_Type
;
8 extern PyTypeObject PyBufferedIOBase_Type
;
9 extern PyTypeObject PyTextIOBase_Type
;
11 /* Concrete classes */
12 extern PyTypeObject PyFileIO_Type
;
13 extern PyTypeObject PyBytesIO_Type
;
14 extern PyTypeObject PyStringIO_Type
;
15 extern PyTypeObject PyBufferedReader_Type
;
16 extern PyTypeObject PyBufferedWriter_Type
;
17 extern PyTypeObject PyBufferedRWPair_Type
;
18 extern PyTypeObject PyBufferedRandom_Type
;
19 extern PyTypeObject PyTextIOWrapper_Type
;
20 extern PyTypeObject PyIncrementalNewlineDecoder_Type
;
23 extern int _PyIO_ConvertSsize_t(PyObject
*, void *);
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.
29 extern PyObject
* _PyIOBase_check_readable(PyObject
*self
, PyObject
*args
);
30 extern PyObject
* _PyIOBase_check_writable(PyObject
*self
, PyObject
*args
);
31 extern PyObject
* _PyIOBase_check_seekable(PyObject
*self
, PyObject
*args
);
32 extern PyObject
* _PyIOBase_check_closed(PyObject
*self
, PyObject
*args
);
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
38 extern int _PyIOBase_finalize(PyObject
*self
);
40 /* Returns true if the given FileIO object is closed.
41 Doesn't check the argument type, so be careful! */
42 extern int _PyFileIO_closed(PyObject
*self
);
44 /* Shortcut to the core of the IncrementalNewlineDecoder.decode method */
45 extern PyObject
*_PyIncrementalNewlineDecoder_decode(
46 PyObject
*self
, PyObject
*input
, int final
);
48 /* Finds the first line ending between `start` and `end`.
49 If found, returns the index after the line ending and doesn't touch
51 If not found, returns -1 and sets `*consumed` to the number of characters
52 which can be safely put aside until another search.
54 NOTE: for performance reasons, `end` must point to a NUL character ('\0').
55 Otherwise, the function will scan further and return garbage. */
56 extern 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
);
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.
64 extern int _PyIO_trap_eintr(void);
66 #define DEFAULT_BUFFER_SIZE (8 * 1024) /* bytes */
69 /* This is the equivalent of PyException_HEAD in 3.x */
77 PyObject
*filename
; /* Not used, but part of the IOError object */
79 } PyBlockingIOErrorObject
;
80 extern PyObject
*PyExc_BlockingIOError
;
83 * Offset type for positioning.
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
94 #if defined(MS_WIN64) || defined(MS_WINDOWS)
96 /* Windows uses long long for offsets */
97 typedef 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 */
107 /* Other platforms use off_t */
108 typedef 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"
131 # error off_t does not match either size_t, long, or long long!
136 extern Py_off_t
PyNumber_AsOff_t(PyObject
*item
, PyObject
*err
);
138 /* Implementation details */
140 extern PyObject
*_PyIO_os_module
;
141 extern PyObject
*_PyIO_locale_module
;
142 extern PyObject
*_PyIO_unsupported_operation
;
144 extern PyObject
*_PyIO_str_close
;
145 extern PyObject
*_PyIO_str_closed
;
146 extern PyObject
*_PyIO_str_decode
;
147 extern PyObject
*_PyIO_str_encode
;
148 extern PyObject
*_PyIO_str_fileno
;
149 extern PyObject
*_PyIO_str_flush
;
150 extern PyObject
*_PyIO_str_getstate
;
151 extern PyObject
*_PyIO_str_isatty
;
152 extern PyObject
*_PyIO_str_newlines
;
153 extern PyObject
*_PyIO_str_nl
;
154 extern PyObject
*_PyIO_str_read
;
155 extern PyObject
*_PyIO_str_read1
;
156 extern PyObject
*_PyIO_str_readable
;
157 extern PyObject
*_PyIO_str_readinto
;
158 extern PyObject
*_PyIO_str_readline
;
159 extern PyObject
*_PyIO_str_reset
;
160 extern PyObject
*_PyIO_str_seek
;
161 extern PyObject
*_PyIO_str_seekable
;
162 extern PyObject
*_PyIO_str_setstate
;
163 extern PyObject
*_PyIO_str_tell
;
164 extern PyObject
*_PyIO_str_truncate
;
165 extern PyObject
*_PyIO_str_writable
;
166 extern PyObject
*_PyIO_str_write
;
168 extern PyObject
*_PyIO_empty_str
;
169 extern PyObject
*_PyIO_empty_bytes
;
170 extern PyObject
*_PyIO_zero
;