Chris@87
|
1 #ifndef Py_CSTRINGIO_H
|
Chris@87
|
2 #define Py_CSTRINGIO_H
|
Chris@87
|
3 #ifdef __cplusplus
|
Chris@87
|
4 extern "C" {
|
Chris@87
|
5 #endif
|
Chris@87
|
6 /*
|
Chris@87
|
7
|
Chris@87
|
8 This header provides access to cStringIO objects from C.
|
Chris@87
|
9 Functions are provided for calling cStringIO objects and
|
Chris@87
|
10 macros are provided for testing whether you have cStringIO
|
Chris@87
|
11 objects.
|
Chris@87
|
12
|
Chris@87
|
13 Before calling any of the functions or macros, you must initialize
|
Chris@87
|
14 the routines with:
|
Chris@87
|
15
|
Chris@87
|
16 PycString_IMPORT
|
Chris@87
|
17
|
Chris@87
|
18 This would typically be done in your init function.
|
Chris@87
|
19
|
Chris@87
|
20 */
|
Chris@87
|
21
|
Chris@87
|
22 #define PycStringIO_CAPSULE_NAME "cStringIO.cStringIO_CAPI"
|
Chris@87
|
23
|
Chris@87
|
24 #define PycString_IMPORT \
|
Chris@87
|
25 PycStringIO = ((struct PycStringIO_CAPI*)PyCapsule_Import(\
|
Chris@87
|
26 PycStringIO_CAPSULE_NAME, 0))
|
Chris@87
|
27
|
Chris@87
|
28 /* Basic functions to manipulate cStringIO objects from C */
|
Chris@87
|
29
|
Chris@87
|
30 static struct PycStringIO_CAPI {
|
Chris@87
|
31
|
Chris@87
|
32 /* Read a string from an input object. If the last argument
|
Chris@87
|
33 is -1, the remainder will be read.
|
Chris@87
|
34 */
|
Chris@87
|
35 int(*cread)(PyObject *, char **, Py_ssize_t);
|
Chris@87
|
36
|
Chris@87
|
37 /* Read a line from an input object. Returns the length of the read
|
Chris@87
|
38 line as an int and a pointer inside the object buffer as char** (so
|
Chris@87
|
39 the caller doesn't have to provide its own buffer as destination).
|
Chris@87
|
40 */
|
Chris@87
|
41 int(*creadline)(PyObject *, char **);
|
Chris@87
|
42
|
Chris@87
|
43 /* Write a string to an output object*/
|
Chris@87
|
44 int(*cwrite)(PyObject *, const char *, Py_ssize_t);
|
Chris@87
|
45
|
Chris@87
|
46 /* Get the output object as a Python string (returns new reference). */
|
Chris@87
|
47 PyObject *(*cgetvalue)(PyObject *);
|
Chris@87
|
48
|
Chris@87
|
49 /* Create a new output object */
|
Chris@87
|
50 PyObject *(*NewOutput)(int);
|
Chris@87
|
51
|
Chris@87
|
52 /* Create an input object from a Python string
|
Chris@87
|
53 (copies the Python string reference).
|
Chris@87
|
54 */
|
Chris@87
|
55 PyObject *(*NewInput)(PyObject *);
|
Chris@87
|
56
|
Chris@87
|
57 /* The Python types for cStringIO input and output objects.
|
Chris@87
|
58 Note that you can do input on an output object.
|
Chris@87
|
59 */
|
Chris@87
|
60 PyTypeObject *InputType, *OutputType;
|
Chris@87
|
61
|
Chris@87
|
62 } *PycStringIO;
|
Chris@87
|
63
|
Chris@87
|
64 /* These can be used to test if you have one */
|
Chris@87
|
65 #define PycStringIO_InputCheck(O) \
|
Chris@87
|
66 (Py_TYPE(O)==PycStringIO->InputType)
|
Chris@87
|
67 #define PycStringIO_OutputCheck(O) \
|
Chris@87
|
68 (Py_TYPE(O)==PycStringIO->OutputType)
|
Chris@87
|
69
|
Chris@87
|
70 #ifdef __cplusplus
|
Chris@87
|
71 }
|
Chris@87
|
72 #endif
|
Chris@87
|
73 #endif /* !Py_CSTRINGIO_H */
|