annotate Include/cStringIO.h @ 25838:8540887bcec6 2.2

Backport of 2.183: Fix memory leak in add_subclass() found by NealN with valgrind.
author Guido van Rossum <guido@python.org>
date Fri, 18 Oct 2002 13:42:21 +0000
parents 488295d1ba11
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25555
488295d1ba11 Backport last checkin:
Neal Norwitz <nnorwitz@gmail.com>
parents: 25553
diff changeset
1 #ifndef Py_CSTRINGIO_H
488295d1ba11 Backport last checkin:
Neal Norwitz <nnorwitz@gmail.com>
parents: 25553
diff changeset
2 #define Py_CSTRINGIO_H
25553
f61d1d2b9ce3 Backport patch (also pointed out in SF #607253):
Neal Norwitz <nnorwitz@gmail.com>
parents: 18064
diff changeset
3 #ifdef __cplusplus
f61d1d2b9ce3 Backport patch (also pointed out in SF #607253):
Neal Norwitz <nnorwitz@gmail.com>
parents: 18064
diff changeset
4 extern "C" {
f61d1d2b9ce3 Backport patch (also pointed out in SF #607253):
Neal Norwitz <nnorwitz@gmail.com>
parents: 18064
diff changeset
5 #endif
4598
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
6775
3117af9dbfce Remove the last bits of log from the leading comments.
Guido van Rossum <guido@python.org>
parents: 6741
diff changeset
8 cStringIO.h,v 1.4 1997/12/07 14:27:00 jim Exp
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 cStringIO C API
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 Copyright
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 Copyright 1996 Digital Creations, L.C., 910 Princess Anne
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 rights reserved. Copyright in this software is owned by DCLC,
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 unless otherwise indicated. Permission to use, copy and
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 distribute this software is hereby granted, provided that the
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 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
20 copyright notice and this permission notice appear. Note that
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 any product, process or technology described in this software
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 may be the subject of other Intellectual Property rights
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 reserved by Digital Creations, L.C. and are not licensed
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 hereunder.
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 Trademarks
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 Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 All other trademarks are owned by their respective companies.
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 No Warranty
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
32
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 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
34 either express or implied, including, but not limited to, the
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 implied warranties of merchantability, fitness for a particular
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 purpose, or non-infringement. This software could include
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 technical inaccuracies or typographical errors. Changes are
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 periodically made to the software; these changes will be
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 incorporated in new editions of the software. DCLC may make
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 improvements and/or changes in this software at any time
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 without notice.
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 Limitation Of Liability
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 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
46 incidental, economic, cover, or consequential damages arising
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 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
48 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
49 allow the exclusion or limitation of implied warranties or
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 limitation of liability for incidental or consequential
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 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
52 you.
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 If you have questions regarding this software,
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 contact:
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 info@digicool.com
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 Digital Creations L.C.
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 (540) 371-6909
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
61
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
62
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 This header provides access to cStringIO objects from C.
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 Functions are provided for calling cStringIO objects and
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 macros are provided for testing whether you have cStringIO
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 objects.
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 Before calling any of the functions or macros, you must initialize
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 the routines with:
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
9944
396a38ea9b84 There's a macro PycString_IMPORT which the documentation listed as
Guido van Rossum <guido@python.org>
parents: 9605
diff changeset
71 PycString_IMPORT
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
72
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 This would typically be done in your init function.
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 */
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
77 /* Basic functions to manipulate cStringIO objects from C */
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
78
5279
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
79 static struct PycStringIO_CAPI {
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
80
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
81 /* Read a string. If the last argument is -1, the remainder will be read. */
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 9944
diff changeset
82 int(*cread)(PyObject *, char **, int);
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
5279
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
84 /* Read a line */
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 9944
diff changeset
85 int(*creadline)(PyObject *, char **);
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
5279
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
87 /* Write a string */
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 9944
diff changeset
88 int(*cwrite)(PyObject *, char *, int);
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
5279
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
90 /* Get the cStringIO object as a Python string */
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 9944
diff changeset
91 PyObject *(*cgetvalue)(PyObject *);
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
5279
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
93 /* Create a new output object */
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 9944
diff changeset
94 PyObject *(*NewOutput)(int);
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
5279
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
96 /* Create an input object from a Python string */
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 9944
diff changeset
97 PyObject *(*NewInput)(PyObject *);
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
98
5279
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
99 /* The Python types for cStringIO input and output objects.
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
100 Note that you can do input on an output object.
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
101 */
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
102 PyTypeObject *InputType, *OutputType;
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
103
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
104 } * PycStringIO = NULL;
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
105
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 /* These can be used to test if you have one */
4902
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
107 #define PycStringIO_InputCheck(O) \
5279
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
108 ((O)->ob_type==PycStringIO->InputType)
4902
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
109 #define PycStringIO_OutputCheck(O) \
5279
16372a4c4c14 Changed the way the C API was exported. Jim Fulton.
Guido van Rossum <guido@python.org>
parents: 4902
diff changeset
110 ((O)->ob_type==PycStringIO->OutputType)
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
111
9605
6b59f9ab5db1 Undo the change here -- there's no point in declaring a static
Guido van Rossum <guido@python.org>
parents: 9586
diff changeset
112 static void *
13660
a1ce07218781 Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents: 13620
diff changeset
113 xxxPyCObject_Import(char *module_name, char *name)
5991
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
114 {
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
115 PyObject *m, *c;
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
116 void *r=NULL;
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
117
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
118 if((m=PyImport_ImportModule(module_name)))
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
119 {
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
120 if((c=PyObject_GetAttrString(m,name)))
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
121 {
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
122 r=PyCObject_AsVoidPtr(c);
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
123 Py_DECREF(c);
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
124 }
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
125 Py_DECREF(m);
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
126 }
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
127
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
128 return r;
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
129 }
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5284
diff changeset
130
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 #define PycString_IMPORT \
18064
ac5489a2548d Cast the result of xxxPyCObject_Import to PycStringIO_CAPI*.
Martin v. Löwis <martin@v.loewis.de>
parents: 13660
diff changeset
132 PycStringIO=(struct PycStringIO_CAPI*)xxxPyCObject_Import("cStringIO", "cStringIO_CAPI")
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
133
25553
f61d1d2b9ce3 Backport patch (also pointed out in SF #607253):
Neal Norwitz <nnorwitz@gmail.com>
parents: 18064
diff changeset
134 #ifdef __cplusplus
f61d1d2b9ce3 Backport patch (also pointed out in SF #607253):
Neal Norwitz <nnorwitz@gmail.com>
parents: 18064
diff changeset
135 }
f61d1d2b9ce3 Backport patch (also pointed out in SF #607253):
Neal Norwitz <nnorwitz@gmail.com>
parents: 18064
diff changeset
136 #endif
25555
488295d1ba11 Backport last checkin:
Neal Norwitz <nnorwitz@gmail.com>
parents: 25553
diff changeset
137 #endif /* !Py_CSTRINGIO_H */