Showing the changes to sys/src/cmd/python/Include/cStringIO.h (1 of 3706 files). Show all
Unified · Split
| @@ -0,0 +1,70 @@ | ||
| 1 | +#ifndef Py_CSTRINGIO_H | |
| 2 | +#define Py_CSTRINGIO_H | |
| 3 | +#ifdef __cplusplus | |
| 4 | +extern "C" { | |
| 5 | +#endif | |
| 6 | +/* | |
| 7 | + | |
| 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 | + | |
| 16 | + PycString_IMPORT | |
| 17 | + | |
| 18 | + This would typically be done in your init function. | |
| 19 | + | |
| 20 | +*/ | |
| 21 | +#define PycString_IMPORT \ | |
| 22 | + PycStringIO = (struct PycStringIO_CAPI*)PyCObject_Import("cStringIO", \ | |
| 23 | + "cStringIO_CAPI") | |
| 24 | + | |
| 25 | +/* Basic functions to manipulate cStringIO objects from C */ | |
| 26 | + | |
| 27 | +static struct PycStringIO_CAPI { | |
| 28 | + | |
| 29 | + /* Read a string from an input object. If the last argument | |
| 30 | + is -1, the remainder will be read. | |
| 31 | + */ | |
| 32 | + int(*cread)(PyObject *, char **, Py_ssize_t); | |
| 33 | + | |
| 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 | + */ | |
| 38 | + int(*creadline)(PyObject *, char **); | |
| 39 | + | |
| 40 | + /* Write a string to an output object*/ | |
| 41 | + int(*cwrite)(PyObject *, const char *, Py_ssize_t); | |
| 42 | + | |
| 43 | + /* Get the output object as a Python string (returns new reference). */ | |
| 44 | + PyObject *(*cgetvalue)(PyObject *); | |
| 45 | + | |
| 46 | + /* Create a new output object */ | |
| 47 | + PyObject *(*NewOutput)(int); | |
| 48 | + | |
| 49 | + /* Create an input object from a Python string | |
| 50 | + (copies the Python string reference). | |
| 51 | + */ | |
| 52 | + PyObject *(*NewInput)(PyObject *); | |
| 53 | + | |
| 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 | + | |
| 59 | +} *PycStringIO; | |
| 60 | + | |
| 61 | +/* These can be used to test if you have one */ | |
| 62 | +#define PycStringIO_InputCheck(O) \ | |
| 63 | + ((O)->ob_type==PycStringIO->InputType) | |
| 64 | +#define PycStringIO_OutputCheck(O) \ | |
| 65 | + ((O)->ob_type==PycStringIO->OutputType) | |
| 66 | + | |
| 67 | +#ifdef __cplusplus | |
| 68 | +} | |
| 69 | +#endif | |
| 70 | +#endif /* !Py_CSTRINGIO_H */ | |