Skip to content

gh-137725: Convert faulthandler to Argument Clinic#137726

Merged
vstinner merged 7 commits intopython:mainfrom
vstinner:faulthandler_ac
Aug 16, 2025
Merged

gh-137725: Convert faulthandler to Argument Clinic#137726
vstinner merged 7 commits intopython:mainfrom
vstinner:faulthandler_ac

Conversation

@vstinner
Copy link
Copy Markdown
Member

@vstinner vstinner commented Aug 13, 2025

@ZeroIntensity ZeroIntensity self-requested a review August 13, 2025 18:42
@ZeroIntensity
Copy link
Copy Markdown
Member

I don't understand this test failure. EXCEPTION_ACCESS_VIOLATION should be defined as 0xC0000005 on Windows, which isn't negative.

@colesbury
Copy link
Copy Markdown
Contributor

EXCEPTION_ACCESS_VIOLATION is >2**31 so when it's cast to a long, which is signed and only 32-bits on Windows, it becomes negative:

cpython/Modules/faulthandler.c

Lines 1330 to 1333 in a10152f

if (PyModule_AddIntConstant(module, "_EXCEPTION_ACCESS_VIOLATION",
EXCEPTION_ACCESS_VIOLATION)) {
return -1;
}

PyAPI_FUNC(int) PyModule_AddIntConstant(PyObject *, const char *, long);

@ZeroIntensity
Copy link
Copy Markdown
Member

ZeroIntensity commented Aug 13, 2025

Ah, and it seems that PyArg_ParseTuple allows negative values for whatever reason (but AC doesn't):

static PyObject *
foo(PyObject *self, PyObject *args)
{
    unsigned int a;
    if (!PyArg_ParseTuple(args, "I", &a)) {
        return NULL;
    }
    printf("a: %u\n", a);

    Py_RETURN_NONE;
}
>>> foo(-1)
a: 4294967295

Yuck.

Comment thread Modules/faulthandler.c
Comment thread Modules/faulthandler.c Outdated
Comment thread Modules/faulthandler.c
@vstinner
Copy link
Copy Markdown
Member Author

I fixed the Windows EXCEPTION constants by using PyLong_FromUnsignedLong(). Constants and _raise_exception() are only defined for test_faulthandler, so it's ok to no longer accept negative values.

@vstinner
Copy link
Copy Markdown
Member Author

Ok, the CI does now pass. The PR is now ready for a review :-) Sorry, I should have marked it as a draft in the beginning.

Copy link
Copy Markdown
Member

@ZeroIntensity ZeroIntensity left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

This PR includes also some behavior changes (constants are positive, negative arguments rejected), so I think it may need a NEWS entry.

Or you can keep the old behavior and change it in the following PR.

Comment thread Modules/faulthandler.c Outdated
Comment thread Modules/faulthandler.c
@vstinner
Copy link
Copy Markdown
Member Author

This PR includes also some behavior changes (constants are positive, negative arguments rejected), so I think it may need a NEWS entry.

These changes only concern private functions and private constants, so I consider that they should not be documented. End users are not impacted, these functions and constants are only used by tests.

Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

Comment thread Modules/faulthandler.c
Comment thread Modules/faulthandler.c
@vstinner vstinner merged commit 5c0231c into python:main Aug 16, 2025
44 checks passed
@vstinner vstinner deleted the faulthandler_ac branch August 16, 2025 13:16
@vstinner
Copy link
Copy Markdown
Member Author

Merged, thanks for your very useful reviews!

Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants