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
;
22 /* These functions are used as METH_NOARGS methods, are normally called
23 * with args=NULL, and return a new reference.
24 * BUT when args=Py_True is passed, they return a borrowed reference.
26 extern PyObject
* _PyIOBase_check_readable(PyObject
*self
, PyObject
*args
);
27 extern PyObject
* _PyIOBase_check_writable(PyObject
*self
, PyObject
*args
);
28 extern PyObject
* _PyIOBase_check_seekable(PyObject
*self
, PyObject
*args
);
29 extern PyObject
* _PyIOBase_check_closed(PyObject
*self
, PyObject
*args
);
31 /* Helper for finalization.
32 This function will revive an object ready to be deallocated and try to
33 close() it. It returns 0 if the object can be destroyed, or -1 if it
35 extern int _PyIOBase_finalize(PyObject
*self
);
37 /* Returns true if the given FileIO object is closed.
38 Doesn't check the argument type, so be careful! */
39 extern int _PyFileIO_closed(PyObject
*self
);
41 /* Shortcut to the core of the IncrementalNewlineDecoder.decode method */
42 extern PyObject
*_PyIncrementalNewlineDecoder_decode(
43 PyObject
*self
, PyObject
*input
, int final
);
45 /* Finds the first line ending between `start` and `end`.
46 If found, returns the index after the line ending and doesn't touch
48 If not found, returns -1 and sets `*consumed` to the number of characters
49 which can be safely put aside until another search.
51 NOTE: for performance reasons, `end` must point to a NUL character ('\0').
52 Otherwise, the function will scan further and return garbage. */
53 extern Py_ssize_t
_PyIO_find_line_ending(
54 int translated
, int universal
, PyObject
*readnl
,
55 Py_UNICODE
*start
, Py_UNICODE
*end
, Py_ssize_t
*consumed
);
58 #define DEFAULT_BUFFER_SIZE (8 * 1024) /* bytes */
61 /* This is the equivalent of PyException_HEAD in 3.x */
69 PyObject
*filename
; /* Not used, but part of the IOError object */
71 } PyBlockingIOErrorObject
;
72 PyAPI_DATA(PyObject
*) PyExc_BlockingIOError
;
75 * Offset type for positioning.
78 /* Printing a variable of type off_t correctly and without producing
79 compiler warnings is surprisingly painful. We identify an integer
80 type whose size matches off_t and then: (1) cast the off_t to that
81 integer type and (2) use the appropriate conversion specification
82 for printf. The cast is necessary: gcc complains about formatting
83 a long with "%lld" even when both long and long long have the same
86 #if defined(MS_WIN64) || defined(MS_WINDOWS)
88 /* Windows uses long long for offsets */
89 typedef PY_LONG_LONG Py_off_t
;
90 # define PyLong_AsOff_t PyLong_AsLongLong
91 # define PyLong_FromOff_t PyLong_FromLongLong
92 # define PY_OFF_T_MAX PY_LLONG_MAX
93 # define PY_OFF_T_MIN PY_LLONG_MIN
94 # define PY_PRIdOFF "lld" /* format to use in printf with type off_t */
95 # define PY_OFF_T_COMPAT PY_LONG_LONG /* type compatible with off_t */
98 /* Other platforms use off_t */
99 typedef off_t Py_off_t
;
100 #if (HAVE_LONG_LONG && SIZEOF_OFF_T == SIZEOF_LONG_LONG)
101 # define PyLong_AsOff_t PyLong_AsLongLong
102 # define PyLong_FromOff_t PyLong_FromLongLong
103 # define PY_OFF_T_MAX PY_LLONG_MAX
104 # define PY_OFF_T_MIN PY_LLONG_MIN
105 # define PY_PRIdOFF "lld"
106 # define PY_OFF_T_COMPAT PY_LONG_LONG
107 #elif (SIZEOF_OFF_T == SIZEOF_LONG)
108 # define PyLong_AsOff_t PyLong_AsLong
109 # define PyLong_FromOff_t PyLong_FromLong
110 # define PY_OFF_T_MAX LONG_MAX
111 # define PY_OFF_T_MIN LONG_MIN
112 # define PY_PRIdOFF "ld"
113 # define PY_OFF_T_COMPAT long
114 #elif (SIZEOF_OFF_T == SIZEOF_SIZE_T)
115 # define PyLong_AsOff_t PyLong_AsSsize_t
116 # define PyLong_FromOff_t PyLong_FromSsize_t
117 # define PY_OFF_T_MAX PY_SSIZE_T_MAX
118 # define PY_OFF_T_MIN PY_SSIZE_T_MIN
119 # define PY_PRIdOFF "zd"
120 # define PY_OFF_T_COMPAT Py_ssize_t
122 # error off_t does not match either size_t, long, or long long!
127 extern Py_off_t
PyNumber_AsOff_t(PyObject
*item
, PyObject
*err
);
129 /* Implementation details */
131 extern PyObject
*_PyIO_os_module
;
132 extern PyObject
*_PyIO_locale_module
;
133 extern PyObject
*_PyIO_unsupported_operation
;
135 extern PyObject
*_PyIO_str_close
;
136 extern PyObject
*_PyIO_str_closed
;
137 extern PyObject
*_PyIO_str_decode
;
138 extern PyObject
*_PyIO_str_encode
;
139 extern PyObject
*_PyIO_str_fileno
;
140 extern PyObject
*_PyIO_str_flush
;
141 extern PyObject
*_PyIO_str_getstate
;
142 extern PyObject
*_PyIO_str_isatty
;
143 extern PyObject
*_PyIO_str_newlines
;
144 extern PyObject
*_PyIO_str_nl
;
145 extern PyObject
*_PyIO_str_read
;
146 extern PyObject
*_PyIO_str_read1
;
147 extern PyObject
*_PyIO_str_readable
;
148 extern PyObject
*_PyIO_str_readinto
;
149 extern PyObject
*_PyIO_str_readline
;
150 extern PyObject
*_PyIO_str_reset
;
151 extern PyObject
*_PyIO_str_seek
;
152 extern PyObject
*_PyIO_str_seekable
;
153 extern PyObject
*_PyIO_str_setstate
;
154 extern PyObject
*_PyIO_str_tell
;
155 extern PyObject
*_PyIO_str_truncate
;
156 extern PyObject
*_PyIO_str_writable
;
157 extern PyObject
*_PyIO_str_write
;
159 extern PyObject
*_PyIO_empty_str
;
160 extern PyObject
*_PyIO_empty_bytes
;
161 extern PyObject
*_PyIO_zero
;