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

gh-111178: Generate correct signature for most self converters #128447

Merged

Conversation

erlend-aasland
Copy link
Contributor

@erlend-aasland erlend-aasland commented Jan 3, 2025

@erlend-aasland

This comment was marked as resolved.

@erlend-aasland
Copy link
Contributor Author

WDYT, @picnixz?

@picnixz
Copy link
Member

picnixz commented Jan 3, 2025

I think this is what I had in mind. I'm no more on my dev session but I'll pick your branch, create a branch with all my known UBSan fixes branches and then I'll need to manually address the remaining ones.

AFAICT, no new _impl functions were added so performances shouldn't be affected I think? (it's only pointer casts for the compiler). I'll review more in details tomorrow but thank you for the work!

@erlend-aasland
Copy link
Contributor Author

Yeah, this PR only makes sure we're using PyObject pointers in the PyMethodDef "entries". No new [clinic input] sections, no new _impl functions. Performance should not be affected.

@erlend-aasland
Copy link
Contributor Author

I'll leave this in draft so we don't create a review rush.

@erlend-aasland
Copy link
Contributor Author

Friendly ping, @picnixz!

@picnixz
Copy link
Member

picnixz commented Jan 20, 2025

Sorry for the late reply. I checked what I still need to do for other UBSan failures and there are quite a lot of places to fix. Here's what I can suggest: we first merge your PR and then we continue fixing the rest of UBSan failures. I wanted to delay this PR until the other failures are patched but there just too many errors in the clang output that it's hard to know where to start.

So, I think we can first fix those now and then continue the work normally. I'll also tag @vstinner, @encukou and @ZeroIntensity who worked with me on that matter to hear their thoughts.

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

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

+1, let's not delay this step.

@picnixz
Copy link
Member

picnixz commented Jan 20, 2025

Not sure if this is meant to be covered by this PR but:

static PyObject *
list_append(PyListObject *self, PyObject *object)
{
    PyObject *return_value = NULL;

    Py_BEGIN_CRITICAL_SECTION(self);
    return_value = list_append_impl((PyListObject *)self, object);
    Py_END_CRITICAL_SECTION();

    return return_value;
}

has not been changed. list_append (in listobject.c.h) should accept a PyObject *. Same for list_remove and others.

@picnixz
Copy link
Member

picnixz commented Jan 20, 2025

Also, the subsequent casts:

#define PY_LIST_CLEAR_METHODDEF    \
    {"clear", (PyCFunction)py_list_clear, METH_NOARGS, py_list_clear__doc__},

for

static PyObject *
py_list_clear(PyObject *self, PyObject *Py_UNUSED(ignored))
{
    PyObject *return_value = NULL;

    Py_BEGIN_CRITICAL_SECTION(self);
    return_value = py_list_clear_impl((PyListObject *)self);
    Py_END_CRITICAL_SECTION();

    return return_value;
}

are not needed but I don't know if it's possible to only remove the cast for the "fixed" methods or not.

@erlend-aasland
Copy link
Contributor Author

Correct, @picnixz, I don't think this is a complete solution. But these kinds of changes have a huge impact. It is pretty easy to validate this change, for example, but if we bake in another Argument Clinic change, it will be harder to validate the generated output. IMO, it is better to address this in a follow-up PR.

@erlend-aasland erlend-aasland merged commit 537296c into python:main Jan 20, 2025
53 checks passed
@erlend-aasland erlend-aasland deleted the ubsan/clinic-self-converters branch January 20, 2025 11:40
@erlend-aasland erlend-aasland changed the title gh-111178: Generate correct signature for self converters gh-111178: Generate correct signature for most self converters Jan 20, 2025
@picnixz
Copy link
Member

picnixz commented Jan 20, 2025

, it will be harder to validate the generated output. IMO, it is better to address this in a follow-up PR.

Sure! I just wanted to be sure that you knew about this. But yes, otherwise I validate the current change (sorry for not having said it explicitly).

@picnixz
Copy link
Member

picnixz commented Jan 20, 2025

@erlend-aasland We're having some CI failures now but I think it's because main wasn't merged recently and clinic not regen.

@erlend-aasland
Copy link
Contributor Author

Hm, yeah I guess we should've synced it before merging.

@picnixz
Copy link
Member

picnixz commented Jan 20, 2025

Do you want to make a patch? (I can also do it if you don't have the time now)

@erlend-aasland
Copy link
Contributor Author

Yes, I'm creating an amendment now. Compiling ... 🤖 🤖 🤖

erlend-aasland added a commit to erlend-aasland/cpython that referenced this pull request Jan 20, 2025
@erlend-aasland
Copy link
Contributor Author

Amendment up: #129060.

@vstinner
Copy link
Member

Nice enhancement, thanks.

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.

4 participants