Skip to content

Fix new 3.14 C API deprecation for _PyLong_Sign #2603

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions com/win32com/src/oleargs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,14 @@ BOOL PyCom_VariantFromPyObject(PyObject *obj, VARIANT *var)
V_BOOL(var) = VARIANT_FALSE;
}
else if (PyLong_Check(obj)) {
#if PY_VERSION_HEX >= 0x03140000
int sign;
if (!PyLong_GetSign(obj, sign)) {
return NULL
}
Comment on lines +142 to +145
Copy link
Collaborator Author

@Avasam Avasam May 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My lack of C++ expertise will show here, but according to the doc: https://docs.python.org/3.14/c-api/long.html#c.PyLong_GetSign

On failure, return -1 with an exception set.

So iiuc, to properly bubble up that exception, I just have to return NULL ? Or is there something else I need to do as well.

Note that the rest of this function always returns FALSE when PyErr_Occurred(). So maybe I want to return FALSE here as well for consistency ?

#else
int sign = _PyLong_Sign(obj);
#endif
size_t nbits = _PyLong_NumBits(obj);
if (nbits == (size_t)-1 && PyErr_Occurred())
return FALSE;
Expand Down
Loading