Changed the way the C API was exported. Jim Fulton.

This commit is contained in:
Guido van Rossum 1997-04-09 17:34:28 +00:00
parent b72cf2d697
commit 0a73dd5f35

View file

@ -70,8 +70,11 @@
This would typically be done in your init function. This would typically be done in your init function.
$Log$ $Log$
Revision 2.2 1997/01/06 22:50:12 guido Revision 2.3 1997/04/09 17:34:28 guido
Jim's latest version Changed the way the C API was exported. Jim Fulton.
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
@ -81,54 +84,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 line */ /* Read a string. If the last argument is -1, the remainder will be read. */
static int(*PycStringIO_creadline)(PyObject *, char **)=NULL; int(*cread)(PyObject *, char **, int);
/* Write a string */ /* Read a line */
static int(*PycStringIO_cwrite)(PyObject *, char *, int)=NULL; int(*creadline)(PyObject *, char **);
/* Get the cStringIO object as a Python string */ /* Write a string */
static PyObject *(*PycStringIO_cgetvalue)(PyObject *)=NULL; int(*cwrite)(PyObject *, char *, int);
/* Create a new output object */ /* Get the cStringIO object as a Python string */
static PyObject *(*PycStringIO_NewOutput)(int)=NULL; PyObject *(*cgetvalue)(PyObject *);
/* Create an input object from a Python string */ /* Create a new output object */
static PyObject *(*PycStringIO_NewInput)(PyObject *)=NULL; PyObject *(*NewOutput)(int);
/* The Python types for cStringIO input and output objects. /* 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. 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)
{
PyObject *m, *c;
void *r=NULL;
#define IMPORT_C_OBJECT(N) \ if(m=PyImport_ImportModule(module_name))
if((PycStringIO_CObject=PyObject_GetAttrString(PycStringIO_Module, #N))) { \ {
PycStringIO_ ## N = PyCObject_AsVoidPtr(PycStringIO_CObject); \ if(c=PyObject_GetAttrString(m,name))
Py_DECREF(PycStringIO_CObject); } {
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 */