annotate Modules/cStringIO.c @ 6719:faebc1940432 legacy-trunk

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