Skip to content
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

Move potential error earlier #7002

Merged
merged 1 commit into from Mar 12, 2023
Merged

Conversation

radarhere
Copy link
Member

For

Pillow/src/_webp.c

Lines 956 to 974 in 6b71090

static int
setup_module(PyObject *m) {
PyObject *d = PyModule_GetDict(m);
addMuxFlagToModule(m);
addAnimFlagToModule(m);
addTransparencyFlagToModule(m);
PyDict_SetItemString(
d, "webpdecoder_version", PyUnicode_FromString(WebPDecoderVersion_str()));
#ifdef HAVE_WEBPANIM
/* Ready object types */
if (PyType_Ready(&WebPAnimDecoder_Type) < 0 ||
PyType_Ready(&WebPAnimEncoder_Type) < 0) {
return -1;
}
#endif
return 0;
}

this PR rearranges the code to run the PyType_Ready conditional first, so it the code fails earlier, and d is not created for potentially no reason (m isn't used if setup_module returns -1).

@hugovk hugovk merged commit 436ebdb into python-pillow:main Mar 12, 2023
@radarhere radarhere deleted the setup_module branch March 12, 2023 11:21
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.

None yet

2 participants