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

Changed the way the C API was exported.

parent 918455f4
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define CSTRINGIO_INCLUDED #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 cStringIO C API
...@@ -70,6 +70,9 @@ ...@@ -70,6 +70,9 @@
This would typically be done in your init function. This would typically be done in your init function.
$Log: cStringIO.h,v $ $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 Revision 1.1 1997/01/02 15:18:36 chris
initial version initial version
...@@ -78,54 +81,59 @@ ...@@ -78,54 +81,59 @@
/* Basic fuctions to manipulate cStringIO objects from C */ /* Basic fuctions to manipulate cStringIO objects from C */
/* Read a string. If the last argument is -1, the remainder will be read. */ static struct PycStringIO_CAPI {
static int(*PycStringIO_cread)(PyObject *, char **, int)=NULL;
/* Read a string. If the last argument is -1, the remainder will be read. */
int(*cread)(PyObject *, char **, int);
/* Read a line */ /* Read a line */
static int(*PycStringIO_creadline)(PyObject *, char **)=NULL; int(*creadline)(PyObject *, char **);
/* Write a string */ /* Write a string */
static int(*PycStringIO_cwrite)(PyObject *, char *, int)=NULL; int(*cwrite)(PyObject *, char *, int);
/* Get the cStringIO object as a Python string */ /* Get the cStringIO object as a Python string */
static PyObject *(*PycStringIO_cgetvalue)(PyObject *)=NULL; PyObject *(*cgetvalue)(PyObject *);
/* Create a new output object */ /* Create a new output object */
static PyObject *(*PycStringIO_NewOutput)(int)=NULL; PyObject *(*NewOutput)(int);
/* Create an input object from a Python string */ /* Create an input object from a Python string */
static PyObject *(*PycStringIO_NewInput)(PyObject *)=NULL; PyObject *(*NewInput)(PyObject *);
/* The Python types for cStringIO input and output objects. /* The Python types for cStringIO input and output objects.
Note that you can do input on an output object. Note that you can do input on an output object.
*/ */
static PyObject *PycStringIO_InputType=NULL, *PycStringIO_OutputType=NULL; PyTypeObject *InputType, *OutputType;
} * PycStringIO = NULL;
/* These can be used to test if you have one */ /* These can be used to test if you have one */
#define PycStringIO_InputCheck(O) \ #define PycStringIO_InputCheck(O) \
((O)->ob_type==(PyTypeObject*)PycStringIO_InputType) ((O)->ob_type==PycStringIO->InputType)
#define PycStringIO_OutputCheck(O) \ #define PycStringIO_OutputCheck(O) \
((O)->ob_type==(PyTypeObject*)PycStringIO_OutputType) ((O)->ob_type==PycStringIO->OutputType)
/* The following is used to implement PycString_IMPORT: */ static void *
static PyObject *PycStringIO_Module=NULL, *PycStringIO_CObject=NULL; PyCObject_Import(char *module_name, char *name)
{
#define IMPORT_C_OBJECT(N) \ PyObject *m, *c;
if((PycStringIO_CObject=PyObject_GetAttrString(PycStringIO_Module, #N))) { \ void *r=NULL;
PycStringIO_ ## N = PyCObject_AsVoidPtr(PycStringIO_CObject); \
Py_DECREF(PycStringIO_CObject); } 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 \ #define PycString_IMPORT \
if((PycStringIO_Module=PyImport_ImportModule("cStringIO"))) { \ PycStringIO=PyCObject_Import("cStringIO", "cStringIO_CAPI")
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); }
#endif /* CSTRINGIO_INCLUDED */ #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