cStringIO.h 1.94 KB
Newer Older
1 2
#ifndef Py_CSTRINGIO_H
#define Py_CSTRINGIO_H
3 4 5
#ifdef __cplusplus
extern "C" {
#endif
Guido van Rossum's avatar
Guido van Rossum committed
6 7 8 9 10 11 12 13 14 15
/*

  This header provides access to cStringIO objects from C.
  Functions are provided for calling cStringIO objects and
  macros are provided for testing whether you have cStringIO 
  objects.

  Before calling any of the functions or macros, you must initialize
  the routines with:

16
    PycString_IMPORT
Guido van Rossum's avatar
Guido van Rossum committed
17 18 19

  This would typically be done in your init function.

Guido van Rossum's avatar
Guido van Rossum committed
20
*/
21 22 23
#define PycString_IMPORT \
  PycStringIO = (struct PycStringIO_CAPI*)PyCObject_Import("cStringIO", \
                                                           "cStringIO_CAPI")
Guido van Rossum's avatar
Guido van Rossum committed
24

25
/* Basic functions to manipulate cStringIO objects from C */
Guido van Rossum's avatar
Guido van Rossum committed
26

27 28
static struct PycStringIO_CAPI {
  
29 30 31
 /* Read a string from an input object.  If the last argument
    is -1, the remainder will be read.
    */
32
  int(*cread)(PyObject *, char **, int);
Guido van Rossum's avatar
Guido van Rossum committed
33

34 35 36 37
 /* Read a line from an input object.  Returns the length of the read
    line as an int and a pointer inside the object buffer as char** (so
    the caller doesn't have to provide its own buffer as destination).
    */
38
  int(*creadline)(PyObject *, char **);
Guido van Rossum's avatar
Guido van Rossum committed
39

40
  /* Write a string to an output object*/
41
  int(*cwrite)(PyObject *, char *, int);
Guido van Rossum's avatar
Guido van Rossum committed
42

43
  /* Get the output object as a Python string (returns new reference). */
44
  PyObject *(*cgetvalue)(PyObject *);
Guido van Rossum's avatar
Guido van Rossum committed
45

46
  /* Create a new output object */
47
  PyObject *(*NewOutput)(int);
Guido van Rossum's avatar
Guido van Rossum committed
48

49 50 51
  /* Create an input object from a Python string
     (copies the Python string reference).
     */
52
  PyObject *(*NewInput)(PyObject *);
Guido van Rossum's avatar
Guido van Rossum committed
53

54 55 56 57 58
  /* The Python types for cStringIO input and output objects.
     Note that you can do input on an output object.
     */
  PyTypeObject *InputType, *OutputType;

59
} *PycStringIO;
Guido van Rossum's avatar
Guido van Rossum committed
60 61

/* These can be used to test if you have one */
Guido van Rossum's avatar
Guido van Rossum committed
62
#define PycStringIO_InputCheck(O) \
63
  ((O)->ob_type==PycStringIO->InputType)
Guido van Rossum's avatar
Guido van Rossum committed
64
#define PycStringIO_OutputCheck(O) \
65 66
  ((O)->ob_type==PycStringIO->OutputType)

67 68 69
#ifdef __cplusplus
}
#endif
70
#endif /* !Py_CSTRINGIO_H */