-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[mypyc] Fix vtable pointer with inherited dunder new #20302
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
Changes from 2 commits
3e8d126
be8f0ff
98d7abb
499389f
54dc884
2fd137e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,3 +62,29 @@ PyObject *CPyObject_GetSlice(PyObject *obj, CPyTagged start, CPyTagged end) { | |
| Py_DECREF(slice); | ||
| return result; | ||
| } | ||
|
|
||
| typedef PyObject *(*SetupFunction)(PyObject *); | ||
|
|
||
| PyObject *CPy_SetupObject(PyObject *type) { | ||
| PyTypeObject *tp = (PyTypeObject *)type; | ||
| PyMethodDef *def = NULL; | ||
| for(; tp; tp = tp->tp_base) { | ||
| def = tp->tp_methods; | ||
| if (!def) { | ||
| continue; | ||
| } | ||
|
|
||
| while (def->ml_name && strcmp(def->ml_name, "__internal_mypyc_setup")) { | ||
|
||
| ++def; | ||
| } | ||
| if (def->ml_name) { | ||
| break; | ||
| } | ||
| } | ||
| if (!def || !def->ml_name) { | ||
| PyErr_SetString(PyExc_LookupError, "Internal error: Unable to find object setup function"); | ||
|
||
| return NULL; | ||
| } | ||
|
|
||
| return ((SetupFunction)(void(*)(void))def->ml_meth)(type); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment here explaining why a dynamic method dispatch is needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a fast path if class is known to not have subclasses -- we would still be able to use the old direct call, right?