summaryrefslogtreecommitdiffstats
path: root/Modules/_testinternalcapi.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2021-10-22 23:20:03 (GMT)
committerGitHub <noreply@github.com>2021-10-22 23:20:03 (GMT)
commit17c61045c51512add61a9e75e9c7343cf4e4fb82 (patch)
tree59a98afdea508cacfb4dc4f10acf2f5b402ea0b2 /Modules/_testinternalcapi.c
parentf30ad65dbf3c6b1b5eec14dc954d65ef32327857 (diff)
downloadcpython-17c61045c51512add61a9e75e9c7343cf4e4fb82.zip
cpython-17c61045c51512add61a9e75e9c7343cf4e4fb82.tar.gz
cpython-17c61045c51512add61a9e75e9c7343cf4e4fb82.tar.bz2
bpo-45506: Normalize _PyPathConfig.stdlib_dir when calculated. (#29040)
The recently added PyConfig.stdlib_dir was being set with ".." entries. When __file__ was added for from modules this caused a problem on out-of-tree builds. This PR fixes that by normalizing "stdlib_dir" when it is calculated in getpath.c. https://bugs.python.org/issue45506
Diffstat (limited to 'Modules/_testinternalcapi.c')
-rw-r--r--Modules/_testinternalcapi.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/Modules/_testinternalcapi.c b/Modules/_testinternalcapi.c
index 1ca0606..1f205b8 100644
--- a/Modules/_testinternalcapi.c
+++ b/Modules/_testinternalcapi.c
@@ -14,12 +14,14 @@
#include "Python.h"
#include "pycore_atomic_funcs.h" // _Py_atomic_int_get()
#include "pycore_bitutils.h" // _Py_bswap32()
+#include "pycore_fileutils.h" // _Py_normalize_path
#include "pycore_gc.h" // PyGC_Head
#include "pycore_hashtable.h" // _Py_hashtable_new()
#include "pycore_initconfig.h" // _Py_GetConfigsAsDict()
#include "pycore_interp.h" // _PyInterpreterState_GetConfigCopy()
#include "pycore_pyerrors.h" // _Py_UTF8_Edit_Cost()
#include "pycore_pystate.h" // _PyThreadState_GET()
+#include "osdefs.h" // MAXPATHLEN
static PyObject *
@@ -366,6 +368,27 @@ test_edit_cost(PyObject *self, PyObject *Py_UNUSED(args))
}
+static PyObject *
+normalize_path(PyObject *self, PyObject *filename)
+{
+ Py_ssize_t size = -1;
+ wchar_t *encoded = PyUnicode_AsWideCharString(filename, &size);
+ if (encoded == NULL) {
+ return NULL;
+ }
+
+ wchar_t buf[MAXPATHLEN + 1];
+ int res = _Py_normalize_path(encoded, buf, Py_ARRAY_LENGTH(buf));
+ PyMem_Free(encoded);
+ if (res != 0) {
+ PyErr_SetString(PyExc_ValueError, "string too long");
+ return NULL;
+ }
+
+ return PyUnicode_FromWideChar(buf, -1);
+}
+
+
static PyMethodDef TestMethods[] = {
{"get_configs", get_configs, METH_NOARGS},
{"get_recursion_depth", get_recursion_depth, METH_NOARGS},
@@ -377,6 +400,7 @@ static PyMethodDef TestMethods[] = {
{"set_config", test_set_config, METH_O},
{"test_atomic_funcs", test_atomic_funcs, METH_NOARGS},
{"test_edit_cost", test_edit_cost, METH_NOARGS},
+ {"normalize_path", normalize_path, METH_O, NULL},
{NULL, NULL} /* sentinel */
};