Neal Norwitz | 638437f | 2002-10-04 12:43:02 +0000 | [diff] [blame] | 1 | #ifndef Py_CSTRINGIO_H |
| 2 | #define Py_CSTRINGIO_H |
Martin v. Löwis | 522cf1f | 2002-03-30 08:57:12 +0000 | [diff] [blame] | 3 | #ifdef __cplusplus |
| 4 | extern "C" { |
| 5 | #endif |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 6 | /* |
| 7 | |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 8 | 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 Rossum | 7999bfb | 1999-01-25 21:36:13 +0000 | [diff] [blame] | 16 | PycString_IMPORT |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 17 | |
| 18 | This would typically be done in your init function. |
| 19 | |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 20 | */ |
Jeremy Hylton | f4d32df | 2002-08-05 18:20:01 +0000 | [diff] [blame] | 21 | #define PycString_IMPORT \ |
| 22 | PycStringIO = (struct PycStringIO_CAPI*)PyCObject_Import("cStringIO", \ |
| 23 | "cStringIO_CAPI") |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 24 | |
Thomas Wouters | 7e47402 | 2000-07-16 12:04:32 +0000 | [diff] [blame] | 25 | /* Basic functions to manipulate cStringIO objects from C */ |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 26 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 27 | static struct PycStringIO_CAPI { |
| 28 | |
| 29 | /* Read a string. If the last argument is -1, the remainder will be read. */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 30 | int(*cread)(PyObject *, char **, int); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 31 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 32 | /* Read a line */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 33 | int(*creadline)(PyObject *, char **); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 34 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 35 | /* Write a string */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 36 | int(*cwrite)(PyObject *, char *, int); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 37 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 38 | /* Get the cStringIO object as a Python string */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 39 | PyObject *(*cgetvalue)(PyObject *); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 40 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 41 | /* Create a new output object */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 42 | PyObject *(*NewOutput)(int); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 43 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 44 | /* Create an input object from a Python string */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 45 | PyObject *(*NewInput)(PyObject *); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 46 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 47 | /* 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 Hylton | f4d32df | 2002-08-05 18:20:01 +0000 | [diff] [blame] | 52 | } *PycStringIO; |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 53 | |
| 54 | /* These can be used to test if you have one */ |
Guido van Rossum | d81a1ba | 1997-01-06 22:50:12 +0000 | [diff] [blame] | 55 | #define PycStringIO_InputCheck(O) \ |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 56 | ((O)->ob_type==PycStringIO->InputType) |
Guido van Rossum | d81a1ba | 1997-01-06 22:50:12 +0000 | [diff] [blame] | 57 | #define PycStringIO_OutputCheck(O) \ |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 58 | ((O)->ob_type==PycStringIO->OutputType) |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 59 | |
Martin v. Löwis | 522cf1f | 2002-03-30 08:57:12 +0000 | [diff] [blame] | 60 | #ifdef __cplusplus |
| 61 | } |
| 62 | #endif |
Neal Norwitz | 638437f | 2002-10-04 12:43:02 +0000 | [diff] [blame] | 63 | #endif /* !Py_CSTRINGIO_H */ |