Mercurial > cpython-lru_cache-weakref
annotate Modules/cStringIO.c @ 5792:dffabc620e4e legacy-trunk
Tweak re_tests and test_re to differentiate between
groups that have no value and groups that are out of bounds.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 15 Jul 1997 15:49:52 +0000 |
| parents | 65c9e90d8142 |
| children | a5737dd96979 |
| rev | line source |
|---|---|
| 4598 | 1 /* |
| 2 | |
| 3 $Id$ | |
| 4 | |
| 5 A simple fast partial StringIO replacement. | |
| 6 | |
| 7 | |
| 8 | |
| 9 Copyright | |
| 10 | |
| 11 Copyright 1996 Digital Creations, L.C., 910 Princess Anne | |
| 12 Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All | |
| 13 rights reserved. Copyright in this software is owned by DCLC, | |
| 14 unless otherwise indicated. Permission to use, copy and | |
| 15 distribute this software is hereby granted, provided that the | |
| 16 above copyright notice appear in all copies and that both that | |
| 17 copyright notice and this permission notice appear. Note that | |
| 18 any product, process or technology described in this software | |
| 19 may be the subject of other Intellectual Property rights | |
| 20 reserved by Digital Creations, L.C. and are not licensed | |
| 21 hereunder. | |
| 22 | |
| 23 Trademarks | |
| 24 | |
| 25 Digital Creations & DCLC, are trademarks of Digital Creations, L.C.. | |
| 26 All other trademarks are owned by their respective companies. | |
| 27 | |
| 28 No Warranty | |
| 29 | |
| 30 The software is provided "as is" without warranty of any kind, | |
| 31 either express or implied, including, but not limited to, the | |
| 32 implied warranties of merchantability, fitness for a particular | |
| 33 purpose, or non-infringement. This software could include | |
| 34 technical inaccuracies or typographical errors. Changes are | |
| 35 periodically made to the software; these changes will be | |
| 36 incorporated in new editions of the software. DCLC may make | |
| 37 improvements and/or changes in this software at any time | |
| 38 without notice. | |
| 39 | |
| 40 Limitation Of Liability | |
| 41 | |
| 42 In no event will DCLC be liable for direct, indirect, special, | |
| 43 incidental, economic, cover, or consequential damages arising | |
| 44 out of the use of or inability to use this software even if | |
| 45 advised of the possibility of such damages. Some states do not | |
| 46 allow the exclusion or limitation of implied warranties or | |
| 47 limitation of liability for incidental or consequential | |
| 48 damages, so the above limitation or exclusion may not apply to | |
| 49 you. | |
| 50 | |
| 51 If you have questions regarding this software, | |
| 52 contact: | |
| 53 | |
| 54 Jim Fulton, jim@digicool.com | |
| 55 Digital Creations L.C. | |
| 56 | |
| 57 (540) 371-6909 | |
| 58 | |
| 59 | |
| 60 $Log$ | |
|
5315
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
61 Revision 2.5 1997/04/11 19:56:06 guido |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
62 My own patch: support writable 'softspace' attribute. |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
63 |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
64 Revision 2.4 1997/04/09 17:35:33 guido |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
65 Unknown changes by Jim Fulton. |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
66 |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
67 Revision 1.16 1997/02/17 22:17:43 jim |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
68 *** empty log message *** |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
69 |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
70 Revision 1.14 1997/01/24 19:56:24 chris |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
71 undid last change |
|
4957
9d58d0e9877e
Quieted gcc -Wall by removing unused local variables.
Barry Warsaw <barry@python.org>
parents:
4906
diff
changeset
|
72 |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
73 Revision 1.13 1997/01/24 19:45:20 chris |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
74 extra byte in buffer no longer included in buf_size |
|
4957
9d58d0e9877e
Quieted gcc -Wall by removing unused local variables.
Barry Warsaw <barry@python.org>
parents:
4906
diff
changeset
|
75 |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
76 Revision 1.12 1997/01/24 19:38:28 chris |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
77 *** empty log message *** |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
78 |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
79 Revision 1.11 1997/01/23 20:45:01 jim |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
80 ANSIfied it. |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
81 Changed way C API was exported. |
| 4906 | 82 |
| 83 Revision 1.10 1997/01/02 15:19:55 chris | |
| 84 checked in to be sure repository is up to date. | |
| 85 | |
| 86 Revision 1.9 1996/12/27 21:40:29 jim | |
| 87 Took out some lamosities in interface, like returning self from | |
| 88 write. | |
| 89 | |
| 90 Revision 1.8 1996/12/23 15:52:49 jim | |
| 91 Added ifdef to check for CObject before using it. | |
| 92 | |
| 93 Revision 1.7 1996/12/23 15:22:35 jim | |
| 94 Finished implementation, adding full compatibility with StringIO, and | |
| 95 then some. | |
| 96 | |
| 97 We still need to take out some cStringIO oddities. | |
| 4598 | 98 |
| 99 Revision 1.6 1996/10/15 18:42:07 jim | |
| 100 Added lots of casts to make warnings go away. | |
| 101 | |
| 102 Revision 1.5 1996/10/11 21:03:42 jim | |
| 103 *** empty log message *** | |
| 104 | |
| 105 Revision 1.4 1996/10/11 21:02:15 jim | |
| 106 *** empty log message *** | |
| 107 | |
| 108 Revision 1.3 1996/10/07 20:51:38 chris | |
| 109 *** empty log message *** | |
| 110 | |
| 111 Revision 1.2 1996/07/18 13:08:34 jfulton | |
| 112 *** empty log message *** | |
| 113 | |
| 114 Revision 1.1 1996/07/15 17:06:33 jfulton | |
| 115 Initial version. | |
| 116 | |
| 117 | |
| 118 */ | |
| 119 static char cStringIO_module_documentation[] = | |
| 120 "A simple fast partial StringIO replacement.\n" | |
| 121 "\n" | |
| 122 "This module provides a simple useful replacement for\n" | |
| 123 "the StringIO module that is written in C. It does not provide the\n" | |
| 124 "full generality if StringIO, but it provides anough for most\n" | |
| 125 "applications and is especially useful in conjuction with the\n" | |
| 126 "pickle module.\n" | |
| 127 "\n" | |
| 128 "Usage:\n" | |
| 129 "\n" | |
| 130 " from cStringIO import StringIO\n" | |
| 131 "\n" | |
| 132 " an_output_stream=StringIO()\n" | |
| 133 " an_output_stream.write(some_stuff)\n" | |
| 134 " ...\n" | |
| 135 " value=an_output_stream.getvalue() # str(an_output_stream) works too!\n" | |
| 136 "\n" | |
| 137 " an_input_stream=StringIO(a_string)\n" | |
| 138 " spam=an_input_stream.readline()\n" | |
| 139 " spam=an_input_stream.read(5)\n" | |
| 140 " an_input_stream.reset() # OK, start over, note no seek yet\n" | |
| 141 " spam=an_input_stream.read() # and read it all\n" | |
| 142 " \n" | |
| 143 "If someone else wants to provide a more complete implementation,\n" | |
| 144 "go for it. :-) \n" | |
| 145 ; | |
| 146 | |
| 147 #include "Python.h" | |
| 148 #include "import.h" | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
149 #include "cStringIO.h" |
| 4598 | 150 |
| 151 #define UNLESS(E) if(!(E)) | |
| 152 | |
| 153 /* ----------------------------------------------------- */ | |
| 154 | |
| 155 /* Declarations for objects of type StringO */ | |
| 156 | |
| 157 typedef struct { | |
| 158 PyObject_HEAD | |
| 159 char *buf; | |
|
5315
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
160 int pos, string_size, buf_size, closed, softspace; |
| 4598 | 161 } Oobject; |
| 162 | |
| 163 staticforward PyTypeObject Otype; | |
| 164 | |
| 165 /* ---------------------------------------------------------------- */ | |
| 166 | |
| 167 /* Declarations for objects of type StringI */ | |
| 168 | |
| 169 typedef struct { | |
| 170 PyObject_HEAD | |
| 171 char *buf; | |
| 172 int pos, string_size, closed; | |
| 173 PyObject *pbuf; | |
| 174 } Iobject; | |
| 175 | |
| 176 staticforward PyTypeObject Itype; | |
| 177 | |
| 178 /* ---------------------------------------------------------------- */ | |
| 179 | |
| 180 static char O_reset__doc__[] = | |
| 181 "reset() -- Reset the file position to the beginning" | |
| 182 ; | |
| 183 | |
| 184 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
185 O_reset(Oobject *self, PyObject *args) { |
| 4598 | 186 self->pos = 0; |
| 187 | |
| 188 Py_INCREF(Py_None); | |
| 189 return Py_None; | |
| 190 } | |
| 191 | |
| 192 | |
| 193 static char O_tell__doc__[] = | |
| 194 "tell() -- get the current position."; | |
| 195 | |
| 196 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
197 O_tell(Oobject *self, PyObject *args) { |
| 4598 | 198 return PyInt_FromLong(self->pos); |
| 199 } | |
| 200 | |
| 201 | |
| 202 static char O_seek__doc__[] = | |
| 203 "seek(position) -- set the current position\n" | |
| 204 "seek(position, mode) -- mode 0: absolute; 1: relative; 2: relative to EOF"; | |
| 205 | |
| 206 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
207 O_seek(Oobject *self, PyObject *args) { |
| 4598 | 208 int position, mode = 0; |
| 209 | |
| 210 UNLESS(PyArg_ParseTuple(args, "i|i", &position, &mode)) | |
| 211 { | |
| 212 return NULL; | |
| 213 } | |
| 214 | |
| 215 if (mode == 2) | |
| 216 { | |
| 217 position += self->string_size; | |
| 218 } | |
| 219 else if (mode == 1) | |
| 220 { | |
| 221 position += self->pos; | |
| 222 } | |
| 223 | |
| 224 self->pos = (position > self->string_size ? self->string_size : | |
| 225 (position < 0 ? 0 : position)); | |
| 226 | |
| 4906 | 227 Py_INCREF(Py_None); |
| 228 return Py_None; | |
| 4598 | 229 } |
| 230 | |
| 231 static char O_read__doc__[] = | |
| 232 "read([s]) -- Read s characters, or the rest of the string" | |
| 233 ; | |
| 234 | |
| 235 static int | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
236 O_cread(PyObject *self, char **output, int n) { |
| 4598 | 237 int l; |
| 238 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
239 l = ((Oobject*)self)->string_size - ((Oobject*)self)->pos; |
| 4598 | 240 if (n < 0 || n > l) |
| 241 { | |
| 242 n = l; | |
| 243 } | |
| 244 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
245 *output=((Oobject*)self)->buf + ((Oobject*)self)->pos; |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
246 ((Oobject*)self)->pos += n; |
| 4598 | 247 return n; |
| 248 } | |
| 249 | |
| 250 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
251 O_read(Oobject *self, PyObject *args) { |
| 4598 | 252 int n = -1; |
| 253 char *output; | |
| 254 | |
| 255 UNLESS(PyArg_ParseTuple(args, "|i", &n)) return NULL; | |
| 256 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
257 n=O_cread((PyObject*)self,&output,n); |
| 4598 | 258 |
| 259 return PyString_FromStringAndSize(output, n); | |
| 260 } | |
| 261 | |
| 262 | |
| 263 static char O_readline__doc__[] = | |
| 264 "readline() -- Read one line" | |
| 265 ; | |
| 266 | |
| 267 static int | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
268 O_creadline(PyObject *self, char **output) { |
| 4598 | 269 char *n, *s; |
| 270 int l; | |
| 271 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
272 for (n = ((Oobject*)self)->buf + ((Oobject*)self)->pos, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
273 s = ((Oobject*)self)->buf + ((Oobject*)self)->string_size; |
| 4598 | 274 n < s && *n != '\n'; n++); |
| 275 if (n < s) n++; | |
| 276 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
277 *output=((Oobject*)self)->buf + ((Oobject*)self)->pos; |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
278 l = n - ((Oobject*)self)->buf - ((Oobject*)self)->pos; |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
279 ((Oobject*)self)->pos += l; |
| 4598 | 280 return l; |
| 281 } | |
| 282 | |
| 283 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
284 O_readline(Oobject *self, PyObject *args) { |
| 4598 | 285 int n; |
| 286 char *output; | |
| 287 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
288 n=O_creadline((PyObject*)self,&output); |
| 4598 | 289 return PyString_FromStringAndSize(output, n); |
| 290 } | |
| 291 | |
| 292 static char O_write__doc__[] = | |
| 293 "write(s) -- Write a string to the file" | |
| 294 "\n\nNote (hack:) writing None resets the buffer" | |
| 295 ; | |
| 296 | |
| 297 | |
| 298 static int | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
299 O_cwrite(PyObject *self, char *c, int l) { |
|
4957
9d58d0e9877e
Quieted gcc -Wall by removing unused local variables.
Barry Warsaw <barry@python.org>
parents:
4906
diff
changeset
|
300 int newl; |
| 4906 | 301 |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
302 newl=((Oobject*)self)->pos+l; |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
303 if(newl >= ((Oobject*)self)->buf_size) |
| 4598 | 304 { |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
305 ((Oobject*)self)->buf_size*=2; |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
306 if(((Oobject*)self)->buf_size <= newl) ((Oobject*)self)->buf_size=newl+1; |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
307 UNLESS(((Oobject*)self)->buf= |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
308 (char*)realloc(((Oobject*)self)->buf, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
309 (((Oobject*)self)->buf_size) *sizeof(char))) |
| 4598 | 310 { |
| 311 PyErr_SetString(PyExc_MemoryError,"out of memory"); | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
312 ((Oobject*)self)->buf_size=((Oobject*)self)->pos=0; |
| 4598 | 313 return -1; |
| 314 } | |
| 315 } | |
| 316 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
317 memcpy(((Oobject*)((Oobject*)self))->buf+((Oobject*)self)->pos,c,l); |
| 4598 | 318 |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
319 ((Oobject*)self)->pos += l; |
| 4598 | 320 |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
321 if (((Oobject*)self)->string_size < ((Oobject*)self)->pos) |
| 4598 | 322 { |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
323 ((Oobject*)self)->string_size = ((Oobject*)self)->pos; |
| 4598 | 324 } |
| 325 | |
| 326 return l; | |
| 327 } | |
| 328 | |
| 329 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
330 O_write(Oobject *self, PyObject *args) { |
| 4598 | 331 PyObject *s; |
|
4957
9d58d0e9877e
Quieted gcc -Wall by removing unused local variables.
Barry Warsaw <barry@python.org>
parents:
4906
diff
changeset
|
332 char *c; |
|
9d58d0e9877e
Quieted gcc -Wall by removing unused local variables.
Barry Warsaw <barry@python.org>
parents:
4906
diff
changeset
|
333 int l; |
| 4598 | 334 |
| 335 UNLESS(PyArg_Parse(args, "O", &s)) return NULL; | |
| 4906 | 336 UNLESS(-1 != (l=PyString_Size(s))) return NULL; |
| 337 UNLESS(c=PyString_AsString(s)) return NULL; | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
338 UNLESS(-1 != O_cwrite((PyObject*)self,c,l)) return NULL; |
| 4598 | 339 |
| 4906 | 340 Py_INCREF(Py_None); |
| 341 return Py_None; | |
| 4598 | 342 } |
| 343 | |
| 344 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
345 O_getval(Oobject *self, PyObject *args) { |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
346 return PyString_FromStringAndSize(self->buf, self->pos); |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
347 } |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
348 |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
349 static PyObject * |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
350 O_cgetval(PyObject *self) { |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
351 return PyString_FromStringAndSize(((Oobject*)self)->buf, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
352 ((Oobject*)self)->pos); |
| 4598 | 353 } |
| 354 | |
| 355 static char O_truncate__doc__[] = | |
| 356 "truncate(): truncate the file at the current position."; | |
| 357 | |
| 358 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
359 O_truncate(Oobject *self, PyObject *args) { |
| 4598 | 360 self->string_size = self->pos; |
| 361 Py_INCREF(Py_None); | |
| 362 return Py_None; | |
| 363 } | |
| 364 | |
| 365 static char O_isatty__doc__[] = "isatty(): always returns 0"; | |
| 366 | |
| 367 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
368 O_isatty(Oobject *self, PyObject *args) { |
| 4598 | 369 return PyInt_FromLong(0); |
| 370 } | |
| 371 | |
| 372 static char O_close__doc__[] = "close(): explicitly release resources held."; | |
| 373 | |
| 374 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
375 O_close(Oobject *self, PyObject *args) { |
| 4598 | 376 free(self->buf); |
| 377 | |
| 378 self->pos = self->string_size = self->buf_size = 0; | |
| 379 self->closed = 1; | |
| 380 | |
| 381 Py_INCREF(Py_None); | |
| 382 return Py_None; | |
| 383 } | |
| 384 | |
| 385 static char O_flush__doc__[] = "flush(): does nothing."; | |
| 386 | |
| 387 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
388 O_flush(Oobject *self, PyObject *args) { |
| 4598 | 389 Py_INCREF(Py_None); |
| 390 return Py_None; | |
| 391 } | |
| 392 | |
| 393 | |
| 394 static char O_writelines__doc__[] = "blah"; | |
| 395 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
396 O_writelines(Oobject *self, PyObject *args) { |
| 4598 | 397 PyObject *string_module = 0; |
| 398 static PyObject *string_joinfields = 0; | |
| 399 | |
| 400 UNLESS(PyArg_Parse(args, "O", args)) | |
| 401 { | |
| 402 return NULL; | |
| 403 } | |
| 404 | |
| 405 if (!string_joinfields) | |
| 406 { | |
| 407 UNLESS(string_module = PyImport_ImportModule("string")) | |
| 408 { | |
| 409 return NULL; | |
| 410 } | |
| 411 | |
| 412 UNLESS(string_joinfields= | |
| 413 PyObject_GetAttrString(string_module, "joinfields")) | |
| 414 { | |
| 415 return NULL; | |
| 416 } | |
| 417 | |
| 418 Py_DECREF(string_module); | |
| 419 } | |
| 420 | |
| 421 if (PyObject_Length(args) == -1) | |
| 422 { | |
| 423 return NULL; | |
| 424 } | |
| 425 | |
| 426 return O_write(self, | |
| 427 PyObject_CallFunction(string_joinfields, "Os", args, "")); | |
| 428 } | |
| 429 | |
| 430 static struct PyMethodDef O_methods[] = { | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
431 {"write", (PyCFunction)O_write, 0, O_write__doc__}, |
| 4598 | 432 {"read", (PyCFunction)O_read, 1, O_read__doc__}, |
| 433 {"readline", (PyCFunction)O_readline, 0, O_readline__doc__}, | |
| 434 {"reset", (PyCFunction)O_reset, 0, O_reset__doc__}, | |
| 435 {"seek", (PyCFunction)O_seek, 1, O_seek__doc__}, | |
| 436 {"tell", (PyCFunction)O_tell, 0, O_tell__doc__}, | |
| 437 {"getvalue", (PyCFunction)O_getval, 0, "getvalue() -- Get the string value"}, | |
| 438 {"truncate", (PyCFunction)O_truncate, 0, O_truncate__doc__}, | |
| 439 {"isatty", (PyCFunction)O_isatty, 0, O_isatty__doc__}, | |
| 440 {"close", (PyCFunction)O_close, 0, O_close__doc__}, | |
| 441 {"flush", (PyCFunction)O_flush, 0, O_flush__doc__}, | |
| 442 {"writelines", (PyCFunction)O_writelines, 0, O_writelines__doc__}, | |
| 443 {NULL, NULL} /* sentinel */ | |
| 444 }; | |
| 445 | |
| 446 /* ---------- */ | |
| 447 | |
| 448 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
449 static PyObject * |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
450 newOobject(int size) { |
| 4598 | 451 Oobject *self; |
| 452 | |
| 453 self = PyObject_NEW(Oobject, &Otype); | |
| 454 if (self == NULL) | |
| 455 return NULL; | |
| 456 self->pos=0; | |
| 457 self->closed = 0; | |
| 458 self->string_size = 0; | |
|
5315
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
459 self->softspace = 0; |
| 4598 | 460 |
| 461 UNLESS(self->buf=malloc(size*sizeof(char))) | |
| 462 { | |
| 463 PyErr_SetString(PyExc_MemoryError,"out of memory"); | |
| 464 self->buf_size = 0; | |
| 465 return NULL; | |
| 466 } | |
| 467 | |
| 468 self->buf_size=size; | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
469 return (PyObject*)self; |
| 4598 | 470 } |
| 471 | |
| 472 | |
| 473 static void | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
474 O_dealloc(Oobject *self) { |
| 4598 | 475 free(self->buf); |
| 476 PyMem_DEL(self); | |
| 477 } | |
| 478 | |
| 479 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
480 O_getattr(Oobject *self, char *name) { |
|
5315
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
481 if (strcmp(name, "softspace") == 0) { |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
482 return PyInt_FromLong(self->softspace); |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
483 } |
| 4598 | 484 return Py_FindMethod(O_methods, (PyObject *)self, name); |
| 485 } | |
| 486 | |
|
5315
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
487 static int |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
488 O_setattr(Oobject *self, char *name, PyObject *value) { |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
489 long x; |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
490 if (strcmp(name, "softspace") != 0) { |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
491 PyErr_SetString(PyExc_AttributeError, name); |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
492 return -1; |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
493 } |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
494 x = PyInt_AsLong(value); |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
495 if (x == -1 && PyErr_Occurred()) |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
496 return -1; |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
497 self->softspace = x; |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
498 return 0; |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
499 } |
|
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
500 |
| 4598 | 501 static char Otype__doc__[] = |
| 502 "Simple type for output to strings." | |
| 503 ; | |
| 504 | |
| 505 static PyTypeObject Otype = { | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
506 PyObject_HEAD_INIT(NULL) |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
507 0, /*ob_size*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
508 "StringO", /*tp_name*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
509 sizeof(Oobject), /*tp_basicsize*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
510 0, /*tp_itemsize*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
511 /* methods */ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
512 (destructor)O_dealloc, /*tp_dealloc*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
513 (printfunc)0, /*tp_print*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
514 (getattrfunc)O_getattr, /*tp_getattr*/ |
|
5315
65c9e90d8142
My own patch: support writable 'softspace' attribute.
Guido van Rossum <guido@python.org>
parents:
5280
diff
changeset
|
515 (setattrfunc)O_setattr, /*tp_setattr*/ |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
516 (cmpfunc)0, /*tp_compare*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
517 (reprfunc)0, /*tp_repr*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
518 0, /*tp_as_number*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
519 0, /*tp_as_sequence*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
520 0, /*tp_as_mapping*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
521 (hashfunc)0, /*tp_hash*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
522 (ternaryfunc)0, /*tp_call*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
523 (reprfunc)0, /*tp_str*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
524 |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
525 /* Space for future expansion */ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
526 0L,0L,0L,0L, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
527 Otype__doc__ /* Documentation string */ |
| 4598 | 528 }; |
| 529 | |
| 530 /* End of code for StringO objects */ | |
| 531 /* -------------------------------------------------------- */ | |
| 532 | |
| 533 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
534 I_close(Iobject *self, PyObject *args) { |
| 4598 | 535 Py_DECREF(self->pbuf); |
| 536 | |
| 537 self->pos = self->string_size = 0; | |
| 538 self->closed = 1; | |
| 539 | |
| 540 Py_INCREF(Py_None); | |
| 541 return Py_None; | |
| 542 } | |
| 543 | |
| 544 static struct PyMethodDef I_methods[] = { | |
| 545 {"read", (PyCFunction)O_read, 1, O_read__doc__}, | |
| 546 {"readline", (PyCFunction)O_readline, 0, O_readline__doc__}, | |
| 547 {"reset", (PyCFunction)O_reset, 0, O_reset__doc__}, | |
| 548 {"seek", (PyCFunction)O_seek, 1, O_seek__doc__}, | |
| 549 {"tell", (PyCFunction)O_tell, 0, O_tell__doc__}, | |
| 550 {"truncate", (PyCFunction)O_truncate, 0, O_truncate__doc__}, | |
| 551 {"isatty", (PyCFunction)O_isatty, 0, O_isatty__doc__}, | |
| 552 {"close", (PyCFunction)I_close, 0, O_close__doc__}, | |
| 553 {"flush", (PyCFunction)O_flush, 0, O_flush__doc__}, | |
| 554 {NULL, NULL} /* sentinel */ | |
| 555 }; | |
| 556 | |
| 557 /* ---------- */ | |
| 558 | |
| 559 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
560 static PyObject * |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
561 newIobject(PyObject *s) { |
| 4598 | 562 Iobject *self; |
| 563 char *buf; | |
| 564 int size; | |
| 565 | |
| 566 UNLESS(buf=PyString_AsString(s)) return NULL; | |
| 567 UNLESS(-1 != (size=PyString_Size(s))) return NULL; | |
| 568 UNLESS(self = PyObject_NEW(Iobject, &Itype)) return NULL; | |
| 569 Py_INCREF(s); | |
| 570 self->buf=buf; | |
| 571 self->string_size=size; | |
| 572 self->pbuf=s; | |
| 573 self->pos=0; | |
| 574 self->closed = 0; | |
| 575 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
576 return (PyObject*)self; |
| 4598 | 577 } |
| 578 | |
| 579 | |
| 580 static void | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
581 I_dealloc(Iobject *self) { |
| 4598 | 582 Py_DECREF(self->pbuf); |
| 583 PyMem_DEL(self); | |
| 584 } | |
| 585 | |
| 586 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
587 I_getattr(Iobject *self, char *name) { |
| 4598 | 588 return Py_FindMethod(I_methods, (PyObject *)self, name); |
| 589 } | |
| 590 | |
| 591 static char Itype__doc__[] = | |
| 592 "Simple type for treating strings as input file streams" | |
| 593 ; | |
| 594 | |
| 595 static PyTypeObject Itype = { | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
596 PyObject_HEAD_INIT(NULL) |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
597 0, /*ob_size*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
598 "StringI", /*tp_name*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
599 sizeof(Iobject), /*tp_basicsize*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
600 0, /*tp_itemsize*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
601 /* methods */ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
602 (destructor)I_dealloc, /*tp_dealloc*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
603 (printfunc)0, /*tp_print*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
604 (getattrfunc)I_getattr, /*tp_getattr*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
605 (setattrfunc)0, /*tp_setattr*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
606 (cmpfunc)0, /*tp_compare*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
607 (reprfunc)0, /*tp_repr*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
608 0, /*tp_as_number*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
609 0, /*tp_as_sequence*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
610 0, /*tp_as_mapping*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
611 (hashfunc)0, /*tp_hash*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
612 (ternaryfunc)0, /*tp_call*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
613 (reprfunc)0, /*tp_str*/ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
614 |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
615 /* Space for future expansion */ |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
616 0L,0L,0L,0L, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
617 Itype__doc__ /* Documentation string */ |
| 4598 | 618 }; |
| 619 | |
| 620 /* End of code for StringI objects */ | |
| 621 /* -------------------------------------------------------- */ | |
| 622 | |
| 623 | |
| 624 static char IO_StringIO__doc__[] = | |
| 625 "StringIO([s]) -- Return a StringIO-like stream for reading or writing" | |
| 626 ; | |
| 627 | |
| 628 static PyObject * | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
629 IO_StringIO(PyObject *self, PyObject *args) { |
| 4598 | 630 PyObject *s=0; |
| 631 | |
| 632 UNLESS(PyArg_ParseTuple(args, "|O", &s)) return NULL; | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
633 if(s) return newIobject(s); |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
634 return newOobject(128); |
| 4598 | 635 } |
| 636 | |
| 637 /* List of methods defined in the module */ | |
| 638 | |
| 639 static struct PyMethodDef IO_methods[] = { | |
| 4906 | 640 {"StringIO", (PyCFunction)IO_StringIO, 1, IO_StringIO__doc__}, |
| 641 {NULL, NULL} /* sentinel */ | |
| 4598 | 642 }; |
| 643 | |
| 644 | |
| 645 /* Initialization function for the module (*must* be called initcStringIO) */ | |
| 646 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
647 static struct PycStringIO_CAPI CAPI = { |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
648 O_cread, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
649 O_creadline, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
650 O_cwrite, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
651 O_cgetval, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
652 newOobject, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
653 newIobject, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
654 &Itype, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
655 &Otype, |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
656 }; |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
657 |
| 4598 | 658 void |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
659 initcStringIO() { |
| 4598 | 660 PyObject *m, *d; |
| 661 | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
662 |
| 4598 | 663 /* Create the module and add the functions */ |
| 664 m = Py_InitModule4("cStringIO", IO_methods, | |
| 665 cStringIO_module_documentation, | |
| 666 (PyObject*)NULL,PYTHON_API_VERSION); | |
| 667 | |
| 668 /* Add some symbolic constants to the module */ | |
| 669 d = PyModule_GetDict(m); | |
| 670 | |
| 4906 | 671 /* Export C API */ |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
672 Itype.ob_type=&PyType_Type; |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
673 Otype.ob_type=&PyType_Type; |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
674 PyDict_SetItemString(d,"cStringIO_CAPI", PyCObject_FromVoidPtr(&CAPI,NULL)); |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
675 |
|
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
676 /* Export Types */ |
| 4598 | 677 PyDict_SetItemString(d,"InputType", (PyObject*)&Itype); |
| 678 PyDict_SetItemString(d,"OutputType", (PyObject*)&Otype); | |
| 679 | |
| 680 /* Check for errors */ | |
|
5280
e8f8cf358054
Unknown changes by Jim Fulton.
Guido van Rossum <guido@python.org>
parents:
4957
diff
changeset
|
681 if (PyErr_Occurred()) Py_FatalError("can't initialize module cStringIO"); |
| 4598 | 682 } |
| 4906 | 683 |
