]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45434: Convert Py_GETENV() macro to a function (GH-28912)
authorVictor Stinner <vstinner@python.org>
Wed, 13 Oct 2021 01:39:50 +0000 (03:39 +0200)
committerGitHub <noreply@github.com>
Wed, 13 Oct 2021 01:39:50 +0000 (03:39 +0200)
Avoid calling directly getenv() in the header file.

Include/cpython/pydebug.h
Python/initconfig.c

index 78bcb118be46598f866aa62c05e66b87ca81a150..cab799f0b38e0c42f2fb2896c02b05d866b2d50a 100644 (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
 }
index 2e3cde83b2534e1413187ee38bf0764ddd7bd9f7..b91d280906cbefaf102dd3a13d82d072de25c7ba 100644 (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 ----------------------------------------------- */