cStringIO.c 17.9 KB
Newer Older
Guido van Rossum's avatar
Guido van Rossum committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
/*

  $Id$

  A simple fast partial StringIO replacement.



     Copyright 

       Copyright 1996 Digital Creations, L.C., 910 Princess Anne
       Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
       rights reserved.  Copyright in this software is owned by DCLC,
       unless otherwise indicated. Permission to use, copy and
       distribute this software is hereby granted, provided that the
       above copyright notice appear in all copies and that both that
       copyright notice and this permission notice appear. Note that
       any product, process or technology described in this software
       may be the subject of other Intellectual Property rights
       reserved by Digital Creations, L.C. and are not licensed
       hereunder.

     Trademarks 

       Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
       All other trademarks are owned by their respective companies. 

     No Warranty 

       The software is provided "as is" without warranty of any kind,
       either express or implied, including, but not limited to, the
       implied warranties of merchantability, fitness for a particular
       purpose, or non-infringement. This software could include
       technical inaccuracies or typographical errors. Changes are
       periodically made to the software; these changes will be
       incorporated in new editions of the software. DCLC may make
       improvements and/or changes in this software at any time
       without notice.

     Limitation Of Liability 

       In no event will DCLC be liable for direct, indirect, special,
       incidental, economic, cover, or consequential damages arising
       out of the use of or inability to use this software even if
       advised of the possibility of such damages. Some states do not
       allow the exclusion or limitation of implied warranties or
       limitation of liability for incidental or consequential
       damages, so the above limitation or exclusion may not apply to
       you.

    If you have questions regarding this software,
    contact:
   
54
      info@digicool.com
Guido van Rossum's avatar
Guido van Rossum committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
      Digital Creations L.C.  
   
      (540) 371-6909


*/
static char cStringIO_module_documentation[] = 
"A simple fast partial StringIO replacement.\n"
"\n"
"This module provides a simple useful replacement for\n"
"the StringIO module that is written in C.  It does not provide the\n"
"full generality if StringIO, but it provides anough for most\n"
"applications and is especially useful in conjuction with the\n"
"pickle module.\n"
"\n"
"Usage:\n"
"\n"
"  from cStringIO import StringIO\n"
"\n"
"  an_output_stream=StringIO()\n"
"  an_output_stream.write(some_stuff)\n"
"  ...\n"
"  value=an_output_stream.getvalue() # str(an_output_stream) works too!\n"
"\n"
"  an_input_stream=StringIO(a_string)\n"
"  spam=an_input_stream.readline()\n"
"  spam=an_input_stream.read(5)\n"
"  an_input_stream.reset()           # OK, start over, note no seek yet\n"
"  spam=an_input_stream.read()       # and read it all\n"
"  \n"
"If someone else wants to provide a more complete implementation,\n"
"go for it. :-)  \n"
87 88
"\n"
"$Id$\n"
Guido van Rossum's avatar
Guido van Rossum committed
89 90 91 92
;

#include "Python.h"
#include "import.h"
93
#include "cStringIO.h"
Guido van Rossum's avatar
Guido van Rossum committed
94 95 96 97 98 99 100 101

#define UNLESS(E) if(!(E))

/* Declarations for objects of type StringO */

typedef struct {
  PyObject_HEAD
  char *buf;
102
  int pos, string_size, buf_size, closed, softspace;
Guido van Rossum's avatar
Guido van Rossum committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
} Oobject;

/* Declarations for objects of type StringI */

typedef struct {
  PyObject_HEAD
  char *buf;
  int pos, string_size, closed;
  PyObject *pbuf;
} Iobject;

static char O_reset__doc__[] = 
"reset() -- Reset the file position to the beginning"
;

static PyObject *
119
O_reset(Oobject *self, PyObject *args) {
Guido van Rossum's avatar
Guido van Rossum committed
120 121 122 123 124 125 126 127 128 129 130
  self->pos = 0;

  Py_INCREF(Py_None);
  return Py_None;
}


static char O_tell__doc__[] =
"tell() -- get the current position.";

static PyObject *
131
O_tell(Oobject *self, PyObject *args) {
Guido van Rossum's avatar
Guido van Rossum committed
132 133 134 135 136 137 138 139 140
  return PyInt_FromLong(self->pos);
}


static char O_seek__doc__[] =
"seek(position)       -- set the current position\n"
"seek(position, mode) -- mode 0: absolute; 1: relative; 2: relative to EOF";

static PyObject *
141
O_seek(Oobject *self, PyObject *args) {
Guido van Rossum's avatar
Guido van Rossum committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
  int position, mode = 0;

  UNLESS(PyArg_ParseTuple(args, "i|i", &position, &mode))
  {
    return NULL;
  }

  if (mode == 2)
  {
    position += self->string_size;
  }
  else if (mode == 1)
  {
    position += self->pos;
  }

  self->pos = (position > self->string_size ? self->string_size : 
	       (position < 0 ? 0 : position));

Guido van Rossum's avatar
Guido van Rossum committed
161 162
  Py_INCREF(Py_None);
  return Py_None;
Guido van Rossum's avatar
Guido van Rossum committed
163 164 165 166 167 168 169
}

static char O_read__doc__[] = 
"read([s]) -- Read s characters, or the rest of the string"
;

static int
170
O_cread(PyObject *self, char **output, int  n) {
Guido van Rossum's avatar
Guido van Rossum committed
171 172
  int l;

173
  l = ((Oobject*)self)->string_size - ((Oobject*)self)->pos;  
Guido van Rossum's avatar
Guido van Rossum committed
174 175 176 177 178
  if (n < 0 || n > l)
  {
    n = l;
  }

179 180
  *output=((Oobject*)self)->buf + ((Oobject*)self)->pos;
  ((Oobject*)self)->pos += n;
Guido van Rossum's avatar
Guido van Rossum committed
181 182 183 184
  return n;
}

static PyObject *
185
O_read(Oobject *self, PyObject *args) {
Guido van Rossum's avatar
Guido van Rossum committed
186 187 188 189 190
  int n = -1;
  char *output;

  UNLESS(PyArg_ParseTuple(args, "|i", &n)) return NULL;

191
  n=O_cread((PyObject*)self,&output,n);
Guido van Rossum's avatar
Guido van Rossum committed
192 193 194 195 196 197 198 199 200 201

  return PyString_FromStringAndSize(output, n);
}


static char O_readline__doc__[] = 
"readline() -- Read one line"
;

static int
202
O_creadline(PyObject *self, char **output) {
Guido van Rossum's avatar
Guido van Rossum committed
203 204 205
  char *n, *s;
  int l;

206 207
  for (n = ((Oobject*)self)->buf + ((Oobject*)self)->pos,
	 s = ((Oobject*)self)->buf + ((Oobject*)self)->string_size; 
Guido van Rossum's avatar
Guido van Rossum committed
208 209 210
       n < s && *n != '\n'; n++);
  if (n < s) n++;
 
211 212 213
  *output=((Oobject*)self)->buf + ((Oobject*)self)->pos;
  l = n - ((Oobject*)self)->buf - ((Oobject*)self)->pos;
  ((Oobject*)self)->pos += l;
Guido van Rossum's avatar
Guido van Rossum committed
214 215 216 217
  return l;
}

static PyObject *
218
O_readline(Oobject *self, PyObject *args) {
Guido van Rossum's avatar
Guido van Rossum committed
219 220 221
  int n;
  char *output;

222
  n=O_creadline((PyObject*)self,&output);
Guido van Rossum's avatar
Guido van Rossum committed
223 224 225 226 227 228 229 230 231 232
  return PyString_FromStringAndSize(output, n);
}

static char O_write__doc__[] = 
"write(s) -- Write a string to the file"
"\n\nNote (hack:) writing None resets the buffer"
;


static int
233
O_cwrite(PyObject *self, char *c, int  l) {
234
  int newl;
Guido van Rossum's avatar
Guido van Rossum committed
235

236 237
  newl=((Oobject*)self)->pos+l;
  if(newl >= ((Oobject*)self)->buf_size)
Guido van Rossum's avatar
Guido van Rossum committed
238
    {
239 240 241 242 243
      ((Oobject*)self)->buf_size*=2;
      if(((Oobject*)self)->buf_size <= newl) ((Oobject*)self)->buf_size=newl+1;
      UNLESS(((Oobject*)self)->buf=
	     (char*)realloc(((Oobject*)self)->buf,
			    (((Oobject*)self)->buf_size) *sizeof(char)))
Guido van Rossum's avatar
Guido van Rossum committed
244 245
	{
	  PyErr_SetString(PyExc_MemoryError,"out of memory");
246
	  ((Oobject*)self)->buf_size=((Oobject*)self)->pos=0;
Guido van Rossum's avatar
Guido van Rossum committed
247 248 249 250
	  return -1;
	}
    }

251
  memcpy(((Oobject*)((Oobject*)self))->buf+((Oobject*)self)->pos,c,l);
Guido van Rossum's avatar
Guido van Rossum committed
252

253
  ((Oobject*)self)->pos += l;
Guido van Rossum's avatar
Guido van Rossum committed
254

255
  if (((Oobject*)self)->string_size < ((Oobject*)self)->pos)
Guido van Rossum's avatar
Guido van Rossum committed
256
    {
257
      ((Oobject*)self)->string_size = ((Oobject*)self)->pos;
Guido van Rossum's avatar
Guido van Rossum committed
258 259 260 261 262 263
    }

  return l;
}

static PyObject *
264
O_write(Oobject *self, PyObject *args) {
Guido van Rossum's avatar
Guido van Rossum committed
265
  PyObject *s;
266 267
  char *c;
  int l;
Guido van Rossum's avatar
Guido van Rossum committed
268 269

  UNLESS(PyArg_Parse(args, "O", &s)) return NULL;
Guido van Rossum's avatar
Guido van Rossum committed
270 271
  UNLESS(-1 != (l=PyString_Size(s))) return NULL;
  UNLESS(c=PyString_AsString(s)) return NULL;
272
  UNLESS(-1 != O_cwrite((PyObject*)self,c,l)) return NULL;
Guido van Rossum's avatar
Guido van Rossum committed
273

Guido van Rossum's avatar
Guido van Rossum committed
274 275
  Py_INCREF(Py_None);
  return Py_None;
Guido van Rossum's avatar
Guido van Rossum committed
276 277 278
}

static PyObject *
279
O_getval(Oobject *self, PyObject *args) {
280 281 282 283 284 285 286 287
  PyObject *use_pos;
  int s;

  use_pos=Py_None;
  UNLESS(PyArg_ParseTuple(args,"|O",&use_pos)) return NULL;
  if(PyObject_IsTrue(use_pos)) s=self->pos;
  else                         s=self->string_size;
  return PyString_FromStringAndSize(self->buf, s);
288 289 290 291 292 293
}

static PyObject *
O_cgetval(PyObject *self) {
  return PyString_FromStringAndSize(((Oobject*)self)->buf,
				    ((Oobject*)self)->pos);
Guido van Rossum's avatar
Guido van Rossum committed
294 295 296 297 298 299
}

static char O_truncate__doc__[] = 
"truncate(): truncate the file at the current position.";

static PyObject *
300
O_truncate(Oobject *self, PyObject *args) {
Guido van Rossum's avatar
Guido van Rossum committed
301 302 303 304 305 306 307 308
  self->string_size = self->pos;
  Py_INCREF(Py_None);
  return Py_None;
}

static char O_isatty__doc__[] = "isatty(): always returns 0";

static PyObject *
309
O_isatty(Oobject *self, PyObject *args) {
Guido van Rossum's avatar
Guido van Rossum committed
310 311 312 313 314 315
  return PyInt_FromLong(0);
}

static char O_close__doc__[] = "close(): explicitly release resources held.";

static PyObject *
316
O_close(Oobject *self, PyObject *args) {
317 318 319
  if (self->buf != NULL)
    free(self->buf);
  self->buf = NULL;
Guido van Rossum's avatar
Guido van Rossum committed
320 321 322 323 324 325 326 327 328 329 330

  self->pos = self->string_size = self->buf_size = 0;
  self->closed = 1;

  Py_INCREF(Py_None);
  return Py_None;
}

static char O_flush__doc__[] = "flush(): does nothing.";

static PyObject *
331
O_flush(Oobject *self, PyObject *args) {
Guido van Rossum's avatar
Guido van Rossum committed
332 333 334 335 336 337 338
  Py_INCREF(Py_None);
  return Py_None;
}


static char O_writelines__doc__[] = "blah";
static PyObject *
339
O_writelines(Oobject *self, PyObject *args) {
Guido van Rossum's avatar
Guido van Rossum committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
  PyObject *string_module = 0;
  static PyObject *string_joinfields = 0;

  UNLESS(PyArg_Parse(args, "O", args))
  {
    return NULL;
  }

  if (!string_joinfields)
  {
    UNLESS(string_module = PyImport_ImportModule("string"))
    {
      return NULL;
    }

    UNLESS(string_joinfields=
        PyObject_GetAttrString(string_module, "joinfields"))
    {
      return NULL;
    }

    Py_DECREF(string_module);
  }

  if (PyObject_Length(args) == -1)
  {
    return NULL;
  }

  return O_write(self, 
      PyObject_CallFunction(string_joinfields, "Os", args, ""));
}

static struct PyMethodDef O_methods[] = {
374
  {"write",	 (PyCFunction)O_write,        0,      O_write__doc__},
Guido van Rossum's avatar
Guido van Rossum committed
375 376 377 378 379
  {"read",       (PyCFunction)O_read,         1,      O_read__doc__},
  {"readline",   (PyCFunction)O_readline,     0,      O_readline__doc__},
  {"reset",      (PyCFunction)O_reset,        0,      O_reset__doc__},
  {"seek",       (PyCFunction)O_seek,         1,      O_seek__doc__},
  {"tell",       (PyCFunction)O_tell,         0,      O_tell__doc__},
380 381 382 383 384 385
  {"getvalue",   (PyCFunction)O_getval,       1,
   "getvalue([use_pos]) -- Get the string value."
   "\n"
   "If use_pos is specified and is a true value, then the string returned\n"
   "will include only the text up to the current file position.\n"
  },
Guido van Rossum's avatar
Guido van Rossum committed
386 387 388 389 390 391 392 393 394 395
  {"truncate",   (PyCFunction)O_truncate,     0,      O_truncate__doc__},
  {"isatty",     (PyCFunction)O_isatty,       0,      O_isatty__doc__},
  {"close",      (PyCFunction)O_close,        0,      O_close__doc__},
  {"flush",      (PyCFunction)O_flush,        0,      O_flush__doc__},
  {"writelines", (PyCFunction)O_writelines,   0,      O_writelines__doc__},
  {NULL,		NULL}		/* sentinel */
};


static void
396
O_dealloc(Oobject *self) {
397 398
  if (self->buf != NULL)
    free(self->buf);
Guido van Rossum's avatar
Guido van Rossum committed
399 400 401 402
  PyMem_DEL(self);
}

static PyObject *
403
O_getattr(Oobject *self, char *name) {
404 405 406
  if (strcmp(name, "softspace") == 0) {
	  return PyInt_FromLong(self->softspace);
  }
Guido van Rossum's avatar
Guido van Rossum committed
407 408 409
  return Py_FindMethod(O_methods, (PyObject *)self, name);
}

410 411 412 413 414 415 416 417 418 419 420 421 422 423
static int
O_setattr(Oobject *self, char *name, PyObject *value) {
	long x;
	if (strcmp(name, "softspace") != 0) {
		PyErr_SetString(PyExc_AttributeError, name);
		return -1;
	}
	x = PyInt_AsLong(value);
	if (x == -1 && PyErr_Occurred())
		return -1;
	self->softspace = x;
	return 0;
}

Guido van Rossum's avatar
Guido van Rossum committed
424 425 426 427 428
static char Otype__doc__[] = 
"Simple type for output to strings."
;

static PyTypeObject Otype = {
429 430 431 432 433 434 435 436 437
  PyObject_HEAD_INIT(NULL)
  0,	       		/*ob_size*/
  "StringO",     		/*tp_name*/
  sizeof(Oobject),       	/*tp_basicsize*/
  0,	       		/*tp_itemsize*/
  /* methods */
  (destructor)O_dealloc,	/*tp_dealloc*/
  (printfunc)0,		/*tp_print*/
  (getattrfunc)O_getattr,	/*tp_getattr*/
438
  (setattrfunc)O_setattr,	/*tp_setattr*/
439 440 441 442 443 444 445 446 447 448 449 450
  (cmpfunc)0,		/*tp_compare*/
  (reprfunc)0,		/*tp_repr*/
  0,			/*tp_as_number*/
  0,			/*tp_as_sequence*/
  0,			/*tp_as_mapping*/
  (hashfunc)0,		/*tp_hash*/
  (ternaryfunc)0,		/*tp_call*/
  (reprfunc)0,		/*tp_str*/
  
  /* Space for future expansion */
  0L,0L,0L,0L,
  Otype__doc__ 		/* Documentation string */
Guido van Rossum's avatar
Guido van Rossum committed
451 452
};

453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
static PyObject *
newOobject(int  size) {
  Oobject *self;
	
  self = PyObject_NEW(Oobject, &Otype);
  if (self == NULL)
    return NULL;
  self->pos=0;
  self->closed = 0;
  self->string_size = 0;
  self->softspace = 0;

  UNLESS(self->buf=malloc(size*sizeof(char)))
    {
      PyErr_SetString(PyExc_MemoryError,"out of memory");
      self->buf_size = 0;
      return NULL;
    }

  self->buf_size=size;
  return (PyObject*)self;
}

Guido van Rossum's avatar
Guido van Rossum committed
476 477 478 479
/* End of code for StringO objects */
/* -------------------------------------------------------- */

static PyObject *
480
I_close(Iobject *self, PyObject *args) {
481 482
  Py_XDECREF(self->pbuf);
  self->pbuf = NULL;
Guido van Rossum's avatar
Guido van Rossum committed
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504

  self->pos = self->string_size = 0;
  self->closed = 1;

  Py_INCREF(Py_None);
  return Py_None;
}

static struct PyMethodDef I_methods[] = {
  {"read",	(PyCFunction)O_read,         1,      O_read__doc__},
  {"readline",	(PyCFunction)O_readline,	0,	O_readline__doc__},
  {"reset",	(PyCFunction)O_reset,	0,	O_reset__doc__},
  {"seek",      (PyCFunction)O_seek,         1,      O_seek__doc__},  
  {"tell",      (PyCFunction)O_tell,         0,      O_tell__doc__},
  {"truncate",  (PyCFunction)O_truncate,     0,      O_truncate__doc__},
  {"isatty",    (PyCFunction)O_isatty,       0,      O_isatty__doc__},
  {"close",     (PyCFunction)I_close,        0,      O_close__doc__},
  {"flush",     (PyCFunction)O_flush,        0,      O_flush__doc__},
  {NULL,		NULL}		/* sentinel */
};

static void
505
I_dealloc(Iobject *self) {
506
  Py_XDECREF(self->pbuf);
Guido van Rossum's avatar
Guido van Rossum committed
507 508 509 510
  PyMem_DEL(self);
}

static PyObject *
511
I_getattr(Iobject *self, char *name) {
Guido van Rossum's avatar
Guido van Rossum committed
512 513 514 515 516 517 518 519
  return Py_FindMethod(I_methods, (PyObject *)self, name);
}

static char Itype__doc__[] = 
"Simple type for treating strings as input file streams"
;

static PyTypeObject Itype = {
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
  PyObject_HEAD_INIT(NULL)
  0,		       	/*ob_size*/
  "StringI",	       	/*tp_name*/
  sizeof(Iobject),       	/*tp_basicsize*/
  0,		       	/*tp_itemsize*/
  /* methods */
  (destructor)I_dealloc,	/*tp_dealloc*/
  (printfunc)0,		/*tp_print*/
  (getattrfunc)I_getattr,	/*tp_getattr*/
  (setattrfunc)0,		/*tp_setattr*/
  (cmpfunc)0,		/*tp_compare*/
  (reprfunc)0,		/*tp_repr*/
  0,			/*tp_as_number*/
  0,			/*tp_as_sequence*/
  0,			/*tp_as_mapping*/
  (hashfunc)0,		/*tp_hash*/
  (ternaryfunc)0,		/*tp_call*/
  (reprfunc)0,		/*tp_str*/
  
  /* Space for future expansion */
  0L,0L,0L,0L,
  Itype__doc__ 		/* Documentation string */
Guido van Rossum's avatar
Guido van Rossum committed
542 543
};

544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
static PyObject *
newIobject(PyObject *s) {
  Iobject *self;
  char *buf;
  int size;
	
  UNLESS(buf=PyString_AsString(s)) return NULL;
  UNLESS(-1 != (size=PyString_Size(s))) return NULL;
  UNLESS(self = PyObject_NEW(Iobject, &Itype)) return NULL;
  Py_INCREF(s);
  self->buf=buf;
  self->string_size=size;
  self->pbuf=s;
  self->pos=0;
  self->closed = 0;
  
  return (PyObject*)self;
}

Guido van Rossum's avatar
Guido van Rossum committed
563 564 565 566 567 568 569 570 571
/* End of code for StringI objects */
/* -------------------------------------------------------- */


static char IO_StringIO__doc__[] =
"StringIO([s]) -- Return a StringIO-like stream for reading or writing"
;

static PyObject *
572
IO_StringIO(PyObject *self, PyObject *args) {
Guido van Rossum's avatar
Guido van Rossum committed
573 574 575
  PyObject *s=0;

  UNLESS(PyArg_ParseTuple(args, "|O", &s)) return NULL;
576 577
  if(s) return newIobject(s);
  return newOobject(128);
Guido van Rossum's avatar
Guido van Rossum committed
578 579 580 581 582
}

/* List of methods defined in the module */

static struct PyMethodDef IO_methods[] = {
Guido van Rossum's avatar
Guido van Rossum committed
583 584
  {"StringIO",	(PyCFunction)IO_StringIO,	1,	IO_StringIO__doc__},
  {NULL,		NULL}		/* sentinel */
Guido van Rossum's avatar
Guido van Rossum committed
585 586 587 588 589
};


/* Initialization function for the module (*must* be called initcStringIO) */

590 591 592 593 594 595 596 597 598 599 600
static struct PycStringIO_CAPI CAPI = {
  O_cread,
  O_creadline,
  O_cwrite,
  O_cgetval,
  newOobject,
  newIobject,
  &Itype,
  &Otype,
};

Guido van Rossum's avatar
Guido van Rossum committed
601
void
602
initcStringIO() {
603
  PyObject *m, *d, *v;
Guido van Rossum's avatar
Guido van Rossum committed
604

605

Guido van Rossum's avatar
Guido van Rossum committed
606 607 608 609 610 611 612 613
  /* Create the module and add the functions */
  m = Py_InitModule4("cStringIO", IO_methods,
		     cStringIO_module_documentation,
		     (PyObject*)NULL,PYTHON_API_VERSION);

  /* Add some symbolic constants to the module */
  d = PyModule_GetDict(m);
  
Guido van Rossum's avatar
Guido van Rossum committed
614
  /* Export C API */
615 616
  Itype.ob_type=&PyType_Type;
  Otype.ob_type=&PyType_Type;
617 618 619
  PyDict_SetItemString(d,"cStringIO_CAPI",
		       v = PyCObject_FromVoidPtr(&CAPI,NULL));
  Py_XDECREF(v);
620 621

  /* Export Types */
Guido van Rossum's avatar
Guido van Rossum committed
622 623
  PyDict_SetItemString(d,"InputType",  (PyObject*)&Itype);
  PyDict_SetItemString(d,"OutputType", (PyObject*)&Otype);
624 625 626

  /* Maybe make certain warnings go away */
  if(0) PycString_IMPORT;
Guido van Rossum's avatar
Guido van Rossum committed
627 628
  
  /* Check for errors */
629
  if (PyErr_Occurred()) Py_FatalError("can't initialize module cStringIO");
Guido van Rossum's avatar
Guido van Rossum committed
630
}
Guido van Rossum's avatar
Guido van Rossum committed
631

632 633 634 635

/******************************************************************************

  $Log$
636 637 638
  Revision 2.8  1997/09/03 18:19:38  guido
  #Plug small memory leaks in constructors.

639 640 641 642 643 644 645 646 647 648 649
  Revision 2.7  1997/09/03 00:09:26  guido
  Fix the bug Jeremy was experiencing: both the close() and the
  dealloc() functions contained code to free/DECREF the buffer
  (there were differences between I and O objects but the logic bug was
  the same).  Fixed this be setting the buffer pointer to NULL and
  testing for that.  (This also makes it safe to call close() more than
  once.)

  XXX Worry: what if you try to read() or write() once the thing is
  closed?

650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
  Revision 2.6  1997/08/13 03:14:41  guido
  cPickle release 0.3 from Jim Fulton

  Revision 1.21  1997/06/19 18:51:42  jim
  Added ident string.

  Revision 1.20  1997/06/13 20:50:50  jim
  - Various changes to make gcc -Wall -pedantic happy, including
    getting rid of staticforward declarations and adding pretend use
    of two statics defined in .h file.

  Revision 1.19  1997/06/02 18:15:17  jim
  Merged in guido's changes.

  Revision 1.18  1997/05/07 16:26:47  jim
  getvalue() can nor be given an argument.  If this argument is true,
  then getvalue returns the text upto the current position.  Otherwise
  it returns all of the text.  The default value of the argument is
  false.

  Revision 1.17  1997/04/17 18:02:46  chris
  getvalue() now returns entire string, not just the string up to
  current position

  Revision 2.5  1997/04/11 19:56:06  guido
  My own patch: support writable 'softspace' attribute.

  > Jim asked: What is softspace for?
  
  It's an old feature.  The print statement uses this to remember
  whether it should insert a space before the next item or not.
  Implementation is in fileobject.c.

  Revision 1.11  1997/01/23 20:45:01  jim
  ANSIfied it.
  Changed way C API was exported.

  Revision 1.10  1997/01/02 15:19:55  chris
  checked in to be sure repository is up to date.

  Revision 1.9  1996/12/27 21:40:29  jim
  Took out some lamosities in interface, like returning self from
  write.

  Revision 1.8  1996/12/23 15:52:49  jim
  Added ifdef to check for CObject before using it.

  Revision 1.7  1996/12/23 15:22:35  jim
  Finished implementation, adding full compatibility with StringIO, and
  then some.

 *****************************************************************************/