annotate Include/fileobject.h @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 31b18a0242ca
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
145
853b736a6a9e Added copyright notice.
Guido van Rossum <guido@python.org>
parents: 6
diff changeset
1
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 /* File object interface */
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
4 #ifndef Py_FILEOBJECT_H
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
5 #define Py_FILEOBJECT_H
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
6 #ifdef __cplusplus
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
7 extern "C" {
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
8 #endif
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
9
22312
19d1d35020bd Patch #530105: Allow file object may to be subtyped
Martin v. Löwis <martin@v.loewis.de>
parents: 21095
diff changeset
10 typedef struct {
61465
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
11 PyObject_HEAD
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
12 FILE *f_fp;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
13 PyObject *f_name;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
14 PyObject *f_mode;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
15 int (*f_close)(FILE *);
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
16 int f_softspace; /* Flag used by 'print' command */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
17 int f_binary; /* Flag which indicates whether the file is
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
18 open in binary (1) or text (0) mode */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
19 char* f_buf; /* Allocated readahead buffer */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
20 char* f_bufend; /* Points after last occupied position */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
21 char* f_bufptr; /* Current buffer position */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
22 char *f_setbuf; /* Buffer for setbuf(3) and setvbuf(3) */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
23 int f_univ_newline; /* Handle any newline convention */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
24 int f_newlinetypes; /* Types of newlines seen */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
25 int f_skipnextlf; /* Skip next \n */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
26 PyObject *f_encoding;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
27 PyObject *f_errors;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
28 PyObject *weakreflist; /* List of weak references */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
29 int unlocked_count; /* Num. currently running sections of code
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
30 using f_fp with the GIL released. */
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
31 int readable;
e38335d4df91 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 58714
diff changeset
32 int writable;
22312
19d1d35020bd Patch #530105: Allow file object may to be subtyped
Martin v. Löwis <martin@v.loewis.de>
parents: 21095
diff changeset
33 } PyFileObject;
19d1d35020bd Patch #530105: Allow file object may to be subtyped
Martin v. Löwis <martin@v.loewis.de>
parents: 21095
diff changeset
34
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
35 PyAPI_DATA(PyTypeObject) PyFile_Type;
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
19894
51cc82605d32 SF bug [#460467] file objects should be subclassable.
Tim Peters <tim.peters@gmail.com>
parents: 17822
diff changeset
37 #define PyFile_Check(op) PyObject_TypeCheck(op, &PyFile_Type)
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 42333
diff changeset
38 #define PyFile_CheckExact(op) (Py_TYPE(op) == &PyFile_Type)
6
fc6fcd7df4f7 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
40 PyAPI_FUNC(PyObject *) PyFile_FromString(char *, char *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
41 PyAPI_FUNC(void) PyFile_SetBufSize(PyObject *, int);
29065
bf1634b023d5 Patch #612627: Add encoding attribute to file objects, and determine
Martin v. Löwis <martin@v.loewis.de>
parents: 24752
diff changeset
42 PyAPI_FUNC(int) PyFile_SetEncoding(PyObject *, const char *);
47413
1062b7dec95b New environment variable PYTHONIOENCODING.
Martin v. Löwis <martin@v.loewis.de>
parents: 46329
diff changeset
43 PyAPI_FUNC(int) PyFile_SetEncodingAndErrors(PyObject *, const char *, char *errors);
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
44 PyAPI_FUNC(PyObject *) PyFile_FromFile(FILE *, char *, char *,
13444
5709ddba423c ANSI-fication and Py_PROTO extermination.
Fred Drake <fdrake@acm.org>
parents: 13256
diff changeset
45 int (*)(FILE *));
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
46 PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
46329
86da9298b908 Make file objects as thread safe as the underlying libc FILE* implementation.
Gregory P. Smith <greg@mad-scientist.com>
parents: 44350
diff changeset
47 PyAPI_FUNC(void) PyFile_IncUseCount(PyFileObject *);
86da9298b908 Make file objects as thread safe as the underlying libc FILE* implementation.
Gregory P. Smith <greg@mad-scientist.com>
parents: 44350
diff changeset
48 PyAPI_FUNC(void) PyFile_DecUseCount(PyFileObject *);
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
49 PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
50 PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
51 PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
52 PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
53 PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
54 PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
55
17822
50376d470648 Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
56 /* The default encoding used by the platform file system APIs
23201
c408e8b2675a Py_UniversalNewlineFread(): Many changes.
Tim Peters <tim.peters@gmail.com>
parents: 23029
diff changeset
57 If non-NULL, this is different than the default encoding for strings
17822
50376d470648 Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
58 */
24752
c1eb668525e1 Excise DL_EXPORT from Include.
Mark Hammond <mhammond@skippinet.com.au>
parents: 24594
diff changeset
59 PyAPI_DATA(const char *) Py_FileSystemDefaultEncoding;
17822
50376d470648 Fix the Py_FileSystemDefaultEncoding checkin - declare the variable in a fileobject.h, and initialize it in bltinmodule.
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
60
23029
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22312
diff changeset
61 /* Routines to replace fread() and fgets() which accept any of \r, \n
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22312
diff changeset
62 or \r\n as line terminators.
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22312
diff changeset
63 */
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22312
diff changeset
64 #define PY_STDIOTEXTMODE "b"
8291473fde3e Mass checkin of universal newline support.
Jack Jansen <jack.jansen@cwi.nl>
parents: 22312
diff changeset
65 char *Py_UniversalNewlineFgets(char *, int, FILE*, PyObject *);
23201
c408e8b2675a Py_UniversalNewlineFread(): Many changes.
Tim Peters <tim.peters@gmail.com>
parents: 23029
diff changeset
66 size_t Py_UniversalNewlineFread(char *, size_t, FILE *, PyObject *);
31471
1dc96d87974e Remove support for --without-universal-newlines (see PEP 11).
Skip Montanaro <skip@pobox.com>
parents: 30320
diff changeset
67
41546
d9a487c2fa96 Export function sanitize_the_mode from fileobject.c as _PyFile_SanitizeMode(). Use this function in posixmodule.c when implementing fdopen(). This fixes test_subprocess.py for a VisualStudio 2005 compile.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 32159
diff changeset
68 /* A routine to do sanity checking on the file mode string. returns
d9a487c2fa96 Export function sanitize_the_mode from fileobject.c as _PyFile_SanitizeMode(). Use this function in posixmodule.c when implementing fdopen(). This fixes test_subprocess.py for a VisualStudio 2005 compile.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 32159
diff changeset
69 non-zero on if an exception occurred
d9a487c2fa96 Export function sanitize_the_mode from fileobject.c as _PyFile_SanitizeMode(). Use this function in posixmodule.c when implementing fdopen(). This fixes test_subprocess.py for a VisualStudio 2005 compile.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 32159
diff changeset
70 */
d9a487c2fa96 Export function sanitize_the_mode from fileobject.c as _PyFile_SanitizeMode(). Use this function in posixmodule.c when implementing fdopen(). This fixes test_subprocess.py for a VisualStudio 2005 compile.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 32159
diff changeset
71 int _PyFile_SanitizeMode(char *mode);
d9a487c2fa96 Export function sanitize_the_mode from fileobject.c as _PyFile_SanitizeMode(). Use this function in posixmodule.c when implementing fdopen(). This fixes test_subprocess.py for a VisualStudio 2005 compile.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 32159
diff changeset
72
51514
0415417cfd48 Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 47413
diff changeset
73 #if defined _MSC_VER && _MSC_VER >= 1400
0415417cfd48 Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 47413
diff changeset
74 /* A routine to check if a file descriptor is valid on Windows. Returns 0
0415417cfd48 Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 47413
diff changeset
75 * and sets errno to EBADF if it isn't. This is to avoid Assertions
0415417cfd48 Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 47413
diff changeset
76 * from various functions in the Windows CRT beginning with
0415417cfd48 Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 47413
diff changeset
77 * Visual Studio 2005
0415417cfd48 Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 47413
diff changeset
78 */
0415417cfd48 Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 47413
diff changeset
79 int _PyVerify_fd(int fd);
51535
dbdd94cd07fb Issue #5204: Define _PyVerify_fd on VC6 to make
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 51514
diff changeset
80 #elif defined _MSC_VER && _MSC_VER >= 1200
dbdd94cd07fb Issue #5204: Define _PyVerify_fd on VC6 to make
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 51514
diff changeset
81 /* fdopen doesn't set errno EBADF and crashes for large fd on debug build */
dbdd94cd07fb Issue #5204: Define _PyVerify_fd on VC6 to make
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
parents: 51514
diff changeset
82 #define _PyVerify_fd(fd) (_get_osfhandle(fd) >= 0)
51514
0415417cfd48 Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 47413
diff changeset
83 #else
0415417cfd48 Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 47413
diff changeset
84 #define _PyVerify_fd(A) (1) /* dummy */
0415417cfd48 Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 47413
diff changeset
85 #endif
0415417cfd48 Issue 4804. Add a function to test the validity of file descriptors on Windows, and stop using global runtime settings to silence the warnings / assertions.
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 47413
diff changeset
86
72114
31b18a0242ca Always define _PyIsSelectable_fd().
Charles-François Natali <neologix@free.fr>
parents: 72113
diff changeset
87 /* A routine to check if a file descriptor can be select()-ed. */
72113
ff6adb867f40 Issue #12287: Fix a stack corruption in ossaudiodev module when the FD is
Charles-François Natali <neologix@free.fr>
parents: 68256
diff changeset
88 #ifdef HAVE_SELECT
72114
31b18a0242ca Always define _PyIsSelectable_fd().
Charles-François Natali <neologix@free.fr>
parents: 72113
diff changeset
89 #define _PyIsSelectable_fd(FD) (((FD) >= 0) && ((FD) < FD_SETSIZE))
31b18a0242ca Always define _PyIsSelectable_fd().
Charles-François Natali <neologix@free.fr>
parents: 72113
diff changeset
90 #else
72113
ff6adb867f40 Issue #12287: Fix a stack corruption in ossaudiodev module when the FD is
Charles-François Natali <neologix@free.fr>
parents: 68256
diff changeset
91 #define _PyIsSelectable_fd(FD) (1)
ff6adb867f40 Issue #12287: Fix a stack corruption in ossaudiodev module when the FD is
Charles-François Natali <neologix@free.fr>
parents: 68256
diff changeset
92 #endif /* HAVE_SELECT */
ff6adb867f40 Issue #12287: Fix a stack corruption in ossaudiodev module when the FD is
Charles-François Natali <neologix@free.fr>
parents: 68256
diff changeset
93
1329
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
94 #ifdef __cplusplus
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
95 }
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
96 #endif
519c25039c6a * Added support for X11 modules.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
97 #endif /* !Py_FILEOBJECT_H */