diff -r 618ea5612e83 Doc/c-api/sys.rst --- a/Doc/c-api/sys.rst Tue Nov 27 23:06:19 2012 +0200 +++ b/Doc/c-api/sys.rst Wed Nov 28 17:10:34 2012 +1100 @@ -32,6 +32,15 @@ own code. +.. c:function:: int PyOS_PutEnv(const char *string) + + Python's own version of :c:func:`putenv` to overcome the limitation that + an embedded interpreter can't have it's environment variables set + by the application embedding it when Python is loaded as a dynamic library. + *string* is the environment variable to set, taking the form ``NAME=VALUE``. + Returns ``0`` on success, ``-1`` on error. + + .. c:function:: PyOS_sighandler_t PyOS_getsig(int i) Return the current signal handler for signal *i*. This is a thin wrapper around diff -r 618ea5612e83 Include/pythonrun.h --- a/Include/pythonrun.h Tue Nov 27 23:06:19 2012 +0200 +++ b/Include/pythonrun.h Wed Nov 28 17:10:34 2012 +1100 @@ -227,6 +227,8 @@ #ifndef Py_LIMITED_API PyAPI_FUNC(char *) PyOS_Readline(FILE *, FILE *, char *); #endif +PyAPI_FUNC(int) PyOS_PutEnv(char *); + PyAPI_DATA(int) (*PyOS_InputHook)(void); PyAPI_DATA(char) *(*PyOS_ReadlineFunctionPointer)(FILE *, FILE *, char *); #ifndef Py_LIMITED_API diff -r 618ea5612e83 Python/pythonrun.c --- a/Python/pythonrun.c Tue Nov 27 23:06:19 2012 +0200 +++ b/Python/pythonrun.c Wed Nov 28 17:10:34 2012 +1100 @@ -2607,6 +2607,19 @@ #endif } +/* + * Use our own setenv() because embedded applications may need to set + * the environment. (see issue #16129). + */ +int PyOS_PutEnv(char *string) +{ +#ifdef MS_WINDOWS + return _putenv(string); +#else + return putenv(string); +#endif +} + /* Deprecated C API functions still provided for binary compatiblity */ #undef PyParser_SimpleParseFile