@@ -132,7 +132,7 @@ grp_getgrgid_impl(PyObject *module, PyObject *id)
132132 if (!_Py_Gid_Converter (id , & gid )) {
133133 return NULL ;
134134 }
135- #if defined( HAVE_GETGRGID_R )
135+ #ifdef HAVE_GETGRGID_R
136136 int status ;
137137 Py_ssize_t bufsize ;
138138 /* Note: 'grp' will be used via pointer 'p' on getgrgid_r success. */
@@ -167,21 +167,17 @@ grp_getgrgid_impl(PyObject *module, PyObject *id)
167167 }
168168
169169 Py_END_ALLOW_THREADS
170- #elif defined( Py_GIL_DISABLED )
170+ #else
171171 static PyMutex getgrgid_mutex = {0 };
172172 PyMutex_Lock (& getgrgid_mutex );
173173 // The getgrgid() function need not be thread-safe.
174174 // https://pubs.opengroup.org/onlinepubs/9699919799/functions/getgrgid.html
175175 p = getgrgid (gid );
176+ #endif
176177 if (p == NULL ) {
177- // Unlock the mutex on error. The following error handling block will
178- // handle the rest.
178+ #ifndef HAVE_GETGRGID_R
179179 PyMutex_Unlock (& getgrgid_mutex );
180- }
181- #else
182- p = getgrgid (gid );
183180#endif
184- if (p == NULL ) {
185181 PyMem_RawFree (buf );
186182 if (nomem == 1 ) {
187183 return PyErr_NoMemory ();
@@ -194,9 +190,9 @@ grp_getgrgid_impl(PyObject *module, PyObject *id)
194190 return NULL ;
195191 }
196192 retval = mkgrent (module , p );
197- #if defined( HAVE_GETGRGID_R )
193+ #ifdef HAVE_GETGRGID_R
198194 PyMem_RawFree (buf );
199- #elif defined( Py_GIL_DISABLED )
195+ #else
200196 PyMutex_Unlock (& getgrgid_mutex );
201197#endif
202198 return retval ;
@@ -226,7 +222,7 @@ grp_getgrnam_impl(PyObject *module, PyObject *name)
226222 /* check for embedded null bytes */
227223 if (PyBytes_AsStringAndSize (bytes , & name_chars , NULL ) == -1 )
228224 goto out ;
229- #if defined( HAVE_GETGRNAM_R )
225+ #ifdef HAVE_GETGRNAM_R
230226 int status ;
231227 Py_ssize_t bufsize ;
232228 /* Note: 'grp' will be used via pointer 'p' on getgrnam_r success. */
@@ -261,21 +257,17 @@ grp_getgrnam_impl(PyObject *module, PyObject *name)
261257 }
262258
263259 Py_END_ALLOW_THREADS
264- #elif defined( Py_GIL_DISABLED )
260+ #else
265261 static PyMutex getgrnam_mutex = {0 };
266262 PyMutex_Lock (& getgrnam_mutex );
267263 // The getgrnam() function need not be thread-safe.
268264 // https://pubs.opengroup.org/onlinepubs/9699919799/functions/getgrnam.html
269265 p = getgrnam (name_chars );
266+ #endif
270267 if (p == NULL ) {
271- // Unlock the mutex on error. The following error handling block will
272- // handle the rest.
268+ #ifndef HAVE_GETGRGID_R
273269 PyMutex_Unlock (& getgrnam_mutex );
274- }
275- #else
276- p = getgrnam (name_chars );
277270#endif
278- if (p == NULL ) {
279271 if (nomem == 1 ) {
280272 PyErr_NoMemory ();
281273 }
@@ -285,7 +277,7 @@ grp_getgrnam_impl(PyObject *module, PyObject *name)
285277 goto out ;
286278 }
287279 retval = mkgrent (module , p );
288- #if !defined( HAVE_GETGRNAM_R ) && defined( Py_GIL_DISABLED )
280+ #ifndef HAVE_GETGRNAM_R
289281 PyMutex_Unlock (& getgrnam_mutex );
290282#endif
291283out :
0 commit comments