From: Victor Stinner Date: Wed, 13 Oct 2021 01:39:50 +0000 (+0200) Subject: bpo-45434: Convert Py_GETENV() macro to a function (GH-28912) X-Git-Tag: v3.11.0a2~225 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=489176e4285314f9ea87b8bd91fe1d55d9af2c42;p=thirdparty%2FPython%2Fcpython.git bpo-45434: Convert Py_GETENV() macro to a function (GH-28912) Avoid calling directly getenv() in the header file. --- diff --git a/Include/cpython/pydebug.h b/Include/cpython/pydebug.h index 78bcb118be46..cab799f0b38e 100644 --- a/Include/cpython/pydebug.h +++ b/Include/cpython/pydebug.h @@ -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 } diff --git a/Python/initconfig.c b/Python/initconfig.c index 2e3cde83b253..b91d280906cb 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -249,6 +249,14 @@ fail: #undef SET_ITEM_STR } +char* +Py_GETENV(const char *name) +{ + if (Py_IgnoreEnvironmentFlag) { + return NULL; + } + return getenv(name); +} /* --- PyStatus ----------------------------------------------- */