annotate Include/cStringIO.h @ 4963:5ded2bc1908b legacy-trunk

"ported" Guido's embedding demo to the mac, and wrote some minimal notes on embedding on the mac.
author Jack Jansen <jack.jansen@cwi.nl>
date Wed, 15 Jan 1997 16:53:37 +0000
parents d46e478b5767
children 16372a4c4c14
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 #ifndef CSTRINGIO_INCLUDED
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 #define CSTRINGIO_INCLUDED
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 /*
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 $Id$
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 cStringIO C API
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
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 info@digicool.com
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 This header provides access to cStringIO objects from C.
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 Functions are provided for calling cStringIO objects and
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 macros are provided for testing whether you have cStringIO
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 objects.
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
64
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 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
66 the routines with:
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 PycStringIO_IMPORT
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
69
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 This would typically be done in your init function.
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
71
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 $Log$
4902
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
73 Revision 2.2 1997/01/06 22:50:12 guido
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
74 Jim's latest version
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
75
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
76 Revision 1.1 1997/01/02 15:18:36 chris
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
77 initial version
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
78
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
79
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 */
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 /* Basic fuctions to manipulate cStringIO objects from C */
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 /* Read a string. If the last argument is -1, the remainder will be read. */
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 static int(*PycStringIO_cread)(PyObject *, char **, int)=NULL;
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 /* Read a line */
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 static int(*PycStringIO_creadline)(PyObject *, char **)=NULL;
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 /* Write a string */
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 static int(*PycStringIO_cwrite)(PyObject *, char *, int)=NULL;
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
92
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 /* Get the cStringIO object as a Python string */
4902
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
94 static PyObject *(*PycStringIO_cgetvalue)(PyObject *)=NULL;
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 /* Create a new output object */
4902
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
97 static PyObject *(*PycStringIO_NewOutput)(int)=NULL;
4598
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 /* Create an input object from a Python string */
4902
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
100 static PyObject *(*PycStringIO_NewInput)(PyObject *)=NULL;
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
101
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 /* The Python types for cStringIO input and output objects.
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 Note that you can do input on an output object.
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 static PyObject *PycStringIO_InputType=NULL, *PycStringIO_OutputType=NULL;
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 /* 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
108 #define PycStringIO_InputCheck(O) \
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
109 ((O)->ob_type==(PyTypeObject*)PycStringIO_InputType)
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
110 #define PycStringIO_OutputCheck(O) \
d46e478b5767 Jim's latest version
Guido van Rossum <guido@python.org>
parents: 4598
diff changeset
111 ((O)->ob_type==(PyTypeObject*)PycStringIO_OutputType)
4598
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
112
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 /* The following is used to implement PycString_IMPORT: */
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 static PyObject *PycStringIO_Module=NULL, *PycStringIO_CObject=NULL;
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
115
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 #define IMPORT_C_OBJECT(N) \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 if((PycStringIO_CObject=PyObject_GetAttrString(PycStringIO_Module, #N))) { \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 PycStringIO_ ## N = PyCObject_AsVoidPtr(PycStringIO_CObject); \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 Py_DECREF(PycStringIO_CObject); }
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
120
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 #define PycString_IMPORT \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 if((PycStringIO_Module=PyImport_ImportModule("cStringIO"))) { \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 PycStringIO_InputType=PyObject_GetAttrString(PycStringIO_Module, \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 "InputType"); \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 PycStringIO_OutputType=PyObject_GetAttrString(PycStringIO_Module, \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 "OutputType"); \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 IMPORT_C_OBJECT(cread); \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 IMPORT_C_OBJECT(creadline); \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 IMPORT_C_OBJECT(cwrite); \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 IMPORT_C_OBJECT(NewInput); \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 IMPORT_C_OBJECT(NewOutput); \
8fdb0539cfb1 Jim F's brainchild
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 IMPORT_C_OBJECT(cgetvalue); }
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 #endif /* CSTRINGIO_INCLUDED */