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 | |
Raymond Hettinger | 7b8e281 | 2003-01-19 00:45:01 +0000 | [diff] [blame] | 29 | /* Read a string from an input object. If the last argument |
| 30 | is -1, the remainder will be read. |
| 31 | */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 32 | int(*cread)(PyObject *, char **, int); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 33 | |
Raymond Hettinger | 7b8e281 | 2003-01-19 00:45:01 +0000 | [diff] [blame] | 34 | /* 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 Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 38 | int(*creadline)(PyObject *, char **); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 39 | |
Raymond Hettinger | 7b8e281 | 2003-01-19 00:45:01 +0000 | [diff] [blame] | 40 | /* Write a string to an output object*/ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 41 | int(*cwrite)(PyObject *, char *, int); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 42 | |
Raymond Hettinger | 7b8e281 | 2003-01-19 00:45:01 +0000 | [diff] [blame] | 43 | /* Get the output object as a Python string (returns new reference). */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 44 | PyObject *(*cgetvalue)(PyObject *); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 45 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 46 | /* Create a new output object */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 47 | PyObject *(*NewOutput)(int); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 48 | |
Raymond Hettinger | 7b8e281 | 2003-01-19 00:45:01 +0000 | [diff] [blame] | 49 | /* Create an input object from a Python string |
| 50 | (copies the Python string reference). |
| 51 | */ |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 52 | PyObject *(*NewInput)(PyObject *); |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 53 | |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 54 | /* 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 Hylton | f4d32df | 2002-08-05 18:20:01 +0000 | [diff] [blame] | 59 | } *PycStringIO; |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 60 | |
| 61 | /* These can be used to test if you have one */ |
Guido van Rossum | d81a1ba | 1997-01-06 22:50:12 +0000 | [diff] [blame] | 62 | #define PycStringIO_InputCheck(O) \ |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 63 | ((O)->ob_type==PycStringIO->InputType) |
Guido van Rossum | d81a1ba | 1997-01-06 22:50:12 +0000 | [diff] [blame] | 64 | #define PycStringIO_OutputCheck(O) \ |
Guido van Rossum | 0a73dd5 | 1997-04-09 17:34:28 +0000 | [diff] [blame] | 65 | ((O)->ob_type==PycStringIO->OutputType) |
Guido van Rossum | 049cd90 | 1996-12-05 23:30:48 +0000 | [diff] [blame] | 66 | |
Martin v. Löwis | 522cf1f | 2002-03-30 08:57:12 +0000 | [diff] [blame] | 67 | #ifdef __cplusplus |
| 68 | } |
| 69 | #endif |
Neal Norwitz | 638437f | 2002-10-04 12:43:02 +0000 | [diff] [blame] | 70 | #endif /* !Py_CSTRINGIO_H */ |