bpo-33625: Release GIL for grp.getgr{nam,gid} and pwd.getpw{nam,uid} by william-gr · Pull Request #7081 · python/cpython (original) (raw)

Ah! Honestly, the new PR is way better than the first version! I was going to merge it, when I spotted another issue: you don't check if PyMem_Malloc() fails. IMHO it's not a good idea to call get*() functions with buf=NULL. Maybe the function fails, maybe you get a crash... I would prefer to avoid the risk of crash :-) I proposed to move code which allocates the memory to avoid redundancy and to make sure that get*() are never called with buf=NULL.

By the way, I also proposed to fix a mojibake (encoding) issue while we are on these functions.

Maybe the mojibake issue can be fixed in a separated PR, since I don't think that we are going to backport this one to 3.7 and older. So maybe wait until this PR is merged, and then write a second PR to fix the mojibake issue, and we can easily backport the second PR to all supported branches.