Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyToCType uses internal function removed from Python 3.13 #1344

Closed
mkleehammer opened this issue Apr 16, 2024 · 3 comments · Fixed by #1361
Closed

PyToCType uses internal function removed from Python 3.13 #1344

mkleehammer opened this issue Apr 16, 2024 · 3 comments · Fixed by #1361

Comments

@mkleehammer
Copy link
Owner

Cannot compile using 3.13:

src/params.cpp: In function ‘int PyToCType(Cursor*, unsigned char**, PyObject*, ParamInfo*)’:
src/params.cpp:250:36: error: too few arguments to function ‘int _PyLong_AsByteArray(PyLongObject*, unsigned char*, size_t, int, int, int)’
  250 |             if (_PyLong_AsByteArray((PyLongObject*)absVal, pNum->val, sizeof(pNum->val), 1, 0))
      |                 ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We need to figure out how to bind Decimals without using this, I guess.

@v-chojas
Copy link
Contributor

We're not the only ones affected by this regression: python/cpython#111140
pyodbc is mentioned there along with some other projects.

@AdamWill
Copy link
Contributor

AdamWill commented Jun 12, 2024

it seems a public function PyLong_AsNativeBytes has been added to do this job, IIUC. See https://github.com/python/cpython/blob/main/Doc/c-api/long.rst for docs on it.

As the error you get - "too few arguments" - implies, the function was re-added after it was removed, but then an extra argument, with_exceptions (an int acting as a boolean), was added in the same commit that introduced PyLong_AsNativeBytes. So for the short term, I think just adding the extra arg to the call would work. For the long term probably a good idea to switch to using the new public function, though. It seems setting with_exceptions to 1 would behave as the function did before (setting it to 0 skips raising an exception when trying to convert a negative int to unsigned).

AdamWill added a commit to AdamWill/pyodbc that referenced this issue Jun 12, 2024
@AdamWill
Copy link
Contributor

Sent #1361 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants