Skip to content

gh-101408: PyObject_GC_Resize should calculate preheader size. #101741

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

Merged
merged 2 commits into from
Apr 23, 2023

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Feb 9, 2023

@corona10
Copy link
Member Author

corona10 commented Feb 9, 2023

@pablogsal @colesbury Can you please take a look?

@corona10 corona10 added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes labels Feb 9, 2023
@corona10 corona10 changed the title gh-101408: PyObject_GC_Resize should calculate preheader size. [WIP] gh-101408: PyObject_GC_Resize should calculate preheader size. Feb 9, 2023
@corona10 corona10 changed the title [WIP] gh-101408: PyObject_GC_Resize should calculate preheader size. gh-101408: PyObject_GC_Resize should calculate preheader size. Feb 9, 2023
@corona10 corona10 requested a review from colesbury February 9, 2023 15:46
Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

This LGTM!

Minor: I don't think this needs backport to 3.10 or 3.11. I think the preheader feature was introduced in 3.12.

@corona10 corona10 removed needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes labels Feb 9, 2023
@corona10
Copy link
Member Author

corona10 commented Feb 9, 2023

This LGTM!

Thank you, I will wait for the @pablogsal review too :)

@corona10 corona10 added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Feb 9, 2023
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @corona10 for commit a09708c 🤖

If you want to schedule another build, you need to add the :hammer: test-with-refleak-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Feb 9, 2023
@corona10
Copy link
Member Author

corona10 commented Feb 9, 2023

The refleak is not related to this PR, I am finding out the which PR cause the leak.

@pablogsal
Copy link
Member

Thanks a lot for tacking this @corona10 and thanks for the catch @colesbury!

I would be more comfortable if we could have a test in testcapi that uses this API, among other things so we don't regress in the future if we keep changing things.

@corona10
Copy link
Member Author

corona10 commented Feb 9, 2023

I would be more comfortable if we could have a test in testcapi that uses this API, among other things so we don't regress in the future if we keep changing things.

Okay, I will finalize the PR by end of this weekend. :)

@corona10 corona10 added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Feb 10, 2023
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @corona10 for commit 27566ab 🤖

If you want to schedule another build, you need to add the :hammer: test-with-refleak-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Feb 10, 2023
@corona10
Copy link
Member Author

corona10 commented Feb 10, 2023

@pablogsal

Hi Pablo, I succeeded in adding the test code for the normal PyObject_GC_Resize case.
But looks hard to create the test code for Py_TPFLAGS_PREHEADER.
Do you have any recommended way for this case?

static PyObject *
test_pyobject_gc(PyObject *self, PyObject *Py_UNUSED(ignored))
{
    PyTupleObject *obj = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, 3);
    obj->ob_item[0] = Py_NewRef(Py_None);
    obj->ob_item[1] = Py_NewRef(Py_None);
    obj->ob_item[2] = Py_NewRef(Py_None);

    if (obj == NULL) {
        goto alloc_failed;
    }
    if (Py_SIZE(obj) != 3) {
        Py_DECREF(obj);
        PyErr_SetString(PyExc_RuntimeError, "Invalid Py_SIZE(obj)");
        return NULL;
    }

    PyTupleObject *new_obj = PyObject_GC_Resize(PyTupleObject, obj, 6);
    if (new_obj == NULL) {
        Py_DECREF(obj);
        goto alloc_failed;
    }

    new_obj->ob_item[3] = Py_NewRef(Py_None);
    new_obj->ob_item[4] = Py_NewRef(Py_None);
    new_obj->ob_item[5] = Py_NewRef(Py_None);
    if (Py_SIZE(new_obj) != 6) {
        Py_DECREF(new_obj);
        PyErr_SetString(PyExc_RuntimeError, "Invalid Py_SIZE(new_obj)");
        return NULL;
    }

    Py_DECREF(new_obj);
    Py_RETURN_NONE;

alloc_failed:
    PyErr_NoMemory();
    return NULL;
}

@corona10 corona10 added the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Mar 2, 2023
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @corona10 for commit 896c5ba 🤖

If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section label Mar 2, 2023
@corona10
Copy link
Member Author

@pablogsal I think that this PR should be merged before 3.12 is officially released, I will let the issue as opened for test code and merging this PR.

@corona10 corona10 merged commit 9c3442c into python:main Apr 23, 2023
@corona10 corona10 deleted the gh-101408 branch April 23, 2023 18:45
@vstinner
Copy link
Member

vstinner commented Dec 2, 2023

No one wrote code since April, maybe it's time to abandon the idea of having tests and just close the issue?

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

Successfully merging this pull request may close these issues.

5 participants