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