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
);
61 #define DEFAULT_BUFFER_SIZE (8 * 1024) /* bytes */
64 /* This is the equivalent of PyException_HEAD in 3.x */
72 PyObject
*filename
; /* Not used, but part of the IOError object */
74 } PyBlockingIOErrorObject
;
75 PyAPI_DATA(PyObject
*) PyExc_BlockingIOError
;
78 * Offset type for positioning.
81 /* Printing a variable of type off_t (with e.g., PyString_FromFormat)
82 correctly and without producing compiler warnings is surprisingly painful.
83 We identify an integer type whose size matches off_t and then: (1) cast the
84 off_t to that integer type and (2) use the appropriate conversion
85 specification. The cast is necessary: gcc complains about formatting a
86 long with "%lld" even when both long and long long have the same
89 #if defined(MS_WIN64) || defined(MS_WINDOWS)
91 /* Windows uses long long for offsets */
92 typedef PY_LONG_LONG Py_off_t
;
93 # define PyLong_AsOff_t PyLong_AsLongLong
94 # define PyLong_FromOff_t PyLong_FromLongLong
95 # define PY_OFF_T_MAX PY_LLONG_MAX
96 # define PY_OFF_T_MIN PY_LLONG_MIN
97 # define PY_OFF_T_COMPAT PY_LONG_LONG /* type compatible with off_t */
98 # define PY_PRIdOFF "lld" /* format to use for that type */
102 /* Other platforms use off_t */
103 typedef off_t Py_off_t
;
104 #if (SIZEOF_OFF_T == SIZEOF_SIZE_T)
105 # define PyLong_AsOff_t PyLong_AsSsize_t
106 # define PyLong_FromOff_t PyLong_FromSsize_t
107 # define PY_OFF_T_MAX PY_SSIZE_T_MAX
108 # define PY_OFF_T_MIN PY_SSIZE_T_MIN
109 # define PY_OFF_T_COMPAT Py_ssize_t
110 # define PY_PRIdOFF "zd"
111 #elif (HAVE_LONG_LONG && SIZEOF_OFF_T == SIZEOF_LONG_LONG)
112 # define PyLong_AsOff_t PyLong_AsLongLong
113 # define PyLong_FromOff_t PyLong_FromLongLong
114 # define PY_OFF_T_MAX PY_LLONG_MAX
115 # define PY_OFF_T_MIN PY_LLONG_MIN
116 # define PY_OFF_T_COMPAT PY_LONG_LONG
117 # define PY_PRIdOFF "lld"
118 #elif (SIZEOF_OFF_T == SIZEOF_LONG)
119 # define PyLong_AsOff_t PyLong_AsLong
120 # define PyLong_FromOff_t PyLong_FromLong
121 # define PY_OFF_T_MAX LONG_MAX
122 # define PY_OFF_T_MIN LONG_MIN
123 # define PY_OFF_T_COMPAT long
124 # define PY_PRIdOFF "ld"
126 # error off_t does not match either size_t, long, or long long!
131 extern Py_off_t
PyNumber_AsOff_t(PyObject
*item
, PyObject
*err
);
133 /* Implementation details */
135 extern PyObject
*_PyIO_os_module
;
136 extern PyObject
*_PyIO_locale_module
;
137 extern PyObject
*_PyIO_unsupported_operation
;
139 extern PyObject
*_PyIO_str_close
;
140 extern PyObject
*_PyIO_str_closed
;
141 extern PyObject
*_PyIO_str_decode
;
142 extern PyObject
*_PyIO_str_encode
;
143 extern PyObject
*_PyIO_str_fileno
;
144 extern PyObject
*_PyIO_str_flush
;
145 extern PyObject
*_PyIO_str_getstate
;
146 extern PyObject
*_PyIO_str_isatty
;
147 extern PyObject
*_PyIO_str_newlines
;
148 extern PyObject
*_PyIO_str_nl
;
149 extern PyObject
*_PyIO_str_read
;
150 extern PyObject
*_PyIO_str_read1
;
151 extern PyObject
*_PyIO_str_readable
;
152 extern PyObject
*_PyIO_str_readinto
;
153 extern PyObject
*_PyIO_str_readline
;
154 extern PyObject
*_PyIO_str_reset
;
155 extern PyObject
*_PyIO_str_seek
;
156 extern PyObject
*_PyIO_str_seekable
;
157 extern PyObject
*_PyIO_str_setstate
;
158 extern PyObject
*_PyIO_str_tell
;
159 extern PyObject
*_PyIO_str_truncate
;
160 extern PyObject
*_PyIO_str_writable
;
161 extern PyObject
*_PyIO_str_write
;
163 extern PyObject
*_PyIO_empty_str
;
164 extern PyObject
*_PyIO_empty_bytes
;
165 extern PyObject
*_PyIO_zero
;