Replace all occurrences of PyInt_AS_LONG with PyInt_AsLong since Python 3.x

doesn't have a separate integer type.
This commit is contained in:
Anthony Tuininga 2008-10-17 03:04:48 +00:00
parent c2fbe9a801
commit 3e55613248
6 changed files with 48 additions and 19 deletions

View File

@ -623,8 +623,10 @@ static int Connection_SplitComponent(
posObj = PyObject_CallMethod(*sourceObj, "find", "s", splitString); posObj = PyObject_CallMethod(*sourceObj, "find", "s", splitString);
if (!posObj) if (!posObj)
return -1; return -1;
pos = PyInt_AS_LONG(posObj); pos = PyInt_AsLong(posObj);
Py_DECREF(posObj); Py_DECREF(posObj);
if (PyErr_Occurred())
return -1;
if (pos >= 0) { if (pos >= 0) {
size = PySequence_Size(*sourceObj); size = PySequence_Size(*sourceObj);
if (PyErr_Occurred()) if (PyErr_Occurred())
@ -907,7 +909,9 @@ static int Connection_SetStmtCacheSize(
PyErr_SetString(PyExc_TypeError, "value must be an integer"); PyErr_SetString(PyExc_TypeError, "value must be an integer");
return -1; 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, status = OCIAttrSet(self->handle, OCI_HTYPE_SVCCTX, (dvoid*) &valueToSet,
0, OCI_ATTR_STMTCACHESIZE, self->environment->errorHandle); 0, OCI_ATTR_STMTCACHESIZE, self->environment->errorHandle);
if (Environment_CheckForError(self->environment, status, if (Environment_CheckForError(self->environment, status,

View File

@ -2011,9 +2011,11 @@ static PyObject *Cursor_ArrayVar(
// determine the number of elements to create // determine the number of elements to create
if (PyList_Check(value)) if (PyList_Check(value))
numElements = PyList_GET_SIZE(value); numElements = PyList_GET_SIZE(value);
else if (PyInt_Check(value)) else if (PyInt_Check(value)) {
numElements = PyInt_AS_LONG(value); numElements = PyInt_AsLong(value);
else { if (PyErr_Occurred())
return NULL;
} else {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"expecting integer or list of values"); "expecting integer or list of values");
return NULL; return NULL;

View File

@ -354,9 +354,13 @@ static int NumberVar_GetFormatAndTextFromDecimal(
PyObject *digits; PyObject *digits;
// acquire basic information from the value tuple // 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); 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); numDigits = PyTuple_GET_SIZE(digits);
// allocate memory for the string and format to use in conversion // allocate memory for the string and format to use in conversion
@ -378,8 +382,13 @@ static int NumberVar_GetFormatAndTextFromDecimal(
*textPtr++ = '-'; *textPtr++ = '-';
for (i = 0; i < numDigits + scale; i++) { for (i = 0; i < numDigits + scale; i++) {
*formatPtr++ = '9'; *formatPtr++ = '9';
if (i < numDigits) if (i < numDigits) {
digit = PyInt_AS_LONG(PyTuple_GetItem(digits, i)); digit = PyInt_AsLong(PyTuple_GetItem(digits, i));
if (PyErr_Occurred()) {
PyMem_Free(textValue);
return -1;
}
}
else digit = 0; else digit = 0;
*textPtr++ = '0' + (char) digit; *textPtr++ = '0' + (char) digit;
} }
@ -390,7 +399,13 @@ static int NumberVar_GetFormatAndTextFromDecimal(
*formatPtr++ = '9'; *formatPtr++ = '9';
if (numDigits + i < 0) if (numDigits + i < 0)
digit = 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; *textPtr++ = '0' + (char) digit;
} }
} }

View File

@ -515,7 +515,9 @@ static int SessionPool_SetOCIAttr(
PyErr_SetString(PyExc_TypeError, "value must be an integer"); PyErr_SetString(PyExc_TypeError, "value must be an integer");
return -1; 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, status = OCIAttrSet(self->handle, OCI_HTYPE_SPOOL, &ociValue, 0,
*attribute, self->environment->errorHandle); *attribute, self->environment->errorHandle);
if (Environment_CheckForError(self->environment, status, if (Environment_CheckForError(self->environment, status,

View File

@ -737,8 +737,9 @@ static udt_Variable *Variable_NewArrayByType(
udt_Cursor *cursor, // cursor to bind variable to udt_Cursor *cursor, // cursor to bind variable to
PyObject *value) // value to bind PyObject *value) // value to bind
{ {
PyObject *type, *numElements; PyObject *typeObj, *numElementsObj;
udt_VariableType *varType; udt_VariableType *varType;
unsigned numElements;
udt_Variable *var; udt_Variable *var;
if (PyList_GET_SIZE(value) != 2) { if (PyList_GET_SIZE(value) != 2) {
@ -747,20 +748,22 @@ static udt_Variable *Variable_NewArrayByType(
return NULL; return NULL;
} }
type = PyList_GET_ITEM(value, 0); typeObj = PyList_GET_ITEM(value, 0);
numElements = PyList_GET_ITEM(value, 1); numElementsObj = PyList_GET_ITEM(value, 1);
if (!PyInt_Check(numElements)) { if (!PyInt_Check(numElementsObj)) {
PyErr_SetString(g_ProgrammingErrorException, PyErr_SetString(g_ProgrammingErrorException,
"number of elements must be an integer"); "number of elements must be an integer");
return NULL; return NULL;
} }
varType = Variable_TypeByPythonType(cursor, type); varType = Variable_TypeByPythonType(cursor, typeObj);
if (!varType) if (!varType)
return NULL; return NULL;
var = Variable_New(cursor, PyInt_AS_LONG(numElements), varType, numElements = PyInt_AsLong(numElementsObj);
varType->elementLength); if (PyErr_Occurred())
return NULL;
var = Variable_New(cursor, numElements, varType, varType->elementLength);
if (!var) if (!var)
return NULL; return NULL;
if (Variable_MakeArray(var) < 0) { if (Variable_MakeArray(var) < 0) {
@ -786,7 +789,9 @@ static udt_Variable *Variable_NewByType(
// passing an integer is assumed to be a string // passing an integer is assumed to be a string
if (PyInt_Check(value)) { if (PyInt_Check(value)) {
maxLength = PyInt_AS_LONG(value); maxLength = PyInt_AsLong(value);
if (PyErr_Occurred())
return NULL;
if (maxLength > MAX_STRING_CHARS) if (maxLength > MAX_STRING_CHARS)
varType = &vt_LongString; varType = &vt_LongString;
else varType = &vt_String; else varType = &vt_String;

View File

@ -49,6 +49,7 @@ typedef int Py_ssize_t;
#ifndef PyInt_Check #ifndef PyInt_Check
#define PyInt_Check PyLong_Check #define PyInt_Check PyLong_Check
#define PyInt_FromLong PyLong_FromLong #define PyInt_FromLong PyLong_FromLong
#define PyInt_AsLong PyLong_AsLong
#define PyInt_Type PyLong_Type #define PyInt_Type PyLong_Type
#endif #endif