Skip to content

bpo-23878: Remove the key parameter of _Py_FindEnvConfigValue() #15555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Include/internal/pycore_pathconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ extern int _PyPathConfig_ComputeSysPath0(
PyObject **path0);
extern int _Py_FindEnvConfigValue(
FILE *env_file,
const wchar_t *key,
wchar_t *value,
size_t value_size);

Expand Down
2 changes: 1 addition & 1 deletion Modules/getpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ calculate_read_pyenv(PyCalculatePath *calculate)
}

/* Look for a 'home' variable and set argv0_path to it, if found */
if (_Py_FindEnvConfigValue(env_file, L"home", tmpbuffer, buflen)) {
if (_Py_FindEnvConfigValue(env_file, tmpbuffer, buflen)) {
if (safe_wcscpy(calculate->argv0_path, tmpbuffer,
Py_ARRAY_LENGTH(calculate->argv0_path)) < 0) {
return PATHLEN_ERR();
Expand Down
2 changes: 1 addition & 1 deletion PC/getpathp.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ calculate_pyvenv_file(PyCalculatePath *calculate)

/* Look for a 'home' variable and set argv0_path to it, if found */
wchar_t tmpbuffer[MAXPATHLEN+1];
if (_Py_FindEnvConfigValue(env_file, L"home", tmpbuffer, MAXPATHLEN)) {
if (_Py_FindEnvConfigValue(env_file, tmpbuffer, MAXPATHLEN)) {
wcscpy_s(calculate->argv0_path, MAXPATHLEN+1, tmpbuffer);
}
fclose(env_file);
Expand Down
5 changes: 2 additions & 3 deletions Python/pathconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,7 @@ _PyPathConfig_ComputeSysPath0(const PyWideStringList *argv, PyObject **path0_p)
/* Search for a prefix value in an environment file (pyvenv.cfg).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't search "for a prefix". It searchs for the the line "home=" and return <path>. It tolerates whitespaces around "=".

If found, copy it into the provided buffer. */
int
_Py_FindEnvConfigValue(FILE *env_file, const wchar_t *key,
wchar_t *value, size_t value_size)
_Py_FindEnvConfigValue(FILE *env_file, wchar_t *value, size_t value_size)
{
int result = 0; /* meaning not found */
char buffer[MAXPATHLEN * 2 + 1]; /* allow extra for key, '=', etc. */
Expand Down Expand Up @@ -763,7 +762,7 @@ _Py_FindEnvConfigValue(FILE *env_file, const wchar_t *key,
if (tmpbuffer) {
wchar_t * state;
wchar_t * tok = WCSTOK(tmpbuffer, L" \t\r\n", &state);
if ((tok != NULL) && !wcscmp(tok, key)) {
if ((tok != NULL) && !wcscmp(tok, L"home")) {
tok = WCSTOK(NULL, L" \t", &state);
if ((tok != NULL) && !wcscmp(tok, L"=")) {
tok = WCSTOK(NULL, L"\r\n", &state);
Expand Down