Chris@87: #ifndef Py_CSTRINGIO_H Chris@87: #define Py_CSTRINGIO_H Chris@87: #ifdef __cplusplus Chris@87: extern "C" { Chris@87: #endif Chris@87: /* Chris@87: Chris@87: This header provides access to cStringIO objects from C. Chris@87: Functions are provided for calling cStringIO objects and Chris@87: macros are provided for testing whether you have cStringIO Chris@87: objects. Chris@87: Chris@87: Before calling any of the functions or macros, you must initialize Chris@87: the routines with: Chris@87: Chris@87: PycString_IMPORT Chris@87: Chris@87: This would typically be done in your init function. Chris@87: Chris@87: */ Chris@87: Chris@87: #define PycStringIO_CAPSULE_NAME "cStringIO.cStringIO_CAPI" Chris@87: Chris@87: #define PycString_IMPORT \ Chris@87: PycStringIO = ((struct PycStringIO_CAPI*)PyCapsule_Import(\ Chris@87: PycStringIO_CAPSULE_NAME, 0)) Chris@87: Chris@87: /* Basic functions to manipulate cStringIO objects from C */ Chris@87: Chris@87: static struct PycStringIO_CAPI { Chris@87: Chris@87: /* Read a string from an input object. If the last argument Chris@87: is -1, the remainder will be read. Chris@87: */ Chris@87: int(*cread)(PyObject *, char **, Py_ssize_t); Chris@87: Chris@87: /* Read a line from an input object. Returns the length of the read Chris@87: line as an int and a pointer inside the object buffer as char** (so Chris@87: the caller doesn't have to provide its own buffer as destination). Chris@87: */ Chris@87: int(*creadline)(PyObject *, char **); Chris@87: Chris@87: /* Write a string to an output object*/ Chris@87: int(*cwrite)(PyObject *, const char *, Py_ssize_t); Chris@87: Chris@87: /* Get the output object as a Python string (returns new reference). */ Chris@87: PyObject *(*cgetvalue)(PyObject *); Chris@87: Chris@87: /* Create a new output object */ Chris@87: PyObject *(*NewOutput)(int); Chris@87: Chris@87: /* Create an input object from a Python string Chris@87: (copies the Python string reference). Chris@87: */ Chris@87: PyObject *(*NewInput)(PyObject *); Chris@87: Chris@87: /* The Python types for cStringIO input and output objects. Chris@87: Note that you can do input on an output object. Chris@87: */ Chris@87: PyTypeObject *InputType, *OutputType; Chris@87: Chris@87: } *PycStringIO; Chris@87: Chris@87: /* These can be used to test if you have one */ Chris@87: #define PycStringIO_InputCheck(O) \ Chris@87: (Py_TYPE(O)==PycStringIO->InputType) Chris@87: #define PycStringIO_OutputCheck(O) \ Chris@87: (Py_TYPE(O)==PycStringIO->OutputType) Chris@87: Chris@87: #ifdef __cplusplus Chris@87: } Chris@87: #endif Chris@87: #endif /* !Py_CSTRINGIO_H */