Skip to content

Commit

Permalink
Adjust for _PyLong_AsByteArray signature change in Python 3.13 (#1344)
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Williamson <awilliam@redhat.com>
  • Loading branch information
AdamWill authored and mkleehammer committed Sep 8, 2024
1 parent 7a710e7 commit c913dc8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,13 @@ static int PyToCType(Cursor *cur, unsigned char **outbuf, PyObject *cell, ParamI
pNum->precision = (SQLCHAR)pi->ColumnSize;
pNum->scale = (SQLCHAR)pi->DecimalDigits;
pNum->sign = _PyLong_Sign(cell) >= 0;
if (_PyLong_AsByteArray((PyLongObject*)absVal, pNum->val, sizeof(pNum->val), 1, 0))
#if PY_VERSION_HEX < 0x030D0000
if (_PyLong_AsByteArray((PyLongObject*)absVal, pNum->val, sizeof(pNum->val), 1, 0)) {
#else
if (_PyLong_AsByteArray((PyLongObject*)absVal, pNum->val, sizeof(pNum->val), 1, 0, 1)) {
#endif
goto NumericOverflow;
}
Py_XDECREF(absVal);
*outbuf += pi->BufferLength;
ind = sizeof(SQL_NUMERIC_STRUCT);
Expand Down Expand Up @@ -477,7 +482,12 @@ static int PyToCType(Cursor *cur, unsigned char **outbuf, PyObject *cell, ParamI
pNum->precision = (SQLCHAR)pi->ColumnSize;
pNum->scale = (SQLCHAR)pi->DecimalDigits;


#if PY_VERSION_HEX < 0x030D0000
int ret = _PyLong_AsByteArray((PyLongObject*)digitLong, pNum->val, sizeof(pNum->val), 1, 0);
#else
int ret = _PyLong_AsByteArray((PyLongObject*)digitLong, pNum->val, sizeof(pNum->val), 1, 0, 1);
#endif
Py_XDECREF(digitLong);
if (ret)
{
Expand Down

0 comments on commit c913dc8

Please sign in to comment.