blob: bc0e45215436ad7fa5d1e45186696ac7d906e4c6 [file] [log] [blame]
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +00001/*
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/* 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.
25 */
Benjamin Peterson680bf1a2009-06-12 02:07:12 +000026extern PyObject* _PyIOBase_check_readable(PyObject *self, PyObject *args);
27extern PyObject* _PyIOBase_check_writable(PyObject *self, PyObject *args);
28extern PyObject* _PyIOBase_check_seekable(PyObject *self, PyObject *args);
29extern PyObject* _PyIOBase_check_closed(PyObject *self, PyObject *args);
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000030
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
34 is alive again. */
35extern int _PyIOBase_finalize(PyObject *self);
36
37/* Returns true if the given FileIO object is closed.
38 Doesn't check the argument type, so be careful! */
39extern int _PyFileIO_closed(PyObject *self);
40
41/* Shortcut to the core of the IncrementalNewlineDecoder.decode method */
42extern PyObject *_PyIncrementalNewlineDecoder_decode(
43 PyObject *self, PyObject *input, int final);
44
45/* Finds the first line ending between `start` and `end`.
46 If found, returns the index after the line ending and doesn't touch
47 `*consumed`.
48 If not found, returns -1 and sets `*consumed` to the number of characters
49 which can be safely put aside until another search.
50
51 NOTE: for performance reasons, `end` must point to a NUL character ('\0').
52 Otherwise, the function will scan further and return garbage. */
53extern 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);
56
57
58#define DEFAULT_BUFFER_SIZE (8 * 1024) /* bytes */
59
60typedef struct {
61 PyException_HEAD
62 PyObject *myerrno;
63 PyObject *strerror;
64 PyObject *filename; /* Not used, but part of the IOError object */
65 Py_ssize_t written;
66} PyBlockingIOErrorObject;
Benjamin Peterson36a30ce2009-03-05 21:41:50 +000067PyAPI_DATA(PyObject *) PyExc_BlockingIOError;
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +000068
69/*
70 * Offset type for positioning.
71 */
72
73#if defined(MS_WIN64) || defined(MS_WINDOWS)
74
75/* Windows uses long long for offsets */
76typedef PY_LONG_LONG Py_off_t;
77# define PyLong_AsOff_t PyLong_AsLongLong
78# define PyLong_FromOff_t PyLong_FromLongLong
79# define PY_OFF_T_MAX PY_LLONG_MAX
80# define PY_OFF_T_MIN PY_LLONG_MIN
81
82#else
83
84/* Other platforms use off_t */
85typedef off_t Py_off_t;
86#if (SIZEOF_OFF_T == SIZEOF_SIZE_T)
87# define PyLong_AsOff_t PyLong_AsSsize_t
88# define PyLong_FromOff_t PyLong_FromSsize_t
89# define PY_OFF_T_MAX PY_SSIZE_T_MAX
90# define PY_OFF_T_MIN PY_SSIZE_T_MIN
91#elif (SIZEOF_OFF_T == SIZEOF_LONG_LONG)
92# define PyLong_AsOff_t PyLong_AsLongLong
93# define PyLong_FromOff_t PyLong_FromLongLong
94# define PY_OFF_T_MAX PY_LLONG_MAX
95# define PY_OFF_T_MIN PY_LLONG_MIN
96#elif (SIZEOF_OFF_T == SIZEOF_LONG)
97# define PyLong_AsOff_t PyLong_AsLong
98# define PyLong_FromOff_t PyLong_FromLong
99# define PY_OFF_T_MAX LONG_MAX
100# define PY_OFF_T_MIN LONG_MIN
101#else
102# error off_t does not match either size_t, long, or long long!
103#endif
104
105#endif
106
107extern Py_off_t PyNumber_AsOff_t(PyObject *item, PyObject *err);
108
109/* Implementation details */
110
111/* IO module structure */
112
113extern PyModuleDef _PyIO_Module;
114
115typedef struct {
116 int initialized;
117 PyObject *os_module;
118 PyObject *locale_module;
119
120 PyObject *unsupported_operation;
121} _PyIO_State;
122
123#define IO_MOD_STATE(mod) ((_PyIO_State *)PyModule_GetState(mod))
124#define IO_STATE IO_MOD_STATE(PyState_FindModule(&_PyIO_Module))
125
126extern PyObject *_PyIO_str_close;
127extern PyObject *_PyIO_str_closed;
128extern PyObject *_PyIO_str_decode;
129extern PyObject *_PyIO_str_encode;
130extern PyObject *_PyIO_str_fileno;
131extern PyObject *_PyIO_str_flush;
132extern PyObject *_PyIO_str_getstate;
133extern PyObject *_PyIO_str_isatty;
134extern PyObject *_PyIO_str_newlines;
135extern PyObject *_PyIO_str_nl;
136extern PyObject *_PyIO_str_read;
137extern PyObject *_PyIO_str_read1;
138extern PyObject *_PyIO_str_readable;
139extern PyObject *_PyIO_str_readinto;
140extern PyObject *_PyIO_str_readline;
141extern PyObject *_PyIO_str_reset;
142extern PyObject *_PyIO_str_seek;
143extern PyObject *_PyIO_str_seekable;
Antoine Pitroue4501852009-05-14 18:55:55 +0000144extern PyObject *_PyIO_str_setstate;
Benjamin Peterson4fa88fa2009-03-04 00:14:51 +0000145extern PyObject *_PyIO_str_tell;
146extern PyObject *_PyIO_str_truncate;
147extern PyObject *_PyIO_str_writable;
148extern PyObject *_PyIO_str_write;
149
150extern PyObject *_PyIO_empty_str;
151extern PyObject *_PyIO_empty_bytes;
Antoine Pitroue4501852009-05-14 18:55:55 +0000152extern PyObject *_PyIO_zero;