blob: 6ca44a830306fc296dea98c0a680b0f97c1e0580 [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*/
Larry Hastings402b73f2010-03-25 00:54:54 +000021
22#define PycStringIO_CAPSULE_NAME "cStringIO.cStringIO_CAPI"
23
Jeremy Hyltonf4d32df2002-08-05 18:20:01 +000024#define PycString_IMPORT \
Larry Hastings402b73f2010-03-25 00:54:54 +000025 PycStringIO = ((struct PycStringIO_CAPI*)PyCapsule_Import(\
26 PycStringIO_CAPSULE_NAME, 0))
Guido van Rossum049cd901996-12-05 23:30:48 +000027
Thomas Wouters7e474022000-07-16 12:04:32 +000028/* Basic functions to manipulate cStringIO objects from C */
Guido van Rossum049cd901996-12-05 23:30:48 +000029
Guido van Rossum0a73dd51997-04-09 17:34:28 +000030static struct PycStringIO_CAPI {
31
Raymond Hettinger7b8e2812003-01-19 00:45:01 +000032 /* Read a string from an input object. If the last argument
33 is -1, the remainder will be read.
34 */
Martin v. Löwis18e16552006-02-15 17:27:45 +000035 int(*cread)(PyObject *, char **, Py_ssize_t);
Guido van Rossum049cd901996-12-05 23:30:48 +000036
Raymond Hettinger7b8e2812003-01-19 00:45:01 +000037 /* Read a line from an input object. Returns the length of the read
38 line as an int and a pointer inside the object buffer as char** (so
39 the caller doesn't have to provide its own buffer as destination).
40 */
Tim Petersdbd9ba62000-07-09 03:09:57 +000041 int(*creadline)(PyObject *, char **);
Guido van Rossum049cd901996-12-05 23:30:48 +000042
Raymond Hettinger7b8e2812003-01-19 00:45:01 +000043 /* Write a string to an output object*/
Martin v. Löwis18e16552006-02-15 17:27:45 +000044 int(*cwrite)(PyObject *, const char *, Py_ssize_t);
Guido van Rossum049cd901996-12-05 23:30:48 +000045
Raymond Hettinger7b8e2812003-01-19 00:45:01 +000046 /* Get the output object as a Python string (returns new reference). */
Tim Petersdbd9ba62000-07-09 03:09:57 +000047 PyObject *(*cgetvalue)(PyObject *);
Guido van Rossum049cd901996-12-05 23:30:48 +000048
Guido van Rossum0a73dd51997-04-09 17:34:28 +000049 /* Create a new output object */
Tim Petersdbd9ba62000-07-09 03:09:57 +000050 PyObject *(*NewOutput)(int);
Guido van Rossum049cd901996-12-05 23:30:48 +000051
Raymond Hettinger7b8e2812003-01-19 00:45:01 +000052 /* Create an input object from a Python string
53 (copies the Python string reference).
54 */
Tim Petersdbd9ba62000-07-09 03:09:57 +000055 PyObject *(*NewInput)(PyObject *);
Guido van Rossum049cd901996-12-05 23:30:48 +000056
Guido van Rossum0a73dd51997-04-09 17:34:28 +000057 /* The Python types for cStringIO input and output objects.
58 Note that you can do input on an output object.
59 */
60 PyTypeObject *InputType, *OutputType;
61
Jeremy Hyltonf4d32df2002-08-05 18:20:01 +000062} *PycStringIO;
Guido van Rossum049cd901996-12-05 23:30:48 +000063
64/* These can be used to test if you have one */
Guido van Rossumd81a1ba1997-01-06 22:50:12 +000065#define PycStringIO_InputCheck(O) \
Christian Heimese93237d2007-12-19 02:37:44 +000066 (Py_TYPE(O)==PycStringIO->InputType)
Guido van Rossumd81a1ba1997-01-06 22:50:12 +000067#define PycStringIO_OutputCheck(O) \
Christian Heimese93237d2007-12-19 02:37:44 +000068 (Py_TYPE(O)==PycStringIO->OutputType)
Guido van Rossum049cd901996-12-05 23:30:48 +000069
Martin v. Löwis522cf1f2002-03-30 08:57:12 +000070#ifdef __cplusplus
71}
72#endif
Neal Norwitz638437f2002-10-04 12:43:02 +000073#endif /* !Py_CSTRINGIO_H */