Commit 3d9bf2cc authored by Jim Fulton's avatar Jim Fulton

Changed the way the C API was exported.

parent 918455f4
......@@ -2,7 +2,7 @@
#define CSTRINGIO_INCLUDED
/*
$Id: cStringIO.h,v 1.1 1997/01/02 15:18:36 chris Exp $
$Id: cStringIO.h,v 1.2 1997/01/27 14:13:05 jim Exp $
cStringIO C API
......@@ -70,6 +70,9 @@
This would typically be done in your init function.
$Log: cStringIO.h,v $
Revision 1.2 1997/01/27 14:13:05 jim
Changed the way the C API was exported.
Revision 1.1 1997/01/02 15:18:36 chris
initial version
......@@ -78,54 +81,59 @@
/* Basic fuctions to manipulate cStringIO objects from C */
/* Read a string. If the last argument is -1, the remainder will be read. */
static int(*PycStringIO_cread)(PyObject *, char **, int)=NULL;
static struct PycStringIO_CAPI {
/* Read a string. If the last argument is -1, the remainder will be read. */
int(*cread)(PyObject *, char **, int);
/* Read a line */
static int(*PycStringIO_creadline)(PyObject *, char **)=NULL;
/* Read a line */
int(*creadline)(PyObject *, char **);
/* Write a string */
static int(*PycStringIO_cwrite)(PyObject *, char *, int)=NULL;
/* Write a string */
int(*cwrite)(PyObject *, char *, int);
/* Get the cStringIO object as a Python string */
static PyObject *(*PycStringIO_cgetvalue)(PyObject *)=NULL;
/* Get the cStringIO object as a Python string */
PyObject *(*cgetvalue)(PyObject *);
/* Create a new output object */
static PyObject *(*PycStringIO_NewOutput)(int)=NULL;
/* Create a new output object */
PyObject *(*NewOutput)(int);
/* Create an input object from a Python string */
static PyObject *(*PycStringIO_NewInput)(PyObject *)=NULL;
/* Create an input object from a Python string */
PyObject *(*NewInput)(PyObject *);
/* The Python types for cStringIO input and output objects.
Note that you can do input on an output object.
*/
static PyObject *PycStringIO_InputType=NULL, *PycStringIO_OutputType=NULL;
/* The Python types for cStringIO input and output objects.
Note that you can do input on an output object.
*/
PyTypeObject *InputType, *OutputType;
} * PycStringIO = NULL;
/* These can be used to test if you have one */
#define PycStringIO_InputCheck(O) \
((O)->ob_type==(PyTypeObject*)PycStringIO_InputType)
((O)->ob_type==PycStringIO->InputType)
#define PycStringIO_OutputCheck(O) \
((O)->ob_type==(PyTypeObject*)PycStringIO_OutputType)
/* The following is used to implement PycString_IMPORT: */
static PyObject *PycStringIO_Module=NULL, *PycStringIO_CObject=NULL;
#define IMPORT_C_OBJECT(N) \
if((PycStringIO_CObject=PyObject_GetAttrString(PycStringIO_Module, #N))) { \
PycStringIO_ ## N = PyCObject_AsVoidPtr(PycStringIO_CObject); \
Py_DECREF(PycStringIO_CObject); }
((O)->ob_type==PycStringIO->OutputType)
static void *
PyCObject_Import(char *module_name, char *name)
{
PyObject *m, *c;
void *r=NULL;
if(m=PyImport_ImportModule(module_name))
{
if(c=PyObject_GetAttrString(m,name))
{
r=PyCObject_AsVoidPtr(c);
Py_DECREF(c);
}
Py_DECREF(m);
}
return r;
}
#define PycString_IMPORT \
if((PycStringIO_Module=PyImport_ImportModule("cStringIO"))) { \
PycStringIO_InputType=PyObject_GetAttrString(PycStringIO_Module, \
"InputType"); \
PycStringIO_OutputType=PyObject_GetAttrString(PycStringIO_Module, \
"OutputType"); \
IMPORT_C_OBJECT(cread); \
IMPORT_C_OBJECT(creadline); \
IMPORT_C_OBJECT(cwrite); \
IMPORT_C_OBJECT(NewInput); \
IMPORT_C_OBJECT(NewOutput); \
IMPORT_C_OBJECT(cgetvalue); }
PycStringIO=PyCObject_Import("cStringIO", "cStringIO_CAPI")
#endif /* CSTRINGIO_INCLUDED */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment