Skip to content

gh-146102: Catch PyErr_NewException() failure in zlib - #151342

Closed
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:zlib
Closed

gh-146102: Catch PyErr_NewException() failure in zlib#151342
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:zlib

Conversation

@vstinner

@vstinnervstinner commented Jun 11, 2026

Copy link
Copy Markdown
Member

@vstinner

Copy link
Copy Markdown
MemberAuthor

Comment threadModules/zlibmodule.c
if (state->ZlibError == NULL) {
return -1;
}
if (PyModule_AddObjectRef(mod, "error", state->ZlibError) < 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This isn't strictly necessary, PyModule_AddObjectRef will return -1 if it's NULL. Looking at other modules, they also follow this pattern.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Oh you're right! I checked PyModule_AddObjectRef() documentation and it's well documented:

To be convenient, the function accepts NULLvalue with an exception
set. In this case, return -1 and just leave the raised exception
unchanged.

@vstinner

Copy link
Copy Markdown
MemberAuthor

This change is not needed. I close the PR.

@vstinner
vstinner deleted the zlib branch June 11, 2026 14:54
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@vstinner@StanFromIreland