blob: dae31bb3af98646b52be1d3bce0eff7e37f58aa4 [file] [log] [blame]
Guido van Rossum049cd901996-12-05 23:30:48 +00001#ifndef CSTRINGIO_INCLUDED
2#define CSTRINGIO_INCLUDED
3/*
4
5 $Id$
6
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
72 $Log$
Guido van Rossumd81a1ba1997-01-06 22:50:12 +000073 Revision 2.2 1997/01/06 22:50:12 guido
74 Jim's latest version
75
76 Revision 1.1 1997/01/02 15:18:36 chris
77 initial version
Guido van Rossum049cd901996-12-05 23:30:48 +000078
79
80*/
81
Guido van Rossum049cd901996-12-05 23:30:48 +000082/* Basic fuctions to manipulate cStringIO objects from C */
83
84/* Read a string. If the last argument is -1, the remainder will be read. */
85static int(*PycStringIO_cread)(PyObject *, char **, int)=NULL;
86
87/* Read a line */
88static int(*PycStringIO_creadline)(PyObject *, char **)=NULL;
89
90/* Write a string */
91static int(*PycStringIO_cwrite)(PyObject *, char *, int)=NULL;
92
93/* Get the cStringIO object as a Python string */
Guido van Rossumd81a1ba1997-01-06 22:50:12 +000094static PyObject *(*PycStringIO_cgetvalue)(PyObject *)=NULL;
Guido van Rossum049cd901996-12-05 23:30:48 +000095
96/* Create a new output object */
Guido van Rossumd81a1ba1997-01-06 22:50:12 +000097static PyObject *(*PycStringIO_NewOutput)(int)=NULL;
Guido van Rossum049cd901996-12-05 23:30:48 +000098
99/* Create an input object from a Python string */
Guido van Rossumd81a1ba1997-01-06 22:50:12 +0000100static PyObject *(*PycStringIO_NewInput)(PyObject *)=NULL;
Guido van Rossum049cd901996-12-05 23:30:48 +0000101
102/* The Python types for cStringIO input and output objects.
103 Note that you can do input on an output object.
104*/
105static PyObject *PycStringIO_InputType=NULL, *PycStringIO_OutputType=NULL;
106
107/* These can be used to test if you have one */
Guido van Rossumd81a1ba1997-01-06 22:50:12 +0000108#define PycStringIO_InputCheck(O) \
109 ((O)->ob_type==(PyTypeObject*)PycStringIO_InputType)
110#define PycStringIO_OutputCheck(O) \
111 ((O)->ob_type==(PyTypeObject*)PycStringIO_OutputType)
Guido van Rossum049cd901996-12-05 23:30:48 +0000112
113/* The following is used to implement PycString_IMPORT: */
114static PyObject *PycStringIO_Module=NULL, *PycStringIO_CObject=NULL;
115
116#define IMPORT_C_OBJECT(N) \
117 if((PycStringIO_CObject=PyObject_GetAttrString(PycStringIO_Module, #N))) { \
118 PycStringIO_ ## N = PyCObject_AsVoidPtr(PycStringIO_CObject); \
119 Py_DECREF(PycStringIO_CObject); }
120
121#define PycString_IMPORT \
122 if((PycStringIO_Module=PyImport_ImportModule("cStringIO"))) { \
123 PycStringIO_InputType=PyObject_GetAttrString(PycStringIO_Module, \
124 "InputType"); \
125 PycStringIO_OutputType=PyObject_GetAttrString(PycStringIO_Module, \
126 "OutputType"); \
127 IMPORT_C_OBJECT(cread); \
128 IMPORT_C_OBJECT(creadline); \
129 IMPORT_C_OBJECT(cwrite); \
130 IMPORT_C_OBJECT(NewInput); \
131 IMPORT_C_OBJECT(NewOutput); \
132 IMPORT_C_OBJECT(cgetvalue); }
133
134#endif /* CSTRINGIO_INCLUDED */