New submission from Brandt Bucher <brandtbuc...@gmail.com>:

Many of the C stdlib modules can benefit from improved error handling during 
initialization. I've now had two PRs where the authors had reference leaks on 
error conditions, but defended their decisions by pointing to examples of 
similar idioms all over the stdlib.

The problems fall into two related categories, mostly:

- Not DECREF'ing the new module object on failure.
- Not handling errors raised by the PyModule_Add* family of functions... 
specifically, the weird steal-on-success semantics of PyModule_AddObject. I've 
already improved the docs for this, so we should see the issue less, but our 
own code should still be fixed.

I intend to turn this into a longer term project. I'll be working my way 
through these modules bit-by-bit over time, using this issue to track all of 
them (since there are a few dozen cases). I'd rather not make one huge one that 
spams all of the code owners and is impossible to review.

If anybody want to make themselves available to review/merge these as I go 
along, that would be great! Many of the ones I'll start with are just adding 
trivial DECREFs to the more popular modules (_asyncio, _contextvars, 
_functools, _random, _warnings, etc...).

----------
assignee: brandtbucher
components: Library (Lib)
messages: 356764
nosy: brandtbucher
priority: normal
severity: normal
status: open
title: Improve stdlib module initialization error handling.
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38823>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to