Skip to content

Commit cc067bf

Browse files
Binary integer variables now explicitly convert values to integers (since
implicit conversion to integer has become an error in Python 3.10) and values that are not `int`, `float` or `decimal.Decimal` are explicitly rejected.
1 parent abb6667 commit cc067bf

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

doc/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Version 8.3 (TBD)
1313
#) Updated embedded ODPI-C to `version 4.3.0
1414
<https://oracle.github.io/odpi/doc/releasenotes.html#
1515
version-4-3-tbd>`__.
16+
#) Binary integer variables now explicitly convert values to integers (since
17+
implicit conversion to integer has become an error in Python 3.10) and
18+
values that are not `int`, `float` or `decimal.Decimal` are explicitly
19+
rejected.
1620

1721

1822
Version 8.2.1 (June 2021)

src/cxoTransform.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ int cxoTransform_fromPython(cxoTransformNum transformNum,
244244
dpiIntervalDS *interval;
245245
PyDateTime_Delta *delta;
246246
int32_t deltaSeconds;
247-
PyObject *textValue;
247+
PyObject *tempValue;
248248
cxoObject *obj;
249249
cxoLob *lob;
250250
int status;
@@ -316,10 +316,21 @@ int cxoTransform_fromPython(cxoTransformNum transformNum,
316316
dbValue->asInt64 = (pyValue == Py_True);
317317
return 0;
318318
}
319-
dbValue->asInt64 = PyLong_AsLong(pyValue);
320-
if (PyErr_Occurred())
319+
if (!PyFloat_Check(pyValue) &&
320+
!PyLong_Check(pyValue) &&
321+
!PyObject_TypeCheck(pyValue, cxoPyTypeDecimal)) {
322+
PyErr_SetString(PyExc_TypeError,
323+
"expecting number or boolean");
321324
return -1;
322-
return 0;
325+
}
326+
tempValue = PyObject_CallFunctionObjArgs((PyObject*) &PyLong_Type,
327+
pyValue, NULL);
328+
if (!tempValue)
329+
return -1;
330+
dbValue->asInt64 = PyLong_AsLong(tempValue);
331+
status = (PyErr_Occurred()) ? -1 : 0;
332+
Py_DECREF(tempValue);
333+
return status;
323334
case CXO_TRANSFORM_INT:
324335
case CXO_TRANSFORM_DECIMAL:
325336
case CXO_TRANSFORM_FLOAT:
@@ -334,11 +345,11 @@ int cxoTransform_fromPython(cxoTransformNum transformNum,
334345
PyErr_SetString(PyExc_TypeError, "expecting number");
335346
return -1;
336347
}
337-
textValue = PyObject_Str(pyValue);
338-
if (!textValue)
348+
tempValue = PyObject_Str(pyValue);
349+
if (!tempValue)
339350
return -1;
340-
status = cxoBuffer_fromObject(buffer, textValue, encoding);
341-
Py_DECREF(textValue);
351+
status = cxoBuffer_fromObject(buffer, tempValue, encoding);
352+
Py_DECREF(tempValue);
342353
if (status < 0)
343354
return -1;
344355
}

0 commit comments

Comments
 (0)