bpo-45434: Convert Py_GETENV() macro to a function (GH-28912)

Avoid calling directly getenv() in the header file.
This commit is contained in:
Victor Stinner 2021-10-13 03:39:50 +02:00 committed by GitHub
parent 9c4766772c
commit 489176e428
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -29,7 +29,7 @@ PyAPI_DATA(int) Py_LegacyWindowsStdioFlag;
/* this is a wrapper around getenv() that pays attention to
Py_IgnoreEnvironmentFlag. It should be used for getting variables like
PYTHONPATH and PYTHONHOME from the environment */
#define Py_GETENV(s) (Py_IgnoreEnvironmentFlag ? NULL : getenv(s))
PyAPI_DATA(char*) Py_GETENV(const char *name);
#ifdef __cplusplus
}

View File

@ -249,6 +249,14 @@ fail:
#undef SET_ITEM_STR
}
char*
Py_GETENV(const char *name)
{
if (Py_IgnoreEnvironmentFlag) {
return NULL;
}
return getenv(name);
}
/* --- PyStatus ----------------------------------------------- */