Mercurial > cpython-lru_cache-weakref
annotate Objects/fileobject.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 65d2d8e67da3 |
| children | 4a8165b3b660 |
| rev | line source |
|---|---|
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
138
diff
changeset
|
1 /*********************************************************** |
|
2059
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2053
diff
changeset
|
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|
866c81068dbd
Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents:
2053
diff
changeset
|
3 The Netherlands. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
138
diff
changeset
|
4 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
138
diff
changeset
|
5 All Rights Reserved |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
138
diff
changeset
|
6 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
7 Permission to use, copy, modify, and distribute this software and its |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
8 documentation for any purpose and without fee is hereby granted, |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
138
diff
changeset
|
9 provided that the above copyright notice appear in all copies and that |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
10 both that copyright notice and this permission notice appear in |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
138
diff
changeset
|
11 supporting documentation, and that the names of Stichting Mathematisch |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
12 Centrum or CWI or Corporation for National Research Initiatives or |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
13 CNRI not be used in advertising or publicity pertaining to |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
14 distribution of the software without specific, written prior |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
15 permission. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
138
diff
changeset
|
16 |
|
4503
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
17 While CWI is the initial source for this software, a modified version |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
18 is made available by the Corporation for National Research Initiatives |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
19 (CNRI) at the Internet address ftp://ftp.python.org. |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
20 |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|
65d2d8e67da3
New permission notice, includes CNRI.
Guido van Rossum <guido@python.org>
parents:
2825
diff
changeset
|
28 PERFORMANCE OF THIS SOFTWARE. |
|
145
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
138
diff
changeset
|
29 |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
138
diff
changeset
|
30 ******************************************************************/ |
|
853b736a6a9e
Added copyright notice.
Guido van Rossum <guido@python.org>
parents:
138
diff
changeset
|
31 |
| 6 | 32 /* File object implementation */ |
| 33 | |
| 86 | 34 #include "allobjects.h" |
|
645
c0e7b0b9b750
Include modsupport.h for getargs().
Guido van Rossum <guido@python.org>
parents:
509
diff
changeset
|
35 #include "modsupport.h" |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
36 #include "structmember.h" |
| 926 | 37 #include "ceval.h" |
| 6 | 38 |
|
2397
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
39 #ifdef THINK_C |
|
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
40 #define HAVE_FOPENRF |
|
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
41 #endif |
|
2667
0b7e14bb54ae
MW does not always set errno on failing fopen()
Jack Jansen <jack.jansen@cwi.nl>
parents:
2397
diff
changeset
|
42 #ifdef __MWERKS__ |
|
0b7e14bb54ae
MW does not always set errno on failing fopen()
Jack Jansen <jack.jansen@cwi.nl>
parents:
2397
diff
changeset
|
43 /* Mwerks fopen() doesn't always set errno */ |
|
0b7e14bb54ae
MW does not always set errno on failing fopen()
Jack Jansen <jack.jansen@cwi.nl>
parents:
2397
diff
changeset
|
44 #define NO_FOPEN_ERRNO |
|
0b7e14bb54ae
MW does not always set errno on failing fopen()
Jack Jansen <jack.jansen@cwi.nl>
parents:
2397
diff
changeset
|
45 #endif |
|
2397
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
46 |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
47 #define BUF(v) GETSTRINGVALUE((stringobject *)v) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
48 |
|
1319
cd397266dc1c
* Makefile: added all: and default: targets.
Guido van Rossum <guido@python.org>
parents:
1313
diff
changeset
|
49 #include <errno.h> |
| 6 | 50 |
| 51 typedef struct { | |
| 52 OB_HEAD | |
| 53 FILE *f_fp; | |
| 54 object *f_name; | |
| 55 object *f_mode; | |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
56 int (*f_close) PROTO((FILE *)); |
|
177
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
57 int f_softspace; /* Flag used by 'print' command */ |
| 6 | 58 } fileobject; |
| 59 | |
| 60 FILE * | |
| 61 getfilefile(f) | |
| 62 object *f; | |
| 63 { | |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
64 if (f == NULL || !is_fileobject(f)) |
| 6 | 65 return NULL; |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
66 else |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
67 return ((fileobject *)f)->f_fp; |
| 6 | 68 } |
| 69 | |
| 70 object * | |
|
1354
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
71 getfilename(f) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
72 object *f; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
73 { |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
74 if (f == NULL || !is_fileobject(f)) |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
75 return NULL; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
76 else |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
77 return ((fileobject *)f)->f_name; |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
78 } |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
79 |
|
fccd415e2eb8
* bltinmodule.c: removed exec() built-in function.
Guido van Rossum <guido@python.org>
parents:
1319
diff
changeset
|
80 object * |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
81 newopenfileobject(fp, name, mode, close) |
| 6 | 82 FILE *fp; |
| 83 char *name; | |
| 84 char *mode; | |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
85 int (*close) FPROTO((FILE *)); |
| 6 | 86 { |
| 87 fileobject *f = NEWOBJ(fileobject, &Filetype); | |
| 88 if (f == NULL) | |
| 89 return NULL; | |
| 90 f->f_fp = NULL; | |
| 91 f->f_name = newstringobject(name); | |
| 92 f->f_mode = newstringobject(mode); | |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
93 f->f_close = close; |
|
177
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
94 f->f_softspace = 0; |
| 6 | 95 if (f->f_name == NULL || f->f_mode == NULL) { |
| 96 DECREF(f); | |
| 97 return NULL; | |
| 98 } | |
| 99 f->f_fp = fp; | |
| 100 return (object *) f; | |
| 101 } | |
| 102 | |
| 103 object * | |
| 104 newfileobject(name, mode) | |
| 105 char *name, *mode; | |
| 106 { | |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
107 extern int fclose PROTO((FILE *)); |
| 6 | 108 fileobject *f; |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
109 f = (fileobject *) newopenfileobject((FILE *)NULL, name, mode, fclose); |
| 6 | 110 if (f == NULL) |
| 111 return NULL; | |
|
2053
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
112 #ifdef HAVE_FOPENRF |
|
138
bb24948957e3
Hack to open resource fork on the Mac: open(filename, '*rb').
Guido van Rossum <guido@python.org>
parents:
109
diff
changeset
|
113 if (*mode == '*') { |
|
bb24948957e3
Hack to open resource fork on the Mac: open(filename, '*rb').
Guido van Rossum <guido@python.org>
parents:
109
diff
changeset
|
114 FILE *fopenRF(); |
|
bb24948957e3
Hack to open resource fork on the Mac: open(filename, '*rb').
Guido van Rossum <guido@python.org>
parents:
109
diff
changeset
|
115 f->f_fp = fopenRF(name, mode+1); |
|
bb24948957e3
Hack to open resource fork on the Mac: open(filename, '*rb').
Guido van Rossum <guido@python.org>
parents:
109
diff
changeset
|
116 } |
|
bb24948957e3
Hack to open resource fork on the Mac: open(filename, '*rb').
Guido van Rossum <guido@python.org>
parents:
109
diff
changeset
|
117 else |
|
bb24948957e3
Hack to open resource fork on the Mac: open(filename, '*rb').
Guido van Rossum <guido@python.org>
parents:
109
diff
changeset
|
118 #endif |
| 926 | 119 { |
| 120 BGN_SAVE | |
| 121 f->f_fp = fopen(name, mode); | |
| 122 END_SAVE | |
| 123 } | |
|
138
bb24948957e3
Hack to open resource fork on the Mac: open(filename, '*rb').
Guido van Rossum <guido@python.org>
parents:
109
diff
changeset
|
124 if (f->f_fp == NULL) { |
|
2667
0b7e14bb54ae
MW does not always set errno on failing fopen()
Jack Jansen <jack.jansen@cwi.nl>
parents:
2397
diff
changeset
|
125 #ifdef NO_FOPEN_ERRNO |
|
0b7e14bb54ae
MW does not always set errno on failing fopen()
Jack Jansen <jack.jansen@cwi.nl>
parents:
2397
diff
changeset
|
126 if ( errno == 0 ) { |
|
0b7e14bb54ae
MW does not always set errno on failing fopen()
Jack Jansen <jack.jansen@cwi.nl>
parents:
2397
diff
changeset
|
127 err_setstr(IOError, "Cannot open file"); |
|
0b7e14bb54ae
MW does not always set errno on failing fopen()
Jack Jansen <jack.jansen@cwi.nl>
parents:
2397
diff
changeset
|
128 DECREF(f); |
|
0b7e14bb54ae
MW does not always set errno on failing fopen()
Jack Jansen <jack.jansen@cwi.nl>
parents:
2397
diff
changeset
|
129 return NULL; |
|
0b7e14bb54ae
MW does not always set errno on failing fopen()
Jack Jansen <jack.jansen@cwi.nl>
parents:
2397
diff
changeset
|
130 } |
|
0b7e14bb54ae
MW does not always set errno on failing fopen()
Jack Jansen <jack.jansen@cwi.nl>
parents:
2397
diff
changeset
|
131 #endif |
| 475 | 132 err_errno(IOError); |
| 6 | 133 DECREF(f); |
| 134 return NULL; | |
| 135 } | |
| 136 return (object *)f; | |
| 137 } | |
| 138 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
139 void |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
140 setfilebufsize(f, bufsize) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
141 object *f; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
142 int bufsize; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
143 { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
144 if (bufsize >= 0) { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
145 #ifdef HAVE_SETVBUF |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
146 int type; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
147 switch (bufsize) { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
148 case 0: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
149 type = _IONBF; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
150 break; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
151 case 1: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
152 type = _IOLBF; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
153 bufsize = BUFSIZ; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
154 break; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
155 default: |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
156 type = _IOFBF; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
157 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
158 setvbuf(((fileobject *)f)->f_fp, (char *)NULL, type, bufsize); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
159 #endif /* HAVE_SETVBUF */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
160 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
161 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
162 |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
163 static object * |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
164 err_closed() |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
165 { |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
166 err_setstr(ValueError, "I/O operation on closed file"); |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
167 return NULL; |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
168 } |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
169 |
| 6 | 170 /* Methods */ |
| 171 | |
| 172 static void | |
| 86 | 173 file_dealloc(f) |
| 6 | 174 fileobject *f; |
| 175 { | |
| 926 | 176 if (f->f_fp != NULL && f->f_close != NULL) { |
| 177 BGN_SAVE | |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
178 (*f->f_close)(f->f_fp); |
| 926 | 179 END_SAVE |
| 180 } | |
| 6 | 181 if (f->f_name != NULL) |
| 182 DECREF(f->f_name); | |
| 183 if (f->f_mode != NULL) | |
| 184 DECREF(f->f_mode); | |
| 185 free((char *)f); | |
| 186 } | |
| 187 | |
| 188 static object * | |
| 86 | 189 file_repr(f) |
| 6 | 190 fileobject *f; |
| 191 { | |
| 192 char buf[300]; | |
|
1182
64cf191d21d0
Checking in last-minute changes that are already part of release 0.9.8
Guido van Rossum <guido@python.org>
parents:
1166
diff
changeset
|
193 sprintf(buf, "<%s file '%.256s', mode '%.10s' at %lx>", |
| 6 | 194 f->f_fp == NULL ? "closed" : "open", |
| 195 getstringvalue(f->f_name), | |
|
1182
64cf191d21d0
Checking in last-minute changes that are already part of release 0.9.8
Guido van Rossum <guido@python.org>
parents:
1166
diff
changeset
|
196 getstringvalue(f->f_mode), |
|
64cf191d21d0
Checking in last-minute changes that are already part of release 0.9.8
Guido van Rossum <guido@python.org>
parents:
1166
diff
changeset
|
197 (long)f); |
| 6 | 198 return newstringobject(buf); |
| 199 } | |
| 200 | |
| 201 static object * | |
| 86 | 202 file_close(f, args) |
| 6 | 203 fileobject *f; |
| 204 object *args; | |
| 205 { | |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
206 int sts = 0; |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
207 if (!getnoarg(args)) |
| 6 | 208 return NULL; |
| 209 if (f->f_fp != NULL) { | |
| 926 | 210 if (f->f_close != NULL) { |
| 211 BGN_SAVE | |
| 212 errno = 0; | |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
213 sts = (*f->f_close)(f->f_fp); |
| 926 | 214 END_SAVE |
| 215 } | |
| 6 | 216 f->f_fp = NULL; |
| 217 } | |
|
689
90ea50786095
Change error handling. Call clearerr() more often.
Guido van Rossum <guido@python.org>
parents:
645
diff
changeset
|
218 if (sts == EOF) |
| 475 | 219 return err_errno(IOError); |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
220 if (sts != 0) |
|
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
221 return newintobject((long)sts); |
| 6 | 222 INCREF(None); |
| 223 return None; | |
| 224 } | |
| 225 | |
| 226 static object * | |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
227 file_seek(f, args) |
| 6 | 228 fileobject *f; |
| 229 object *args; | |
| 230 { | |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
231 long offset; |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
232 int whence; |
| 926 | 233 int ret; |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
234 |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
235 if (f->f_fp == NULL) |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
236 return err_closed(); |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
237 whence = 0; |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
238 if (!getargs(args, "l", &offset)) { |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
239 err_clear(); |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
240 if (!getargs(args, "(li)", &offset, &whence)) |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
241 return NULL; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
242 } |
| 926 | 243 BGN_SAVE |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
244 errno = 0; |
| 926 | 245 ret = fseek(f->f_fp, offset, whence); |
| 246 END_SAVE | |
| 247 if (ret != 0) { | |
|
689
90ea50786095
Change error handling. Call clearerr() more often.
Guido van Rossum <guido@python.org>
parents:
645
diff
changeset
|
248 err_errno(IOError); |
|
90ea50786095
Change error handling. Call clearerr() more often.
Guido van Rossum <guido@python.org>
parents:
645
diff
changeset
|
249 clearerr(f->f_fp); |
|
90ea50786095
Change error handling. Call clearerr() more often.
Guido van Rossum <guido@python.org>
parents:
645
diff
changeset
|
250 return NULL; |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
251 } |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
252 INCREF(None); |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
253 return None; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
254 } |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
255 |
|
2053
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
256 #ifdef HAVE_FTRUNCATE |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
257 static object * |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
258 file_truncate(f, args) |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
259 fileobject *f; |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
260 object *args; |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
261 { |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
262 long newsize; |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
263 int ret; |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
264 |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
265 if (f->f_fp == NULL) |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
266 return err_closed(); |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
267 if (!getargs(args, "l", &newsize)) { |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
268 err_clear(); |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
269 if (!getnoarg(args)) |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
270 return NULL; |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
271 BGN_SAVE |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
272 errno = 0; |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
273 newsize = ftell(f->f_fp); /* default to current position*/ |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
274 END_SAVE |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
275 if (newsize == -1L) { |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
276 err_errno(IOError); |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
277 clearerr(f->f_fp); |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
278 return NULL; |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
279 } |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
280 } |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
281 BGN_SAVE |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
282 errno = 0; |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
283 ret = fflush(f->f_fp); |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
284 END_SAVE |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
285 if (ret == 0) { |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
286 BGN_SAVE |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
287 errno = 0; |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
288 ret = ftruncate(fileno(f->f_fp), newsize); |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
289 END_SAVE |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
290 } |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
291 if (ret != 0) { |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
292 err_errno(IOError); |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
293 clearerr(f->f_fp); |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
294 return NULL; |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
295 } |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
296 INCREF(None); |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
297 return None; |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
298 } |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
299 #endif /* HAVE_FTRUNCATE */ |
|
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
300 |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
301 static object * |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
302 file_tell(f, args) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
303 fileobject *f; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
304 object *args; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
305 { |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
306 long offset; |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
307 if (f->f_fp == NULL) |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
308 return err_closed(); |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
309 if (!getnoarg(args)) |
| 6 | 310 return NULL; |
| 926 | 311 BGN_SAVE |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
312 errno = 0; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
313 offset = ftell(f->f_fp); |
| 926 | 314 END_SAVE |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
315 if (offset == -1L) { |
|
689
90ea50786095
Change error handling. Call clearerr() more often.
Guido van Rossum <guido@python.org>
parents:
645
diff
changeset
|
316 err_errno(IOError); |
|
90ea50786095
Change error handling. Call clearerr() more often.
Guido van Rossum <guido@python.org>
parents:
645
diff
changeset
|
317 clearerr(f->f_fp); |
|
90ea50786095
Change error handling. Call clearerr() more often.
Guido van Rossum <guido@python.org>
parents:
645
diff
changeset
|
318 return NULL; |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
319 } |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
320 return newintobject(offset); |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
321 } |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
322 |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
323 static object * |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
324 file_fileno(f, args) |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
325 fileobject *f; |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
326 object *args; |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
327 { |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
328 if (f->f_fp == NULL) |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
329 return err_closed(); |
|
902
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
330 if (!getnoarg(args)) |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
331 return NULL; |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
332 return newintobject((long) fileno(f->f_fp)); |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
333 } |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
334 |
|
a4793ae26682
Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
335 static object * |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
336 file_flush(f, args) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
337 fileobject *f; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
338 object *args; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
339 { |
| 926 | 340 int res; |
| 341 | |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
342 if (f->f_fp == NULL) |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
343 return err_closed(); |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
344 if (!getnoarg(args)) |
| 6 | 345 return NULL; |
| 926 | 346 BGN_SAVE |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
347 errno = 0; |
| 926 | 348 res = fflush(f->f_fp); |
| 349 END_SAVE | |
| 350 if (res != 0) { | |
|
689
90ea50786095
Change error handling. Call clearerr() more often.
Guido van Rossum <guido@python.org>
parents:
645
diff
changeset
|
351 err_errno(IOError); |
|
90ea50786095
Change error handling. Call clearerr() more often.
Guido van Rossum <guido@python.org>
parents:
645
diff
changeset
|
352 clearerr(f->f_fp); |
|
90ea50786095
Change error handling. Call clearerr() more often.
Guido van Rossum <guido@python.org>
parents:
645
diff
changeset
|
353 return NULL; |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
354 } |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
355 INCREF(None); |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
356 return None; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
357 } |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
358 |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
359 static object * |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
360 file_isatty(f, args) |
|
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
361 fileobject *f; |
|
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
362 object *args; |
|
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
363 { |
| 926 | 364 long res; |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
365 if (f->f_fp == NULL) |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
366 return err_closed(); |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
367 if (!getnoarg(args)) |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
368 return NULL; |
| 926 | 369 BGN_SAVE |
| 370 res = isatty((int)fileno(f->f_fp)); | |
| 371 END_SAVE | |
| 372 return newintobject(res); | |
|
261
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
373 } |
|
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
374 |
|
f4a944e9835f
In support of popen(), file objects are now parametrized with a close
Guido van Rossum <guido@python.org>
parents:
251
diff
changeset
|
375 static object * |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
376 file_read(f, args) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
377 fileobject *f; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
378 object *args; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
379 { |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
380 int n, n1, n2, n3; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
381 object *v; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
382 |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
383 if (f->f_fp == NULL) |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
384 return err_closed(); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
385 if (args == NULL) |
|
2825
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
386 n = -1; |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
387 else { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
388 if (!getargs(args, "i", &n)) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
389 return NULL; |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
390 } |
|
2825
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
391 n2 = n >= 0 ? n : BUFSIZ; |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
392 v = newsizedstringobject((char *)NULL, n2); |
| 86 | 393 if (v == NULL) |
| 6 | 394 return NULL; |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
395 n1 = 0; |
| 926 | 396 BGN_SAVE |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
397 for (;;) { |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
398 n3 = fread(BUF(v)+n1, 1, n2-n1, f->f_fp); |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
399 /* XXX Error check? */ |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
400 if (n3 == 0) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
401 break; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
402 n1 += n3; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
403 if (n1 == n) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
404 break; |
|
2825
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
405 if (n < 0) { |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
406 n2 = n1 + BUFSIZ; |
| 926 | 407 RET_SAVE |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
408 if (resizestring(&v, n2) < 0) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
409 return NULL; |
| 926 | 410 RES_SAVE |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
411 } |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
412 } |
| 926 | 413 END_SAVE |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
414 if (n1 != n2) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
415 resizestring(&v, n1); |
| 6 | 416 return v; |
| 417 } | |
| 418 | |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
419 /* Internal routine to get a line. |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
420 Size argument interpretation: |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
421 > 0: max length; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
422 = 0: read arbitrary line; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
423 < 0: strip trailing '\n', raise EOFError if EOF reached immediately |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
424 */ |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
425 |
|
1313
6ee380349c84
* Added gmtime/localtime/mktime and SYSV timezone globals to timemodule.c.
Guido van Rossum <guido@python.org>
parents:
1198
diff
changeset
|
426 static object * |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
427 getline(f, n) |
| 6 | 428 fileobject *f; |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
429 int n; |
| 6 | 430 { |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
431 register FILE *fp; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
432 register int c; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
433 register char *buf, *end; |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
434 int n1, n2; |
| 6 | 435 object *v; |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
436 |
|
916
fec18e244d16
fileobject.c: fix fatal bug in getline() (forgot to initialize fp now)
Guido van Rossum <guido@python.org>
parents:
908
diff
changeset
|
437 fp = f->f_fp; |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
438 n2 = n > 0 ? n : 100; |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
439 v = newsizedstringobject((char *)NULL, n2); |
| 86 | 440 if (v == NULL) |
| 6 | 441 return NULL; |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
442 buf = BUF(v); |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
443 end = buf + n2; |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
916
diff
changeset
|
444 |
| 926 | 445 BGN_SAVE |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
446 for (;;) { |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
447 if ((c = getc(fp)) == EOF) { |
|
251
48d58b74a3a4
Call clearerr() after EOF seen.
Guido van Rossum <guido@python.org>
parents:
183
diff
changeset
|
448 clearerr(fp); |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
449 if (sigcheck()) { |
| 926 | 450 RET_SAVE |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
451 DECREF(v); |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
452 return NULL; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
453 } |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
454 if (n < 0 && buf == BUF(v)) { |
| 926 | 455 RET_SAVE |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
456 DECREF(v); |
|
509
5b5f86ee4f79
Added message to EOFError.
Guido van Rossum <guido@python.org>
parents:
475
diff
changeset
|
457 err_setstr(EOFError, |
|
5b5f86ee4f79
Added message to EOFError.
Guido van Rossum <guido@python.org>
parents:
475
diff
changeset
|
458 "EOF when reading a line"); |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
459 return NULL; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
460 } |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
461 break; |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
462 } |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
463 if ((*buf++ = c) == '\n') { |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
464 if (n < 0) |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
465 buf--; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
466 break; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
467 } |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
468 if (buf == end) { |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
469 if (n > 0) |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
470 break; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
471 n1 = n2; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
472 n2 += 1000; |
| 926 | 473 RET_SAVE |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
474 if (resizestring(&v, n2) < 0) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
475 return NULL; |
| 926 | 476 RES_SAVE |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
477 buf = BUF(v) + n1; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
478 end = BUF(v) + n2; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
479 } |
| 6 | 480 } |
| 926 | 481 END_SAVE |
|
923
72aceed365d4
* Makefile adapted to changes below.
Guido van Rossum <guido@python.org>
parents:
916
diff
changeset
|
482 |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
483 n1 = buf - BUF(v); |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
484 if (n1 != n2) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
485 resizestring(&v, n1); |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
486 return v; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
487 } |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
488 |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
489 /* External C interface */ |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
490 |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
491 object * |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
492 filegetline(f, n) |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
493 object *f; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
494 int n; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
495 { |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
496 if (f == NULL) { |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
497 err_badcall(); |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
498 return NULL; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
499 } |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
500 if (!is_fileobject(f)) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
501 object *reader; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
502 object *args; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
503 object *result; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
504 reader = getattr(f, "readline"); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
505 if (reader == NULL) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
506 return NULL; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
507 if (n <= 0) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
508 args = mkvalue("()"); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
509 else |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
510 args = mkvalue("(i)", n); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
511 if (args == NULL) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
512 DECREF(reader); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
513 return NULL; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
514 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
515 result = call_object(reader, args); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
516 DECREF(reader); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
517 DECREF(args); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
518 if (result != NULL && !is_stringobject(result)) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
519 DECREF(result); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
520 result = NULL; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
521 err_setstr(TypeError, |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
522 "object.readline() returned non-string"); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
523 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
524 if (n < 0 && result != NULL) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
525 char *s = getstringvalue(result); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
526 int len = getstringsize(result); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
527 if (len == 0) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
528 DECREF(result); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
529 result = NULL; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
530 err_setstr(EOFError, |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
531 "EOF when reading a line"); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
532 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
533 else if (s[len-1] == '\n') { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
534 if (result->ob_refcnt == 1) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
535 resizestring(&result, len-1); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
536 else { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
537 object *v; |
|
1166
a7cf20c845a3
fileobject.c: fix nasty bug; Makefile; turn on STROP and change lint flags.
Guido van Rossum <guido@python.org>
parents:
1073
diff
changeset
|
538 v = newsizedstringobject(s, len-1); |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
539 DECREF(result); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
540 result = v; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
541 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
542 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
543 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
544 return result; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
545 } |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
546 if (((fileobject*)f)->f_fp == NULL) |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
547 return err_closed(); |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
548 return getline((fileobject *)f, n); |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
549 } |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
550 |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
551 /* Python method */ |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
552 |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
553 static object * |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
554 file_readline(f, args) |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
555 fileobject *f; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
556 object *args; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
557 { |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
558 int n; |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
559 |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
560 if (f->f_fp == NULL) |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
561 return err_closed(); |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
562 if (args == NULL) |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
563 n = 0; /* Unlimited */ |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
564 else { |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
565 if (!getintarg(args, &n)) |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
566 return NULL; |
|
2825
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
567 if (n == 0) |
|
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
568 return newstringobject(""); |
|
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
569 if (n < 0) |
|
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
570 n = 0; |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
571 } |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
572 |
| 734 | 573 return getline(f, n); |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
574 } |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
575 |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
576 static object * |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
577 file_readlines(f, args) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
578 fileobject *f; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
579 object *args; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
580 { |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
581 object *list; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
582 object *line; |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
583 |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
584 if (f->f_fp == NULL) |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
585 return err_closed(); |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
586 if (!getnoarg(args)) |
|
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
587 return NULL; |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
588 if ((list = newlistobject(0)) == NULL) |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
589 return NULL; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
590 for (;;) { |
|
183
c9168afe23dd
Added external interface to readline, for raw_input().
Guido van Rossum <guido@python.org>
parents:
177
diff
changeset
|
591 line = getline(f, 0); |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
592 if (line != NULL && getstringsize(line) == 0) { |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
593 DECREF(line); |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
594 break; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
595 } |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
596 if (line == NULL || addlistitem(list, line) != 0) { |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
597 DECREF(list); |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
598 XDECREF(line); |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
599 return NULL; |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
600 } |
|
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
601 DECREF(line); |
| 6 | 602 } |
|
154
f2efceaf73cc
Fixed read() and readline() to do arbitrarily long reads.
Guido van Rossum <guido@python.org>
parents:
145
diff
changeset
|
603 return list; |
| 6 | 604 } |
| 605 | |
| 606 static object * | |
| 86 | 607 file_write(f, args) |
| 6 | 608 fileobject *f; |
| 609 object *args; | |
| 610 { | |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
611 char *s; |
| 6 | 612 int n, n2; |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
613 if (f->f_fp == NULL) |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
614 return err_closed(); |
|
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
615 if (!getargs(args, "s#", &s, &n)) |
| 6 | 616 return NULL; |
|
177
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
617 f->f_softspace = 0; |
| 926 | 618 BGN_SAVE |
| 6 | 619 errno = 0; |
|
908
424f55e67d5d
Makefile: added instann rules and $(*DEST*) defines.
Guido van Rossum <guido@python.org>
parents:
902
diff
changeset
|
620 n2 = fwrite(s, 1, n, f->f_fp); |
| 926 | 621 END_SAVE |
| 6 | 622 if (n2 != n) { |
| 475 | 623 err_errno(IOError); |
|
689
90ea50786095
Change error handling. Call clearerr() more often.
Guido van Rossum <guido@python.org>
parents:
645
diff
changeset
|
624 clearerr(f->f_fp); |
| 6 | 625 return NULL; |
| 626 } | |
| 627 INCREF(None); | |
| 628 return None; | |
| 629 } | |
| 630 | |
|
1362
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
631 static object * |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
632 file_writelines(f, args) |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
633 fileobject *f; |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
634 object *args; |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
635 { |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
636 int i, n; |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
637 if (f->f_fp == NULL) |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
638 return err_closed(); |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
639 if (args == NULL || !is_listobject(args)) { |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
640 err_setstr(TypeError, |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
641 "writelines() requires list of strings"); |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
642 return NULL; |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
643 } |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
644 n = getlistsize(args); |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
645 f->f_softspace = 0; |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
646 BGN_SAVE |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
647 errno = 0; |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
648 for (i = 0; i < n; i++) { |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
649 object *line = getlistitem(args, i); |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
650 int len; |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
651 int nwritten; |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
652 if (!is_stringobject(line)) { |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
653 RET_SAVE |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
654 err_setstr(TypeError, |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
655 "writelines() requires list of strings"); |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
656 return NULL; |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
657 } |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
658 len = getstringsize(line); |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
659 nwritten = fwrite(getstringvalue(line), 1, len, f->f_fp); |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
660 if (nwritten != len) { |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
661 RET_SAVE |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
662 err_errno(IOError); |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
663 clearerr(f->f_fp); |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
664 return NULL; |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
665 } |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
666 } |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
667 END_SAVE |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
668 INCREF(None); |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
669 return None; |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
670 } |
|
560407ec632b
* filemodule.c: added writelines() -- analogous to readlines()
Guido van Rossum <guido@python.org>
parents:
1354
diff
changeset
|
671 |
| 86 | 672 static struct methodlist file_methods[] = { |
|
2397
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
673 {"close", (method)file_close, 0}, |
|
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
674 {"flush", (method)file_flush, 0}, |
|
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
675 {"fileno", (method)file_fileno, 0}, |
|
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
676 {"isatty", (method)file_isatty, 0}, |
|
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
677 {"read", (method)file_read, 0}, |
|
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
678 {"readline", (method)file_readline, 0}, |
|
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
679 {"readlines", (method)file_readlines, 0}, |
|
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
680 {"seek", (method)file_seek, 0}, |
|
2053
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
681 #ifdef HAVE_FTRUNCATE |
|
2397
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
682 {"truncate", (method)file_truncate, 0}, |
|
2053
de49d49044d7
Lots of minor changes. Note for mappingobject.c: the hash table pointer
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
683 #endif |
|
2397
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
684 {"tell", (method)file_tell, 0}, |
|
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
685 {"write", (method)file_write, 0}, |
|
0736a7ec2f28
explicitly init flags in methodlists
Guido van Rossum <guido@python.org>
parents:
2059
diff
changeset
|
686 {"writelines", (method)file_writelines, 0}, |
| 6 | 687 {NULL, NULL} /* sentinel */ |
| 688 }; | |
| 689 | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
690 #define OFF(x) offsetof(fileobject, x) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
691 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
692 static struct memberlist file_memberlist[] = { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
693 {"softspace", T_INT, OFF(f_softspace)}, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
694 {"mode", T_OBJECT, OFF(f_mode), RO}, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
695 {"name", T_OBJECT, OFF(f_name), RO}, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
696 /* getattr(f, "closed") is implemented without this table */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
697 {"closed", T_INT, 0, RO}, |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
698 {NULL} /* Sentinel */ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
699 }; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
700 |
| 6 | 701 static object * |
| 86 | 702 file_getattr(f, name) |
| 6 | 703 fileobject *f; |
| 704 char *name; | |
| 705 { | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
706 object *res; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
707 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
708 res = findmethod(file_methods, (object *)f, name); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
709 if (res != NULL) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
710 return res; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
711 err_clear(); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
712 if (strcmp(name, "closed") == 0) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
713 return newintobject((long)(f->f_fp == 0)); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
714 return getmember((char *)f, file_memberlist, name); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
715 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
716 |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
717 static int |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
718 file_setattr(f, name, v) |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
719 fileobject *f; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
720 char *name; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
721 object *v; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
722 { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
723 if (v == NULL) { |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
724 err_setstr(AttributeError, "can't delete file attributes"); |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
725 return -1; |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
726 } |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
727 return setmember((char *)f, file_memberlist, name, v); |
| 6 | 728 } |
| 729 | |
| 730 typeobject Filetype = { | |
| 731 OB_HEAD_INIT(&Typetype) | |
| 732 0, | |
| 733 "file", | |
| 734 sizeof(fileobject), | |
| 735 0, | |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
736 (destructor)file_dealloc, /*tp_dealloc*/ |
|
1051
f54e64c8b9b7
* Makefile: added IMGFILE; moved some stuff around.
Guido van Rossum <guido@python.org>
parents:
926
diff
changeset
|
737 0, /*tp_print*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
738 (getattrfunc)file_getattr, /*tp_getattr*/ |
|
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
739 (setattrfunc)file_setattr, /*tp_setattr*/ |
| 6 | 740 0, /*tp_compare*/ |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
741 (reprfunc)file_repr, /*tp_repr*/ |
| 6 | 742 }; |
|
177
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
743 |
|
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
744 /* Interface for the 'soft space' between print items. */ |
|
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
745 |
|
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
746 int |
|
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
747 softspace(f, newflag) |
|
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
748 object *f; |
|
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
749 int newflag; |
|
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
750 { |
|
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
751 int oldflag = 0; |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
752 if (f == NULL) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
753 /* Do nothing */ |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
754 } |
|
1389
e99c22490bfb
* fileobject.c (softspace): fix bug if called with NULL file.
Guido van Rossum <guido@python.org>
parents:
1362
diff
changeset
|
755 else if (is_fileobject(f)) { |
|
177
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
756 oldflag = ((fileobject *)f)->f_softspace; |
|
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
757 ((fileobject *)f)->f_softspace = newflag; |
|
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
758 } |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
759 else { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
760 object *v; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
761 v = getattr(f, "softspace"); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
762 if (v == NULL) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
763 err_clear(); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
764 else { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
765 if (is_intobject(v)) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
766 oldflag = getintvalue(v); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
767 DECREF(v); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
768 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
769 v = newintobject((long)newflag); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
770 if (v == NULL) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
771 err_clear(); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
772 else { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
773 if (setattr(f, "softspace", v) != 0) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
774 err_clear(); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
775 DECREF(v); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
776 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
777 } |
|
177
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
778 return oldflag; |
|
bd49ca6c4add
Added 'softspace' interface to replace 'needspace' printing hack.
Guido van Rossum <guido@python.org>
parents:
154
diff
changeset
|
779 } |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
780 |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
781 /* Interfaces to write objects/strings to file-like objects */ |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
782 |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
783 int |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
784 writeobject(v, f, flags) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
785 object *v; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
786 object *f; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
787 int flags; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
788 { |
|
2825
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
789 object *writer, *value, *args, *result; |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
790 if (f == NULL) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
791 err_setstr(TypeError, "writeobject with NULL file"); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
792 return -1; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
793 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
794 else if (is_fileobject(f)) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
795 FILE *fp = getfilefile(f); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
796 if (fp == NULL) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
797 err_closed(); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
798 return -1; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
799 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
800 return printobject(v, fp, flags); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
801 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
802 writer = getattr(f, "write"); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
803 if (writer == NULL) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
804 return -1; |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1389
diff
changeset
|
805 if (flags & PRINT_RAW) |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1389
diff
changeset
|
806 value = strobject(v); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1389
diff
changeset
|
807 else |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
808 value = reprobject(v); |
|
1400
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1389
diff
changeset
|
809 if (value == NULL) { |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1389
diff
changeset
|
810 DECREF(writer); |
|
aac8231a715c
* mpzmodule.c: removed redundant mpz_print function.
Guido van Rossum <guido@python.org>
parents:
1389
diff
changeset
|
811 return -1; |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
812 } |
|
2825
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
813 args = mkvalue("(O)", value); |
|
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
814 if (value == NULL) { |
|
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
815 DECREF(value); |
|
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
816 DECREF(writer); |
|
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
817 return -1; |
|
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
818 } |
|
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
819 result = call_object(writer, args); |
|
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
820 DECREF(args); |
|
bebb0ea7de20
fix read(0), readline(0); make tuple for call_object args
Guido van Rossum <guido@python.org>
parents:
2667
diff
changeset
|
821 DECREF(value); |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
822 DECREF(writer); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
823 if (result == NULL) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
824 return -1; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
825 DECREF(result); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
826 return 0; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
827 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
828 |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
829 void |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
830 writestring(s, f) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
831 char *s; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
832 object *f; |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
833 { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
834 if (f == NULL) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
835 /* Do nothing */ |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
836 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
837 else if (is_fileobject(f)) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
838 FILE *fp = getfilefile(f); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
839 if (fp != NULL) |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
840 fputs(s, fp); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
841 } |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1400
diff
changeset
|
842 else if (!err_occurred()) { |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
843 object *v = newstringobject(s); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
844 if (v == NULL) { |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
845 err_clear(); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
846 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
847 else { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
1182
diff
changeset
|
848 if (writeobject(v, f, PRINT_RAW) != 0) |
|
1073
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
849 err_clear(); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
850 DECREF(v); |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
851 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
852 } |
|
2c0432fcc270
Modified most (but not yet all) I/O to always go through sys.stdout or
Guido van Rossum <guido@python.org>
parents:
1051
diff
changeset
|
853 } |
