Skip to content

bpo-46449: Fix refcount of deepfrozen code #30984

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ find_frozen(PyObject *nameobj, struct frozen_info *info)
if (info != NULL) {
info->nameobj = nameobj; // borrowed
info->data = (const char *)p->code;
info->get_code = p->get_code;
info->get_code = p->get_code; // function returns borrowed ref
info->size = p->size < 0 ? -(p->size) : p->size;
info->is_package = p->size < 0 ? true : false;
info->origname = name;
Expand All @@ -1321,7 +1321,7 @@ unmarshal_frozen_code(struct frozen_info *info)
if (info->get_code) {
PyObject *code = info->get_code();
assert(code != NULL);
return code;
return Py_NewRef(code);
Copy link
Member

@vstinner vstinner Jan 28, 2022

Choose a reason for hiding this comment

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

The get_code() function was added to the _frozen structure in Python 3.11. New C API functions must no longer return borrowed references, but strong references: https://devguide.python.org/c-api/#public-c-api

Would it be possible to change the generated code to return strong references instead? I don't understand how deepfreeze generates its "get_code()" functions.

cc @kumaraditya303

Copy link
Contributor

Choose a reason for hiding this comment

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

}
PyObject *co = PyMarshal_ReadObjectFromString(info->data, info->size);
if (co == NULL) {
Expand Down