blob: 6a2532dd0b40e6d67db83915c1ec65790aa5b6e5 [file] [log] [blame]
Guido van Rossum049cd901996-12-05 23:30:48 +00001#ifndef CSTRINGIO_INCLUDED
2#define CSTRINGIO_INCLUDED
3/*
4
Guido van Rossum36facb01997-12-04 01:14:08 +00005 cStringIO.h,v 1.3 1997/06/13 19:44:02 jim Exp
Guido van Rossum049cd901996-12-05 23:30:48 +00006
7 cStringIO C API
8
9 Copyright
10
11 Copyright 1996 Digital Creations, L.C., 910 Princess Anne
12 Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
13 rights reserved. Copyright in this software is owned by DCLC,
14 unless otherwise indicated. Permission to use, copy and
15 distribute this software is hereby granted, provided that the
16 above copyright notice appear in all copies and that both that
17 copyright notice and this permission notice appear. Note that
18 any product, process or technology described in this software
19 may be the subject of other Intellectual Property rights
20 reserved by Digital Creations, L.C. and are not licensed
21 hereunder.
22
23 Trademarks
24
25 Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
26 All other trademarks are owned by their respective companies.
27
28 No Warranty
29
30 The software is provided "as is" without warranty of any kind,
31 either express or implied, including, but not limited to, the
32 implied warranties of merchantability, fitness for a particular
33 purpose, or non-infringement. This software could include
34 technical inaccuracies or typographical errors. Changes are
35 periodically made to the software; these changes will be
36 incorporated in new editions of the software. DCLC may make
37 improvements and/or changes in this software at any time
38 without notice.
39
40 Limitation Of Liability
41
42 In no event will DCLC be liable for direct, indirect, special,
43 incidental, economic, cover, or consequential damages arising
44 out of the use of or inability to use this software even if
45 advised of the possibility of such damages. Some states do not
46 allow the exclusion or limitation of implied warranties or
47 limitation of liability for incidental or consequential
48 damages, so the above limitation or exclusion may not apply to
49 you.
50
51 If you have questions regarding this software,
52 contact:
53
54 info@digicool.com
55 Digital Creations L.C.
56
57 (540) 371-6909
58
59
60 This header provides access to cStringIO objects from C.
61 Functions are provided for calling cStringIO objects and
62 macros are provided for testing whether you have cStringIO
63 objects.
64
65 Before calling any of the functions or macros, you must initialize
66 the routines with:
67
68 PycStringIO_IMPORT
69
70 This would typically be done in your init function.
71
Guido van Rossum36facb01997-12-04 01:14:08 +000072 cStringIO.h,v
Guido van Rossum142eeb81997-08-13 03:14:41 +000073 Revision 1.3 1997/06/13 19:44:02 jim
74 - changed to avoid warning of multiple declarations in 1.5 and
75 our 1.4.
Guido van Rossum0a73dd51997-04-09 17:34:28 +000076
77 Revision 1.2 1997/01/27 14:13:05 jim
78 Changed the way the C API was exported.
Guido van Rossumd81a1ba1997-01-06 22:50:12 +000079
80 Revision 1.1 1997/01/02 15:18:36 chris
81 initial version
Guido van Rossum049cd901996-12-05 23:30:48 +000082
83
84*/
85
Guido van Rossum049cd901996-12-05 23:30:48 +000086/* Basic fuctions to manipulate cStringIO objects from C */
87
Guido van Rossum0a73dd51997-04-09 17:34:28 +000088static struct PycStringIO_CAPI {
89
90 /* Read a string. If the last argument is -1, the remainder will be read. */
Guido van Rossumeec6ef11997-10-07 14:44:48 +000091 int(*cread) Py_FPROTO((PyObject *, char **, int));
Guido van Rossum049cd901996-12-05 23:30:48 +000092
Guido van Rossum0a73dd51997-04-09 17:34:28 +000093 /* Read a line */
Guido van Rossumeec6ef11997-10-07 14:44:48 +000094 int(*creadline) Py_FPROTO((PyObject *, char **));
Guido van Rossum049cd901996-12-05 23:30:48 +000095
Guido van Rossum0a73dd51997-04-09 17:34:28 +000096 /* Write a string */
Guido van Rossumeec6ef11997-10-07 14:44:48 +000097 int(*cwrite) Py_FPROTO((PyObject *, char *, int));
Guido van Rossum049cd901996-12-05 23:30:48 +000098
Guido van Rossum0a73dd51997-04-09 17:34:28 +000099 /* Get the cStringIO object as a Python string */
Guido van Rossumeec6ef11997-10-07 14:44:48 +0000100 PyObject *(*cgetvalue) Py_FPROTO((PyObject *));
Guido van Rossum049cd901996-12-05 23:30:48 +0000101
Guido van Rossum0a73dd51997-04-09 17:34:28 +0000102 /* Create a new output object */
Guido van Rossumeec6ef11997-10-07 14:44:48 +0000103 PyObject *(*NewOutput) Py_FPROTO((int));
Guido van Rossum049cd901996-12-05 23:30:48 +0000104
Guido van Rossum0a73dd51997-04-09 17:34:28 +0000105 /* Create an input object from a Python string */
Guido van Rossumeec6ef11997-10-07 14:44:48 +0000106 PyObject *(*NewInput) Py_FPROTO((PyObject *));
Guido van Rossum049cd901996-12-05 23:30:48 +0000107
Guido van Rossum0a73dd51997-04-09 17:34:28 +0000108 /* The Python types for cStringIO input and output objects.
109 Note that you can do input on an output object.
110 */
111 PyTypeObject *InputType, *OutputType;
112
113} * PycStringIO = NULL;
Guido van Rossum049cd901996-12-05 23:30:48 +0000114
115/* These can be used to test if you have one */
Guido van Rossumd81a1ba1997-01-06 22:50:12 +0000116#define PycStringIO_InputCheck(O) \
Guido van Rossum0a73dd51997-04-09 17:34:28 +0000117 ((O)->ob_type==PycStringIO->InputType)
Guido van Rossumd81a1ba1997-01-06 22:50:12 +0000118#define PycStringIO_OutputCheck(O) \
Guido van Rossum0a73dd51997-04-09 17:34:28 +0000119 ((O)->ob_type==PycStringIO->OutputType)
Guido van Rossum049cd901996-12-05 23:30:48 +0000120
Guido van Rossum142eeb81997-08-13 03:14:41 +0000121static void *
Guido van Rossumeec6ef11997-10-07 14:44:48 +0000122xxxPyCObject_Import(module_name, name)
123 char *module_name;
124 char *name;
Guido van Rossum142eeb81997-08-13 03:14:41 +0000125{
126 PyObject *m, *c;
127 void *r=NULL;
128
129 if((m=PyImport_ImportModule(module_name)))
130 {
131 if((c=PyObject_GetAttrString(m,name)))
132 {
133 r=PyCObject_AsVoidPtr(c);
134 Py_DECREF(c);
135 }
136 Py_DECREF(m);
137 }
138
139 return r;
140}
141
Guido van Rossum049cd901996-12-05 23:30:48 +0000142#define PycString_IMPORT \
Guido van Rossum142eeb81997-08-13 03:14:41 +0000143 PycStringIO=xxxPyCObject_Import("cStringIO", "cStringIO_CAPI")
Guido van Rossum049cd901996-12-05 23:30:48 +0000144
145#endif /* CSTRINGIO_INCLUDED */