Skip to content

Commit e91dc89

Browse files
author
guido
committed
Changed the way the C API was exported. Jim Fulton.
git-svn-id: http://svn.python.org/projects/python/trunk@7754 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent b676d0b commit e91dc89

1 file changed

Lines changed: 47 additions & 39 deletions

File tree

Include/cStringIO.h

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@
7070
This would typically be done in your init function.
7171
7272
$Log$
73-
Revision 2.2 1997/01/06 22:50:12 guido
74-
Jim's latest version
73+
Revision 2.3 1997/04/09 17:34:28 guido
74+
Changed the way the C API was exported. Jim Fulton.
75+
76+
Revision 1.2 1997/01/27 14:13:05 jim
77+
Changed the way the C API was exported.
7578
7679
Revision 1.1 1997/01/02 15:18:36 chris
7780
initial version
@@ -81,54 +84,59 @@
8184

8285
/* Basic fuctions to manipulate cStringIO objects from C */
8386

84-
/* Read a string. If the last argument is -1, the remainder will be read. */
85-
static int(*PycStringIO_cread)(PyObject *, char **, int)=NULL;
87+
static struct PycStringIO_CAPI {
88+
89+
/* Read a string. If the last argument is -1, the remainder will be read. */
90+
int(*cread)(PyObject *, char **, int);
8691

87-
/* Read a line */
88-
static int(*PycStringIO_creadline)(PyObject *, char **)=NULL;
92+
/* Read a line */
93+
int(*creadline)(PyObject *, char **);
8994

90-
/* Write a string */
91-
static int(*PycStringIO_cwrite)(PyObject *, char *, int)=NULL;
95+
/* Write a string */
96+
int(*cwrite)(PyObject *, char *, int);
9297

93-
/* Get the cStringIO object as a Python string */
94-
static PyObject *(*PycStringIO_cgetvalue)(PyObject *)=NULL;
98+
/* Get the cStringIO object as a Python string */
99+
PyObject *(*cgetvalue)(PyObject *);
95100

96-
/* Create a new output object */
97-
static PyObject *(*PycStringIO_NewOutput)(int)=NULL;
101+
/* Create a new output object */
102+
PyObject *(*NewOutput)(int);
98103

99-
/* Create an input object from a Python string */
100-
static PyObject *(*PycStringIO_NewInput)(PyObject *)=NULL;
104+
/* Create an input object from a Python string */
105+
PyObject *(*NewInput)(PyObject *);
101106

102-
/* The Python types for cStringIO input and output objects.
103-
Note that you can do input on an output object.
104-
*/
105-
static PyObject *PycStringIO_InputType=NULL, *PycStringIO_OutputType=NULL;
107+
/* The Python types for cStringIO input and output objects.
108+
Note that you can do input on an output object.
109+
*/
110+
PyTypeObject *InputType, *OutputType;
111+
112+
} * PycStringIO = NULL;
106113

107114
/* These can be used to test if you have one */
108115
#define PycStringIO_InputCheck(O) \
109-
((O)->ob_type==(PyTypeObject*)PycStringIO_InputType)
116+
((O)->ob_type==PycStringIO->InputType)
110117
#define PycStringIO_OutputCheck(O) \
111-
((O)->ob_type==(PyTypeObject*)PycStringIO_OutputType)
112-
113-
/* The following is used to implement PycString_IMPORT: */
114-
static PyObject *PycStringIO_Module=NULL, *PycStringIO_CObject=NULL;
115-
116-
#define IMPORT_C_OBJECT(N) \
117-
if((PycStringIO_CObject=PyObject_GetAttrString(PycStringIO_Module, #N))) { \
118-
PycStringIO_ ## N = PyCObject_AsVoidPtr(PycStringIO_CObject); \
119-
Py_DECREF(PycStringIO_CObject); }
118+
((O)->ob_type==PycStringIO->OutputType)
119+
120+
static void *
121+
PyCObject_Import(char *module_name, char *name)
122+
{
123+
PyObject *m, *c;
124+
void *r=NULL;
125+
126+
if(m=PyImport_ImportModule(module_name))
127+
{
128+
if(c=PyObject_GetAttrString(m,name))
129+
{
130+
r=PyCObject_AsVoidPtr(c);
131+
Py_DECREF(c);
132+
}
133+
Py_DECREF(m);
134+
}
135+
136+
return r;
137+
}
120138

121139
#define PycString_IMPORT \
122-
if((PycStringIO_Module=PyImport_ImportModule("cStringIO"))) { \
123-
PycStringIO_InputType=PyObject_GetAttrString(PycStringIO_Module, \
124-
"InputType"); \
125-
PycStringIO_OutputType=PyObject_GetAttrString(PycStringIO_Module, \
126-
"OutputType"); \
127-
IMPORT_C_OBJECT(cread); \
128-
IMPORT_C_OBJECT(creadline); \
129-
IMPORT_C_OBJECT(cwrite); \
130-
IMPORT_C_OBJECT(NewInput); \
131-
IMPORT_C_OBJECT(NewOutput); \
132-
IMPORT_C_OBJECT(cgetvalue); }
140+
PycStringIO=PyCObject_Import("cStringIO", "cStringIO_CAPI")
133141

134142
#endif /* CSTRINGIO_INCLUDED */

0 commit comments

Comments
 (0)