blob: 66e1edb548ace7cdce5fe44520db324998954eb8 [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
Raymond Hettinger7b8e2812003-01-19 00:45:01 +000029 /* Read a string from an input object. If the last argument
30 is -1, the remainder will be read.
31 */
Tim Petersdbd9ba62000-07-09 03:09:57 +000032 int(*cread)(PyObject *, char **, int);
Guido van Rossum049cd901996-12-05 23:30:48 +000033
Raymond Hettinger7b8e2812003-01-19 00:45:01 +000034 /* Read a line from an input object. Returns the length of the read
35 line as an int and a pointer inside the object buffer as char** (so
36 the caller doesn't have to provide its own buffer as destination).
37 */
Tim Petersdbd9ba62000-07-09 03:09:57 +000038 int(*creadline)(PyObject *, char **);
Guido van Rossum049cd901996-12-05 23:30:48 +000039
Raymond Hettinger7b8e2812003-01-19 00:45:01 +000040 /* Write a string to an output object*/
Tim Petersdbd9ba62000-07-09 03:09:57 +000041 int(*cwrite)(PyObject *, char *, int);
Guido van Rossum049cd901996-12-05 23:30:48 +000042
Raymond Hettinger7b8e2812003-01-19 00:45:01 +000043 /* Get the output object as a Python string (returns new reference). */
Tim Petersdbd9ba62000-07-09 03:09:57 +000044 PyObject *(*cgetvalue)(PyObject *);
Guido van Rossum049cd901996-12-05 23:30:48 +000045
Guido van Rossum0a73dd51997-04-09 17:34:28 +000046 /* Create a new output object */
Tim Petersdbd9ba62000-07-09 03:09:57 +000047 PyObject *(*NewOutput)(int);
Guido van Rossum049cd901996-12-05 23:30:48 +000048
Raymond Hettinger7b8e2812003-01-19 00:45:01 +000049 /* Create an input object from a Python string
50 (copies the Python string reference).
51 */
Tim Petersdbd9ba62000-07-09 03:09:57 +000052 PyObject *(*NewInput)(PyObject *);
Guido van Rossum049cd901996-12-05 23:30:48 +000053
Guido van Rossum0a73dd51997-04-09 17:34:28 +000054 /* The Python types for cStringIO input and output objects.
55 Note that you can do input on an output object.
56 */
57 PyTypeObject *InputType, *OutputType;
58
Jeremy Hyltonf4d32df2002-08-05 18:20:01 +000059} *PycStringIO;
Guido van Rossum049cd901996-12-05 23:30:48 +000060
61/* These can be used to test if you have one */
Guido van Rossumd81a1ba1997-01-06 22:50:12 +000062#define PycStringIO_InputCheck(O) \
Guido van Rossum0a73dd51997-04-09 17:34:28 +000063 ((O)->ob_type==PycStringIO->InputType)
Guido van Rossumd81a1ba1997-01-06 22:50:12 +000064#define PycStringIO_OutputCheck(O) \
Guido van Rossum0a73dd51997-04-09 17:34:28 +000065 ((O)->ob_type==PycStringIO->OutputType)
Guido van Rossum049cd901996-12-05 23:30:48 +000066
Martin v. Löwis522cf1f2002-03-30 08:57:12 +000067#ifdef __cplusplus
68}
69#endif
Neal Norwitz638437f2002-10-04 12:43:02 +000070#endif /* !Py_CSTRINGIO_H */