Skip to content

Adding tp_reachable#65

Open
mjp41 wants to merge 6 commits intoimmutable-mainfrom
tp_reaches
Open

Adding tp_reachable#65
mjp41 wants to merge 6 commits intoimmutable-mainfrom
tp_reaches

Conversation

@mjp41
Copy link
Owner

@mjp41 mjp41 commented Jan 16, 2026


📚 Documentation preview 📚: https://cpython-previews--65.org.readthedocs.build/

Copy link
Collaborator

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

The addition itself looks good, but it doesn't set the tp_reachable for most built-in types. Once that is done it should be good to go.

@mjp41
Copy link
Owner Author

mjp41 commented Jan 19, 2026

The addition itself looks good, but it doesn't set the tp_reachable for most built-in types. Once that is done it should be good to go.

Sounds good. I mostly wanted to get someone else's eyes on it, and then we can decide how broad a blast radius we want.

Comment on lines 132 to 143
static PyObject *
immutable_clear_tp_reachable(PyObject *module, PyObject *obj)
{
if (!PyType_Check(obj)) {
PyErr_SetString(PyExc_TypeError, "Expected a type");
return NULL;
}
PyTypeObject *tp = (PyTypeObject *)obj;
tp->tp_reachable = NULL;
Py_RETURN_NONE;
}

Copy link
Owner Author

Choose a reason for hiding this comment

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

Not sure I am happy exposing this for a test. We should find a better way to test this. I think we really need to build a C-Module that doesn't have tp_reachable, and never will.

Copy link
Collaborator

Choose a reason for hiding this comment

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

There are c-modules in CPython which are only used for testing. They expose C Types for testing. Would that be sufficient?

Comment on lines +2502 to +2507
if (co->_co_cached != NULL) {
Py_VISIT(co->_co_cached->_co_code);
Py_VISIT(co->_co_cached->_co_varnames);
Py_VISIT(co->_co_cached->_co_cellvars);
Py_VISIT(co->_co_cached->_co_freevars);
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

This makes me worry about write barriers on the cache. There is a lot of stuff around modifying this for NoGIL

Comment on lines 8386 to 8390
/*
* TODO: We should discuss this. I am a little confused about the
* correct way to do this. This gives a good level of compatibility,
* but is perhaps too much.
*
Copy link
Owner Author

Choose a reason for hiding this comment

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

Can we discuss this?

@mjp41 mjp41 requested a review from xFrednet February 27, 2026 09:41
@mjp41 mjp41 marked this pull request as ready for review February 27, 2026 09:41
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.

2 participants