From 3e55613248fc5cf9ccfa141fec5b1fe79b67b6b2 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 17 Oct 2008 03:04:48 +0000 Subject: [PATCH] Replace all occurrences of PyInt_AS_LONG with PyInt_AsLong since Python 3.x doesn't have a separate integer type. --- Connection.c | 8 ++++++-- Cursor.c | 8 +++++--- NumberVar.c | 25 ++++++++++++++++++++----- SessionPool.c | 4 +++- Variable.c | 21 +++++++++++++-------- cx_Oracle.c | 1 + 6 files changed, 48 insertions(+), 19 deletions(-) diff --git a/Connection.c b/Connection.c index 63020e9..116f72b 100644 --- a/Connection.c +++ b/Connection.c @@ -623,8 +623,10 @@ static int Connection_SplitComponent( posObj = PyObject_CallMethod(*sourceObj, "find", "s", splitString); if (!posObj) return -1; - pos = PyInt_AS_LONG(posObj); + pos = PyInt_AsLong(posObj); Py_DECREF(posObj); + if (PyErr_Occurred()) + return -1; if (pos >= 0) { size = PySequence_Size(*sourceObj); if (PyErr_Occurred()) @@ -907,7 +909,9 @@ static int Connection_SetStmtCacheSize( PyErr_SetString(PyExc_TypeError, "value must be an integer"); return -1; } - valueToSet = (ub4) PyInt_AS_LONG(value); + valueToSet = (ub4) PyInt_AsLong(value); + if (PyErr_Occurred()) + return -1; status = OCIAttrSet(self->handle, OCI_HTYPE_SVCCTX, (dvoid*) &valueToSet, 0, OCI_ATTR_STMTCACHESIZE, self->environment->errorHandle); if (Environment_CheckForError(self->environment, status, diff --git a/Cursor.c b/Cursor.c index 717ca09..94ca8ee 100644 --- a/Cursor.c +++ b/Cursor.c @@ -2011,9 +2011,11 @@ static PyObject *Cursor_ArrayVar( // determine the number of elements to create if (PyList_Check(value)) numElements = PyList_GET_SIZE(value); - else if (PyInt_Check(value)) - numElements = PyInt_AS_LONG(value); - else { + else if (PyInt_Check(value)) { + numElements = PyInt_AsLong(value); + if (PyErr_Occurred()) + return NULL; + } else { PyErr_SetString(PyExc_TypeError, "expecting integer or list of values"); return NULL; diff --git a/NumberVar.c b/NumberVar.c index 86b5dbe..491750e 100644 --- a/NumberVar.c +++ b/NumberVar.c @@ -354,9 +354,13 @@ static int NumberVar_GetFormatAndTextFromDecimal( PyObject *digits; // acquire basic information from the value tuple - sign = PyInt_AS_LONG(PyTuple_GET_ITEM(tupleValue, 0)); + sign = PyInt_AsLong(PyTuple_GET_ITEM(tupleValue, 0)); + if (PyErr_Occurred()) + return -1; digits = PyTuple_GET_ITEM(tupleValue, 1); - scale = PyInt_AS_LONG(PyTuple_GET_ITEM(tupleValue, 2)); + scale = PyInt_AsLong(PyTuple_GET_ITEM(tupleValue, 2)); + if (PyErr_Occurred()) + return -1; numDigits = PyTuple_GET_SIZE(digits); // allocate memory for the string and format to use in conversion @@ -378,8 +382,13 @@ static int NumberVar_GetFormatAndTextFromDecimal( *textPtr++ = '-'; for (i = 0; i < numDigits + scale; i++) { *formatPtr++ = '9'; - if (i < numDigits) - digit = PyInt_AS_LONG(PyTuple_GetItem(digits, i)); + if (i < numDigits) { + digit = PyInt_AsLong(PyTuple_GetItem(digits, i)); + if (PyErr_Occurred()) { + PyMem_Free(textValue); + return -1; + } + } else digit = 0; *textPtr++ = '0' + (char) digit; } @@ -390,7 +399,13 @@ static int NumberVar_GetFormatAndTextFromDecimal( *formatPtr++ = '9'; if (numDigits + i < 0) digit = 0; - else digit = PyInt_AS_LONG(PyTuple_GetItem(digits, numDigits + i)); + else { + digit = PyInt_AsLong(PyTuple_GetItem(digits, numDigits + i)); + if (PyErr_Occurred()) { + PyMem_Free(textValue); + return -1; + } + } *textPtr++ = '0' + (char) digit; } } diff --git a/SessionPool.c b/SessionPool.c index 5bc98f7..6e0b902 100644 --- a/SessionPool.c +++ b/SessionPool.c @@ -515,7 +515,9 @@ static int SessionPool_SetOCIAttr( PyErr_SetString(PyExc_TypeError, "value must be an integer"); return -1; } - ociValue = PyInt_AS_LONG(value); + ociValue = PyInt_AsLong(value); + if (PyErr_Occurred()) + return -1; status = OCIAttrSet(self->handle, OCI_HTYPE_SPOOL, &ociValue, 0, *attribute, self->environment->errorHandle); if (Environment_CheckForError(self->environment, status, diff --git a/Variable.c b/Variable.c index 8444f98..a9b8b69 100644 --- a/Variable.c +++ b/Variable.c @@ -737,8 +737,9 @@ static udt_Variable *Variable_NewArrayByType( udt_Cursor *cursor, // cursor to bind variable to PyObject *value) // value to bind { - PyObject *type, *numElements; + PyObject *typeObj, *numElementsObj; udt_VariableType *varType; + unsigned numElements; udt_Variable *var; if (PyList_GET_SIZE(value) != 2) { @@ -747,20 +748,22 @@ static udt_Variable *Variable_NewArrayByType( return NULL; } - type = PyList_GET_ITEM(value, 0); - numElements = PyList_GET_ITEM(value, 1); - if (!PyInt_Check(numElements)) { + typeObj = PyList_GET_ITEM(value, 0); + numElementsObj = PyList_GET_ITEM(value, 1); + if (!PyInt_Check(numElementsObj)) { PyErr_SetString(g_ProgrammingErrorException, "number of elements must be an integer"); return NULL; } - varType = Variable_TypeByPythonType(cursor, type); + varType = Variable_TypeByPythonType(cursor, typeObj); if (!varType) return NULL; - var = Variable_New(cursor, PyInt_AS_LONG(numElements), varType, - varType->elementLength); + numElements = PyInt_AsLong(numElementsObj); + if (PyErr_Occurred()) + return NULL; + var = Variable_New(cursor, numElements, varType, varType->elementLength); if (!var) return NULL; if (Variable_MakeArray(var) < 0) { @@ -786,7 +789,9 @@ static udt_Variable *Variable_NewByType( // passing an integer is assumed to be a string if (PyInt_Check(value)) { - maxLength = PyInt_AS_LONG(value); + maxLength = PyInt_AsLong(value); + if (PyErr_Occurred()) + return NULL; if (maxLength > MAX_STRING_CHARS) varType = &vt_LongString; else varType = &vt_String; diff --git a/cx_Oracle.c b/cx_Oracle.c index 9760575..78885d9 100644 --- a/cx_Oracle.c +++ b/cx_Oracle.c @@ -49,6 +49,7 @@ typedef int Py_ssize_t; #ifndef PyInt_Check #define PyInt_Check PyLong_Check #define PyInt_FromLong PyLong_FromLong +#define PyInt_AsLong PyLong_AsLong #define PyInt_Type PyLong_Type #endif