blob: fa3fcd70a6b88d34acb19e6a518891d407ccaacd [file] [log] [blame]
Guido van Rossum049cd901996-12-05 23:30:48 +00001#ifndef CSTRINGIO_INCLUDED
2#define CSTRINGIO_INCLUDED
Martin v. Löwis522cf1f2002-03-30 08:57:12 +00003#ifdef __cplusplus
4extern "C" {
5#endif
Guido van Rossum049cd901996-12-05 23:30:48 +00006/*
7
Guido van Rossumcd8732a1997-12-08 15:16:08 +00008 cStringIO.h,v 1.4 1997/12/07 14:27:00 jim Exp
Guido van Rossum049cd901996-12-05 23:30:48 +00009
10 cStringIO C API
11
12 Copyright
13
14 Copyright 1996 Digital Creations, L.C., 910 Princess Anne
15 Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
16 rights reserved. Copyright in this software is owned by DCLC,
17 unless otherwise indicated. Permission to use, copy and
18 distribute this software is hereby granted, provided that the
19 above copyright notice appear in all copies and that both that
20 copyright notice and this permission notice appear. Note that
21 any product, process or technology described in this software
22 may be the subject of other Intellectual Property rights
23 reserved by Digital Creations, L.C. and are not licensed
24 hereunder.
25
26 Trademarks
27
28 Digital Creations & DCLC, are trademarks of Digital Creations, L.C..
29 All other trademarks are owned by their respective companies.
30
31 No Warranty
32
33 The software is provided "as is" without warranty of any kind,
34 either express or implied, including, but not limited to, the
35 implied warranties of merchantability, fitness for a particular
36 purpose, or non-infringement. This software could include
37 technical inaccuracies or typographical errors. Changes are
38 periodically made to the software; these changes will be
39 incorporated in new editions of the software. DCLC may make
40 improvements and/or changes in this software at any time
41 without notice.
42
43 Limitation Of Liability
44
45 In no event will DCLC be liable for direct, indirect, special,
46 incidental, economic, cover, or consequential damages arising
47 out of the use of or inability to use this software even if
48 advised of the possibility of such damages. Some states do not
49 allow the exclusion or limitation of implied warranties or
50 limitation of liability for incidental or consequential
51 damages, so the above limitation or exclusion may not apply to
52 you.
53
54 If you have questions regarding this software,
55 contact:
56
57 info@digicool.com
58 Digital Creations L.C.
59
60 (540) 371-6909
61
62
63 This header provides access to cStringIO objects from C.
64 Functions are provided for calling cStringIO objects and
65 macros are provided for testing whether you have cStringIO
66 objects.
67
68 Before calling any of the functions or macros, you must initialize
69 the routines with:
70
Guido van Rossum7999bfb1999-01-25 21:36:13 +000071 PycString_IMPORT
Guido van Rossum049cd901996-12-05 23:30:48 +000072
73 This would typically be done in your init function.
74
Guido van Rossum049cd901996-12-05 23:30:48 +000075*/
76
Thomas Wouters7e474022000-07-16 12:04:32 +000077/* Basic functions to manipulate cStringIO objects from C */
Guido van Rossum049cd901996-12-05 23:30:48 +000078
Guido van Rossum0a73dd51997-04-09 17:34:28 +000079static struct PycStringIO_CAPI {
80
81 /* Read a string. If the last argument is -1, the remainder will be read. */
Tim Petersdbd9ba62000-07-09 03:09:57 +000082 int(*cread)(PyObject *, char **, int);
Guido van Rossum049cd901996-12-05 23:30:48 +000083
Guido van Rossum0a73dd51997-04-09 17:34:28 +000084 /* Read a line */
Tim Petersdbd9ba62000-07-09 03:09:57 +000085 int(*creadline)(PyObject *, char **);
Guido van Rossum049cd901996-12-05 23:30:48 +000086
Guido van Rossum0a73dd51997-04-09 17:34:28 +000087 /* Write a string */
Tim Petersdbd9ba62000-07-09 03:09:57 +000088 int(*cwrite)(PyObject *, char *, int);
Guido van Rossum049cd901996-12-05 23:30:48 +000089
Guido van Rossum0a73dd51997-04-09 17:34:28 +000090 /* Get the cStringIO object as a Python string */
Tim Petersdbd9ba62000-07-09 03:09:57 +000091 PyObject *(*cgetvalue)(PyObject *);
Guido van Rossum049cd901996-12-05 23:30:48 +000092
Guido van Rossum0a73dd51997-04-09 17:34:28 +000093 /* Create a new output object */
Tim Petersdbd9ba62000-07-09 03:09:57 +000094 PyObject *(*NewOutput)(int);
Guido van Rossum049cd901996-12-05 23:30:48 +000095
Guido van Rossum0a73dd51997-04-09 17:34:28 +000096 /* Create an input object from a Python string */
Tim Petersdbd9ba62000-07-09 03:09:57 +000097 PyObject *(*NewInput)(PyObject *);
Guido van Rossum049cd901996-12-05 23:30:48 +000098
Guido van Rossum0a73dd51997-04-09 17:34:28 +000099 /* The Python types for cStringIO input and output objects.
100 Note that you can do input on an output object.
101 */
102 PyTypeObject *InputType, *OutputType;
103
104} * PycStringIO = NULL;
Guido van Rossum049cd901996-12-05 23:30:48 +0000105
106/* These can be used to test if you have one */
Guido van Rossumd81a1ba1997-01-06 22:50:12 +0000107#define PycStringIO_InputCheck(O) \
Guido van Rossum0a73dd51997-04-09 17:34:28 +0000108 ((O)->ob_type==PycStringIO->InputType)
Guido van Rossumd81a1ba1997-01-06 22:50:12 +0000109#define PycStringIO_OutputCheck(O) \
Guido van Rossum0a73dd51997-04-09 17:34:28 +0000110 ((O)->ob_type==PycStringIO->OutputType)
Guido van Rossum049cd901996-12-05 23:30:48 +0000111
Guido van Rossumf0f36001998-12-08 13:23:22 +0000112static void *
Thomas Wouters78890102000-07-22 19:25:51 +0000113xxxPyCObject_Import(char *module_name, char *name)
Guido van Rossum142eeb81997-08-13 03:14:41 +0000114{
115 PyObject *m, *c;
116 void *r=NULL;
117
118 if((m=PyImport_ImportModule(module_name)))
119 {
120 if((c=PyObject_GetAttrString(m,name)))
121 {
122 r=PyCObject_AsVoidPtr(c);
123 Py_DECREF(c);
124 }
125 Py_DECREF(m);
126 }
127
128 return r;
129}
130
Guido van Rossum049cd901996-12-05 23:30:48 +0000131#define PycString_IMPORT \
Martin v. Löwiseefa9642001-06-09 07:59:43 +0000132 PycStringIO=(struct PycStringIO_CAPI*)xxxPyCObject_Import("cStringIO", "cStringIO_CAPI")
Guido van Rossum049cd901996-12-05 23:30:48 +0000133
Martin v. Löwis522cf1f2002-03-30 08:57:12 +0000134#ifdef __cplusplus
135}
136#endif
Guido van Rossum049cd901996-12-05 23:30:48 +0000137#endif /* CSTRINGIO_INCLUDED */