Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 489176e

Browse files
authored
bpo-45434: Convert Py_GETENV() macro to a function (GH-28912)
Avoid calling directly getenv() in the header file.
1 parent 9c47667 commit 489176e

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

Include/cpython/pydebug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PyAPI_DATA(int) Py_LegacyWindowsStdioFlag;
2929
/* this is a wrapper around getenv() that pays attention to
3030
Py_IgnoreEnvironmentFlag. It should be used for getting variables like
3131
PYTHONPATH and PYTHONHOME from the environment */
32-
#define Py_GETENV(s) (Py_IgnoreEnvironmentFlag ? NULL : getenv(s))
32+
PyAPI_DATA(char*) Py_GETENV(const char *name);
3333

3434
#ifdef __cplusplus
3535
}

Python/initconfig.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ _Py_GetGlobalVariablesAsDict(void)
249249
#undef SET_ITEM_STR
250250
}
251251

252+
char*
253+
Py_GETENV(const char *name)
254+
{
255+
if (Py_IgnoreEnvironmentFlag) {
256+
return NULL;
257+
}
258+
return getenv(name);
259+
}
252260

253261
/* --- PyStatus ----------------------------------------------- */
254262

0 commit comments

Comments
 (0)