Skip to content

Commit 96f15f4

Browse files
Move declaration of Python types, methods and members to the end of the file in
order to avoid unnecessary forward declarations.
1 parent dd49259 commit 96f15f4

22 files changed

+1190
-1581
lines changed

src/cxoApiType.c

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,6 @@
1010

1111
#include "cxoModule.h"
1212

13-
//-----------------------------------------------------------------------------
14-
// declaration of functions
15-
//-----------------------------------------------------------------------------
16-
static void cxoApiType_free(cxoApiType*);
17-
static PyObject *cxoApiType_repr(cxoApiType*);
18-
19-
20-
//-----------------------------------------------------------------------------
21-
// declaration of members
22-
//-----------------------------------------------------------------------------
23-
static PyMemberDef cxoMembers[] = {
24-
{ "name", T_STRING, offsetof(cxoApiType, name), READONLY },
25-
{ NULL }
26-
};
27-
28-
29-
//-----------------------------------------------------------------------------
30-
// Python type declaration
31-
//-----------------------------------------------------------------------------
32-
PyTypeObject cxoPyTypeApiType = {
33-
PyVarObject_HEAD_INIT(NULL, 0)
34-
.tp_name = "cx_Oracle.ApiType",
35-
.tp_basicsize = sizeof(cxoApiType),
36-
.tp_dealloc = (destructor) cxoApiType_free,
37-
.tp_repr = (reprfunc) cxoApiType_repr,
38-
.tp_flags = Py_TPFLAGS_DEFAULT,
39-
.tp_members = cxoMembers
40-
};
41-
42-
4313
//-----------------------------------------------------------------------------
4414
// cxoApiType_free()
4515
// Free the API type object.
@@ -74,3 +44,26 @@ static PyObject *cxoApiType_repr(cxoApiType *apiType)
7444
Py_DECREF(apiTypeName);
7545
return result;
7646
}
47+
48+
49+
//-----------------------------------------------------------------------------
50+
// declaration of members
51+
//-----------------------------------------------------------------------------
52+
static PyMemberDef cxoMembers[] = {
53+
{ "name", T_STRING, offsetof(cxoApiType, name), READONLY },
54+
{ NULL }
55+
};
56+
57+
58+
//-----------------------------------------------------------------------------
59+
// Python type declaration
60+
//-----------------------------------------------------------------------------
61+
PyTypeObject cxoPyTypeApiType = {
62+
PyVarObject_HEAD_INIT(NULL, 0)
63+
.tp_name = "cx_Oracle.ApiType",
64+
.tp_basicsize = sizeof(cxoApiType),
65+
.tp_dealloc = (destructor) cxoApiType_free,
66+
.tp_repr = (reprfunc) cxoApiType_repr,
67+
.tp_flags = Py_TPFLAGS_DEFAULT,
68+
.tp_members = cxoMembers
69+
};

src/cxoConnection.c

Lines changed: 134 additions & 192 deletions
Large diffs are not rendered by default.

src/cxoCursor.c

Lines changed: 129 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -14,139 +14,6 @@
1414

1515
#include "cxoModule.h"
1616

17-
//-----------------------------------------------------------------------------
18-
// functions for the Python type "Cursor"
19-
//-----------------------------------------------------------------------------
20-
static void cxoCursor_free(cxoCursor*);
21-
static PyObject *cxoCursor_getIter(cxoCursor*);
22-
static PyObject *cxoCursor_getNext(cxoCursor*);
23-
static PyObject *cxoCursor_close(cxoCursor*, PyObject*);
24-
static PyObject *cxoCursor_callFunc(cxoCursor*, PyObject*, PyObject*);
25-
static PyObject *cxoCursor_callProc(cxoCursor*, PyObject*, PyObject*);
26-
static PyObject *cxoCursor_execute(cxoCursor*, PyObject*, PyObject*);
27-
static PyObject *cxoCursor_executeMany(cxoCursor*, PyObject*, PyObject*);
28-
static PyObject *cxoCursor_executeManyPrepared(cxoCursor*, PyObject*);
29-
static PyObject *cxoCursor_fetchOne(cxoCursor*, PyObject*);
30-
static PyObject *cxoCursor_fetchMany(cxoCursor*, PyObject*, PyObject*);
31-
static PyObject *cxoCursor_fetchAll(cxoCursor*, PyObject*);
32-
static PyObject *cxoCursor_fetchRaw(cxoCursor*, PyObject*, PyObject*);
33-
static PyObject *cxoCursor_parse(cxoCursor*, PyObject*);
34-
static PyObject *cxoCursor_prepare(cxoCursor*, PyObject*);
35-
static PyObject *cxoCursor_scroll(cxoCursor*, PyObject*, PyObject*);
36-
static PyObject *cxoCursor_setInputSizes(cxoCursor*, PyObject*, PyObject*);
37-
static PyObject *cxoCursor_setOutputSize(cxoCursor*, PyObject*);
38-
static PyObject *cxoCursor_var(cxoCursor*, PyObject*, PyObject*);
39-
static PyObject *cxoCursor_arrayVar(cxoCursor*, PyObject*);
40-
static PyObject *cxoCursor_bindNames(cxoCursor*, PyObject*);
41-
static PyObject *cxoCursor_getDescription(cxoCursor*, void*);
42-
static PyObject *cxoCursor_getLastRowid(cxoCursor*, void*);
43-
static PyObject *cxoCursor_getPrefetchRows(cxoCursor*, void*);
44-
static PyObject *cxoCursor_new(PyTypeObject*, PyObject*, PyObject*);
45-
static int cxoCursor_init(cxoCursor*, PyObject*, PyObject*);
46-
static PyObject *cxoCursor_repr(cxoCursor*);
47-
static PyObject* cxoCursor_getBatchErrors(cxoCursor*);
48-
static PyObject *cxoCursor_getArrayDMLRowCounts(cxoCursor*);
49-
static PyObject *cxoCursor_getImplicitResults(cxoCursor*);
50-
static PyObject *cxoCursor_contextManagerEnter(cxoCursor*, PyObject*);
51-
static PyObject *cxoCursor_contextManagerExit(cxoCursor*, PyObject*);
52-
static int cxoCursor_performDefine(cxoCursor*, uint32_t);
53-
static int cxoCursor_setPrefetchRows(cxoCursor*, PyObject*, void*);
54-
55-
56-
//-----------------------------------------------------------------------------
57-
// declaration of methods for Python type
58-
//-----------------------------------------------------------------------------
59-
static PyMethodDef cxoCursorMethods[] = {
60-
{ "execute", (PyCFunction) cxoCursor_execute,
61-
METH_VARARGS | METH_KEYWORDS },
62-
{ "fetchall", (PyCFunction) cxoCursor_fetchAll, METH_NOARGS },
63-
{ "fetchone", (PyCFunction) cxoCursor_fetchOne, METH_NOARGS },
64-
{ "fetchmany", (PyCFunction) cxoCursor_fetchMany,
65-
METH_VARARGS | METH_KEYWORDS },
66-
{ "fetchraw", (PyCFunction) cxoCursor_fetchRaw,
67-
METH_VARARGS | METH_KEYWORDS },
68-
{ "prepare", (PyCFunction) cxoCursor_prepare, METH_VARARGS },
69-
{ "parse", (PyCFunction) cxoCursor_parse, METH_O },
70-
{ "setinputsizes", (PyCFunction) cxoCursor_setInputSizes,
71-
METH_VARARGS | METH_KEYWORDS },
72-
{ "executemany", (PyCFunction) cxoCursor_executeMany,
73-
METH_VARARGS | METH_KEYWORDS },
74-
{ "callproc", (PyCFunction) cxoCursor_callProc,
75-
METH_VARARGS | METH_KEYWORDS },
76-
{ "callfunc", (PyCFunction) cxoCursor_callFunc,
77-
METH_VARARGS | METH_KEYWORDS },
78-
{ "executemanyprepared", (PyCFunction) cxoCursor_executeManyPrepared,
79-
METH_VARARGS },
80-
{ "setoutputsize", (PyCFunction) cxoCursor_setOutputSize, METH_VARARGS },
81-
{ "scroll", (PyCFunction) cxoCursor_scroll, METH_VARARGS | METH_KEYWORDS },
82-
{ "var", (PyCFunction) cxoCursor_var, METH_VARARGS | METH_KEYWORDS },
83-
{ "arrayvar", (PyCFunction) cxoCursor_arrayVar, METH_VARARGS },
84-
{ "bindnames", (PyCFunction) cxoCursor_bindNames, METH_NOARGS },
85-
{ "close", (PyCFunction) cxoCursor_close, METH_NOARGS },
86-
{ "getbatcherrors", (PyCFunction) cxoCursor_getBatchErrors, METH_NOARGS },
87-
{ "getarraydmlrowcounts", (PyCFunction) cxoCursor_getArrayDMLRowCounts,
88-
METH_NOARGS },
89-
{ "getimplicitresults", (PyCFunction) cxoCursor_getImplicitResults,
90-
METH_NOARGS },
91-
{ "__enter__", (PyCFunction) cxoCursor_contextManagerEnter, METH_NOARGS },
92-
{ "__exit__", (PyCFunction) cxoCursor_contextManagerExit, METH_VARARGS },
93-
{ NULL, NULL }
94-
};
95-
96-
97-
//-----------------------------------------------------------------------------
98-
// declaration of members for Python type
99-
//-----------------------------------------------------------------------------
100-
static PyMemberDef cxoCursorMembers[] = {
101-
{ "arraysize", T_UINT, offsetof(cxoCursor, arraySize), 0 },
102-
{ "bindarraysize", T_UINT, offsetof(cxoCursor, bindArraySize), 0 },
103-
{ "rowcount", T_ULONGLONG, offsetof(cxoCursor, rowCount), READONLY },
104-
{ "statement", T_OBJECT, offsetof(cxoCursor, statement), READONLY },
105-
{ "connection", T_OBJECT_EX, offsetof(cxoCursor, connection), READONLY },
106-
{ "rowfactory", T_OBJECT, offsetof(cxoCursor, rowFactory), 0 },
107-
{ "bindvars", T_OBJECT, offsetof(cxoCursor, bindVariables), READONLY },
108-
{ "fetchvars", T_OBJECT, offsetof(cxoCursor, fetchVariables), READONLY },
109-
{ "inputtypehandler", T_OBJECT, offsetof(cxoCursor, inputTypeHandler),
110-
0 },
111-
{ "outputtypehandler", T_OBJECT, offsetof(cxoCursor, outputTypeHandler),
112-
0 },
113-
{ "scrollable", T_BOOL, offsetof(cxoCursor, isScrollable), 0 },
114-
{ NULL }
115-
};
116-
117-
118-
//-----------------------------------------------------------------------------
119-
// declaration of calculated members for Python type
120-
//-----------------------------------------------------------------------------
121-
static PyGetSetDef cxoCursorCalcMembers[] = {
122-
{ "description", (getter) cxoCursor_getDescription, 0, 0, 0 },
123-
{ "lastrowid", (getter) cxoCursor_getLastRowid, 0, 0, 0 },
124-
{ "prefetchrows", (getter) cxoCursor_getPrefetchRows,
125-
(setter) cxoCursor_setPrefetchRows, 0, 0 },
126-
{ NULL }
127-
};
128-
129-
130-
//-----------------------------------------------------------------------------
131-
// declaration of Python type "Cursor"
132-
//-----------------------------------------------------------------------------
133-
PyTypeObject cxoPyTypeCursor = {
134-
PyVarObject_HEAD_INIT(NULL, 0)
135-
.tp_name = "cx_Oracle.Cursor",
136-
.tp_basicsize = sizeof(cxoCursor),
137-
.tp_dealloc = (destructor) cxoCursor_free,
138-
.tp_repr = (reprfunc) cxoCursor_repr,
139-
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
140-
.tp_iter = (getiterfunc) cxoCursor_getIter,
141-
.tp_iternext = (iternextfunc) cxoCursor_getNext,
142-
.tp_methods = cxoCursorMethods,
143-
.tp_members = cxoCursorMembers,
144-
.tp_getset = cxoCursorCalcMembers,
145-
.tp_init = (initproc) cxoCursor_init,
146-
.tp_new = cxoCursor_new
147-
};
148-
149-
15017
//-----------------------------------------------------------------------------
15118
// cxoCursor_new()
15219
// Create a new cursor object.
@@ -254,41 +121,6 @@ static int cxoCursor_isOpen(cxoCursor *cursor)
254121
}
255122

256123

257-
//-----------------------------------------------------------------------------
258-
// cxoCursor_verifyFetch()
259-
// Verify that fetching may happen from this cursor.
260-
//-----------------------------------------------------------------------------
261-
static int cxoCursor_verifyFetch(cxoCursor *cursor)
262-
{
263-
uint32_t numQueryColumns;
264-
265-
// make sure the cursor is open
266-
if (cxoCursor_isOpen(cursor) < 0)
267-
return -1;
268-
269-
// fixup REF cursor, if applicable
270-
if (cursor->fixupRefCursor) {
271-
cursor->fetchArraySize = cursor->arraySize;
272-
if (dpiStmt_setFetchArraySize(cursor->handle,
273-
cursor->fetchArraySize) < 0)
274-
return cxoError_raiseAndReturnInt();
275-
if (dpiStmt_getNumQueryColumns(cursor->handle, &numQueryColumns) < 0)
276-
return cxoError_raiseAndReturnInt();
277-
if (cxoCursor_performDefine(cursor, numQueryColumns) < 0)
278-
return cxoError_raiseAndReturnInt();
279-
cursor->fixupRefCursor = 0;
280-
}
281-
282-
// make sure the cursor is for a query
283-
if (!cursor->fetchVariables) {
284-
cxoError_raiseFromString(cxoInterfaceErrorException, "not a query");
285-
return -1;
286-
}
287-
288-
return 0;
289-
}
290-
291-
292124
//-----------------------------------------------------------------------------
293125
// cxoCursor_fetchRow()
294126
// Fetch a single row from the cursor. Internally the number of rows left in
@@ -453,6 +285,41 @@ static int cxoCursor_performDefine(cxoCursor *cursor, uint32_t numQueryColumns)
453285
}
454286

455287

288+
//-----------------------------------------------------------------------------
289+
// cxoCursor_verifyFetch()
290+
// Verify that fetching may happen from this cursor.
291+
//-----------------------------------------------------------------------------
292+
static int cxoCursor_verifyFetch(cxoCursor *cursor)
293+
{
294+
uint32_t numQueryColumns;
295+
296+
// make sure the cursor is open
297+
if (cxoCursor_isOpen(cursor) < 0)
298+
return -1;
299+
300+
// fixup REF cursor, if applicable
301+
if (cursor->fixupRefCursor) {
302+
cursor->fetchArraySize = cursor->arraySize;
303+
if (dpiStmt_setFetchArraySize(cursor->handle,
304+
cursor->fetchArraySize) < 0)
305+
return cxoError_raiseAndReturnInt();
306+
if (dpiStmt_getNumQueryColumns(cursor->handle, &numQueryColumns) < 0)
307+
return cxoError_raiseAndReturnInt();
308+
if (cxoCursor_performDefine(cursor, numQueryColumns) < 0)
309+
return cxoError_raiseAndReturnInt();
310+
cursor->fixupRefCursor = 0;
311+
}
312+
313+
// make sure the cursor is for a query
314+
if (!cursor->fetchVariables) {
315+
cxoError_raiseFromString(cxoInterfaceErrorException, "not a query");
316+
return -1;
317+
}
318+
319+
return 0;
320+
}
321+
322+
456323
//-----------------------------------------------------------------------------
457324
// cxoCursor_itemDescription()
458325
// Return a tuple describing the item at the given position.
@@ -2239,3 +2106,97 @@ static int cxoCursor_setPrefetchRows(cxoCursor* cursor, PyObject *value,
22392106
return cxoError_raiseAndReturnInt();
22402107
return 0;
22412108
}
2109+
2110+
2111+
//-----------------------------------------------------------------------------
2112+
// declaration of methods for Python type
2113+
//-----------------------------------------------------------------------------
2114+
static PyMethodDef cxoMethods[] = {
2115+
{ "execute", (PyCFunction) cxoCursor_execute,
2116+
METH_VARARGS | METH_KEYWORDS },
2117+
{ "fetchall", (PyCFunction) cxoCursor_fetchAll, METH_NOARGS },
2118+
{ "fetchone", (PyCFunction) cxoCursor_fetchOne, METH_NOARGS },
2119+
{ "fetchmany", (PyCFunction) cxoCursor_fetchMany,
2120+
METH_VARARGS | METH_KEYWORDS },
2121+
{ "fetchraw", (PyCFunction) cxoCursor_fetchRaw,
2122+
METH_VARARGS | METH_KEYWORDS },
2123+
{ "prepare", (PyCFunction) cxoCursor_prepare, METH_VARARGS },
2124+
{ "parse", (PyCFunction) cxoCursor_parse, METH_O },
2125+
{ "setinputsizes", (PyCFunction) cxoCursor_setInputSizes,
2126+
METH_VARARGS | METH_KEYWORDS },
2127+
{ "executemany", (PyCFunction) cxoCursor_executeMany,
2128+
METH_VARARGS | METH_KEYWORDS },
2129+
{ "callproc", (PyCFunction) cxoCursor_callProc,
2130+
METH_VARARGS | METH_KEYWORDS },
2131+
{ "callfunc", (PyCFunction) cxoCursor_callFunc,
2132+
METH_VARARGS | METH_KEYWORDS },
2133+
{ "executemanyprepared", (PyCFunction) cxoCursor_executeManyPrepared,
2134+
METH_VARARGS },
2135+
{ "setoutputsize", (PyCFunction) cxoCursor_setOutputSize, METH_VARARGS },
2136+
{ "scroll", (PyCFunction) cxoCursor_scroll, METH_VARARGS | METH_KEYWORDS },
2137+
{ "var", (PyCFunction) cxoCursor_var, METH_VARARGS | METH_KEYWORDS },
2138+
{ "arrayvar", (PyCFunction) cxoCursor_arrayVar, METH_VARARGS },
2139+
{ "bindnames", (PyCFunction) cxoCursor_bindNames, METH_NOARGS },
2140+
{ "close", (PyCFunction) cxoCursor_close, METH_NOARGS },
2141+
{ "getbatcherrors", (PyCFunction) cxoCursor_getBatchErrors, METH_NOARGS },
2142+
{ "getarraydmlrowcounts", (PyCFunction) cxoCursor_getArrayDMLRowCounts,
2143+
METH_NOARGS },
2144+
{ "getimplicitresults", (PyCFunction) cxoCursor_getImplicitResults,
2145+
METH_NOARGS },
2146+
{ "__enter__", (PyCFunction) cxoCursor_contextManagerEnter, METH_NOARGS },
2147+
{ "__exit__", (PyCFunction) cxoCursor_contextManagerExit, METH_VARARGS },
2148+
{ NULL, NULL }
2149+
};
2150+
2151+
2152+
//-----------------------------------------------------------------------------
2153+
// declaration of members for Python type
2154+
//-----------------------------------------------------------------------------
2155+
static PyMemberDef cxoMembers[] = {
2156+
{ "arraysize", T_UINT, offsetof(cxoCursor, arraySize), 0 },
2157+
{ "bindarraysize", T_UINT, offsetof(cxoCursor, bindArraySize), 0 },
2158+
{ "rowcount", T_ULONGLONG, offsetof(cxoCursor, rowCount), READONLY },
2159+
{ "statement", T_OBJECT, offsetof(cxoCursor, statement), READONLY },
2160+
{ "connection", T_OBJECT_EX, offsetof(cxoCursor, connection), READONLY },
2161+
{ "rowfactory", T_OBJECT, offsetof(cxoCursor, rowFactory), 0 },
2162+
{ "bindvars", T_OBJECT, offsetof(cxoCursor, bindVariables), READONLY },
2163+
{ "fetchvars", T_OBJECT, offsetof(cxoCursor, fetchVariables), READONLY },
2164+
{ "inputtypehandler", T_OBJECT, offsetof(cxoCursor, inputTypeHandler),
2165+
0 },
2166+
{ "outputtypehandler", T_OBJECT, offsetof(cxoCursor, outputTypeHandler),
2167+
0 },
2168+
{ "scrollable", T_BOOL, offsetof(cxoCursor, isScrollable), 0 },
2169+
{ NULL }
2170+
};
2171+
2172+
2173+
//-----------------------------------------------------------------------------
2174+
// declaration of calculated members for Python type
2175+
//-----------------------------------------------------------------------------
2176+
static PyGetSetDef cxoCalcMembers[] = {
2177+
{ "description", (getter) cxoCursor_getDescription, 0, 0, 0 },
2178+
{ "lastrowid", (getter) cxoCursor_getLastRowid, 0, 0, 0 },
2179+
{ "prefetchrows", (getter) cxoCursor_getPrefetchRows,
2180+
(setter) cxoCursor_setPrefetchRows, 0, 0 },
2181+
{ NULL }
2182+
};
2183+
2184+
2185+
//-----------------------------------------------------------------------------
2186+
// declaration of Python type
2187+
//-----------------------------------------------------------------------------
2188+
PyTypeObject cxoPyTypeCursor = {
2189+
PyVarObject_HEAD_INIT(NULL, 0)
2190+
.tp_name = "cx_Oracle.Cursor",
2191+
.tp_basicsize = sizeof(cxoCursor),
2192+
.tp_dealloc = (destructor) cxoCursor_free,
2193+
.tp_repr = (reprfunc) cxoCursor_repr,
2194+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
2195+
.tp_iter = (getiterfunc) cxoCursor_getIter,
2196+
.tp_iternext = (iternextfunc) cxoCursor_getNext,
2197+
.tp_methods = cxoMethods,
2198+
.tp_members = cxoMembers,
2199+
.tp_getset = cxoCalcMembers,
2200+
.tp_init = (initproc) cxoCursor_init,
2201+
.tp_new = cxoCursor_new
2202+
};

0 commit comments

Comments
 (0)