-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
Crash in specialize_dict_access(): type->ht_cached_keys is NULL on a pybind11 type #96046
Comments
@rwgk: Would you mind to have a look? |
If I understood correctly, this command installed pybind11-2.10.0 in a temporary virtual environment to build the pikepdf C extensions. |
Will do. Hopefully later today. |
But I couldn't figure out how to have the pybind11 diff applied when the E.g., is there a way to run a Or can I get |
You should be able to replace the pybind11 requirement here: With a link to https://github.com/rwgk/pybind11/archive/refs/heads/undo_Py_TPFLAGS_MANAGED_DICT.zip [build-system]
requires = [
"setuptools >= 52",
"setuptools-scm[toml] >= 7.0.5",
"wheel >= 0.35",
"https://github.com/rwgk/pybind11/archive/refs/heads/undo_Py_TPFLAGS_MANAGED_DICT.zip",
]
build-backend = "setuptools.build_meta"
|
pikepdf calls pybind11 make_new_python_type() function. Simplified code: inline PyObject *make_new_python_type(const type_record &rec) {
...
auto *heap_type = (PyHeapTypeObject *) metaclass->tp_alloc(metaclass, 0);
...
type->tp_name = full_name;
type->tp_doc = tp_doc;
type->tp_base = type_incref((PyTypeObject *) base);
type->tp_basicsize = static_cast<ssize_t>(sizeof(instance));
...
type->tp_as_number = &heap_type->as_number;
type->tp_as_sequence = &heap_type->as_sequence;
type->tp_as_mapping = &heap_type->as_mapping;
type->tp_as_async = &heap_type->as_async;
...
type->tp_flags |= Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE;
...
if (PyType_Ready(type) < 0) {
pybind11_fail(std::string(rec.name) + ": PyType_Ready failed: " + error_string());
}
...
return (PyObject *) type;
} This function calls PyType_Ready() but not type_new(). Maybe type_new() initializing When PyType_Ready() is called, the caller is supposed to be done with initializing the type members, and so it's ok to set (or override) some members like |
You are not the only one who had the idea to move |
I hacked locally PyType_Ready() to initialize ht_cached_keys. With this change, building pikepdf documentation with Sphinx no longer crashes. |
Thanks a lot @hroncok! It didn't work straightaway, but with your hint and looking at the docs I could figure it out quickly: I just had to insert Good news: the pybind11 PR fixes the crash.
|
We seem to have two ways of fixing the crash now:
Should I merge the pybind11 PR? — I'm guessing yes, because that enables testing with Python 3.11rc1. Could you please confirm? |
PR #96047 is going to be merged soon: PyType_Ready() will initialize ht_cached_keys in the next Python 3.11 release. I'm not sure that pybind11 should be changed. I don't know well the effect of Py_TPFLAGS_MANAGED_DICT. |
@pablogsal this issue should be fixed. I think it shouldn't block the 3.11 release. |
The issue has the "release blocker" label. I understood that #96047 fixed pybind11. |
That was my understanding but nobody closed the issue so it was unclear if something else was missing. We should close it or remove the release blocker label if nothing else is missing here. |
I can no longer reproduce the crash. I confirm that pybind11 was fixed and works around in the 3.11 branch. I close the issue. I ran commands of the first issue comment, and it no longer crashs. Tested versions:
|
The crash occurs while building the pikepdf documentation with Sphinx. Reproduce on Fedora 36 with these commands:
gdb traceback:
Frame 0: crash in _PyDictKeys_StringLookup() because dk=NULL.
Frame 1, specialize_dict_access(): call _PyDictKeys_StringLookup(NULL, name), keys is NULL:
Fedora bug report: https://bugzilla.redhat.com/show_bug.cgi?id=2118215
The text was updated successfully, but these errors were encountered: