blob: 50921d9e84d5e211c83cc40cc964bf2f30ebb78e [file] [log] [blame]
Neal Norwitz638437f2002-10-04 12:43:02 +00001#ifndef Py_CSTRINGIO_H
2#define Py_CSTRINGIO_H
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 Rossum049cd901996-12-05 23:30:48 +00008 This header provides access to cStringIO objects from C.
9 Functions are provided for calling cStringIO objects and
10 macros are provided for testing whether you have cStringIO
11 objects.
12
13 Before calling any of the functions or macros, you must initialize
14 the routines with:
15
Guido van Rossum7999bfb1999-01-25 21:36:13 +000016 PycString_IMPORT
Guido van Rossum049cd901996-12-05 23:30:48 +000017
18 This would typically be done in your init function.
19
Guido van Rossum049cd901996-12-05 23:30:48 +000020*/
Jeremy Hyltonf4d32df2002-08-05 18:20:01 +000021#define PycString_IMPORT \
22 PycStringIO = (struct PycStringIO_CAPI*)PyCObject_Import("cStringIO", \
23 "cStringIO_CAPI")
Guido van Rossum049cd901996-12-05 23:30:48 +000024
Thomas Wouters7e474022000-07-16 12:04:32 +000025/* Basic functions to manipulate cStringIO objects from C */
Guido van Rossum049cd901996-12-05 23:30:48 +000026
Guido van Rossum0a73dd51997-04-09 17:34:28 +000027static struct PycStringIO_CAPI {
28
29 /* Read a string. If the last argument is -1, the remainder will be read. */
Tim Petersdbd9ba62000-07-09 03:09:57 +000030 int(*cread)(PyObject *, char **, int);
Guido van Rossum049cd901996-12-05 23:30:48 +000031
Guido van Rossum0a73dd51997-04-09 17:34:28 +000032 /* Read a line */
Tim Petersdbd9ba62000-07-09 03:09:57 +000033 int(*creadline)(PyObject *, char **);
Guido van Rossum049cd901996-12-05 23:30:48 +000034
Guido van Rossum0a73dd51997-04-09 17:34:28 +000035 /* Write a string */
Tim Petersdbd9ba62000-07-09 03:09:57 +000036 int(*cwrite)(PyObject *, char *, int);
Guido van Rossum049cd901996-12-05 23:30:48 +000037
Guido van Rossum0a73dd51997-04-09 17:34:28 +000038 /* Get the cStringIO object as a Python string */
Tim Petersdbd9ba62000-07-09 03:09:57 +000039 PyObject *(*cgetvalue)(PyObject *);
Guido van Rossum049cd901996-12-05 23:30:48 +000040
Guido van Rossum0a73dd51997-04-09 17:34:28 +000041 /* Create a new output object */
Tim Petersdbd9ba62000-07-09 03:09:57 +000042 PyObject *(*NewOutput)(int);
Guido van Rossum049cd901996-12-05 23:30:48 +000043
Guido van Rossum0a73dd51997-04-09 17:34:28 +000044 /* Create an input object from a Python string */
Tim Petersdbd9ba62000-07-09 03:09:57 +000045 PyObject *(*NewInput)(PyObject *);
Guido van Rossum049cd901996-12-05 23:30:48 +000046
Guido van Rossum0a73dd51997-04-09 17:34:28 +000047 /* The Python types for cStringIO input and output objects.
48 Note that you can do input on an output object.
49 */
50 PyTypeObject *InputType, *OutputType;
51
Jeremy Hyltonf4d32df2002-08-05 18:20:01 +000052} *PycStringIO;
Guido van Rossum049cd901996-12-05 23:30:48 +000053
54/* These can be used to test if you have one */
Guido van Rossumd81a1ba1997-01-06 22:50:12 +000055#define PycStringIO_InputCheck(O) \
Guido van Rossum0a73dd51997-04-09 17:34:28 +000056 ((O)->ob_type==PycStringIO->InputType)
Guido van Rossumd81a1ba1997-01-06 22:50:12 +000057#define PycStringIO_OutputCheck(O) \
Guido van Rossum0a73dd51997-04-09 17:34:28 +000058 ((O)->ob_type==PycStringIO->OutputType)
Guido van Rossum049cd901996-12-05 23:30:48 +000059
Martin v. Löwis522cf1f2002-03-30 08:57:12 +000060#ifdef __cplusplus
61}
62#endif
Neal Norwitz638437f2002-10-04 12:43:02 +000063#endif /* !Py_CSTRINGIO_H */