summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorPablo Galindo <pablogsal@gmail.com>2022-01-14 21:20:56 (GMT)
committerPablo Galindo <pablogsal@gmail.com>2022-01-14 21:20:56 (GMT)
commit2402f1e1f80499a870a86d848e5228d527d9be1d (patch)
tree3c9a8c5f87659b1610c880a0cbb93872f6f7b856 /Modules
parent01d4fe09763a6e55e38d338bf45e8c35e32a3581 (diff)
parentc5640ef87511c960e339af37b486678788be910a (diff)
downloadcpython-2402f1e1f80499a870a86d848e5228d527d9be1d.zip
cpython-2402f1e1f80499a870a86d848e5228d527d9be1d.tar.gz
cpython-2402f1e1f80499a870a86d848e5228d527d9be1d.tar.bz2
Merge remote-tracking branch 'upstream/main'
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_hashopenssl.c2
-rw-r--r--Modules/_tracemalloc.c3
-rw-r--r--Modules/gcmodule.c26
-rw-r--r--Modules/getpath.c6
-rw-r--r--Modules/posixmodule.c45
5 files changed, 61 insertions, 21 deletions
diff --git a/Modules/_hashopenssl.c b/Modules/_hashopenssl.c
index eeea61a..fb155b2 100644
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -883,7 +883,7 @@ py_evp_fromname(PyObject *module, const char *digestname, PyObject *data_obj,
goto exit;
}
-#if defined(EVP_MD_CTX_FLAG_NON_FIPS_ALLOW) && OPENSSL_VERSION_NUMBER >= 0x30000000L
+#if defined(EVP_MD_CTX_FLAG_NON_FIPS_ALLOW) && OPENSSL_VERSION_NUMBER < 0x30000000L
// In OpenSSL 1.1.1 the non FIPS allowed flag is context specific while
// in 3.0.0 it is a different EVP_MD provider.
if (!usedforsecurity) {
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index b838439..14bad00 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -1242,6 +1242,9 @@ tracemalloc_copy_domain(_Py_hashtable_t *domains,
_Py_hashtable_t *traces = (_Py_hashtable_t *)value;
_Py_hashtable_t *traces2 = tracemalloc_copy_traces(traces);
+ if (traces2 == NULL) {
+ return -1;
+ }
if (_Py_hashtable_set(domains2, TO_PTR(domain), traces2) < 0) {
_Py_hashtable_destroy(traces2);
return -1;
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index e22f031..16f8c2b 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -139,24 +139,20 @@ get_gc_state(void)
void
_PyGC_InitState(GCState *gcstate)
{
- gcstate->enabled = 1; /* automatic collection enabled? */
-
-#define _GEN_HEAD(n) GEN_HEAD(gcstate, n)
- struct gc_generation generations[NUM_GENERATIONS] = {
- /* PyGC_Head, threshold, count */
- {{(uintptr_t)_GEN_HEAD(0), (uintptr_t)_GEN_HEAD(0)}, 700, 0},
- {{(uintptr_t)_GEN_HEAD(1), (uintptr_t)_GEN_HEAD(1)}, 10, 0},
- {{(uintptr_t)_GEN_HEAD(2), (uintptr_t)_GEN_HEAD(2)}, 10, 0},
- };
+#define INIT_HEAD(GEN) \
+ do { \
+ GEN.head._gc_next = (uintptr_t)&GEN.head; \
+ GEN.head._gc_prev = (uintptr_t)&GEN.head; \
+ } while (0)
+
for (int i = 0; i < NUM_GENERATIONS; i++) {
- gcstate->generations[i] = generations[i];
+ assert(gcstate->generations[i].count == 0);
+ INIT_HEAD(gcstate->generations[i]);
};
gcstate->generation0 = GEN_HEAD(gcstate, 0);
- struct gc_generation permanent_generation = {
- {(uintptr_t)&gcstate->permanent_generation.head,
- (uintptr_t)&gcstate->permanent_generation.head}, 0, 0
- };
- gcstate->permanent_generation = permanent_generation;
+ INIT_HEAD(gcstate->permanent_generation);
+
+#undef INIT_HEAD
}
diff --git a/Modules/getpath.c b/Modules/getpath.c
index fdfe929..5c646c9 100644
--- a/Modules/getpath.c
+++ b/Modules/getpath.c
@@ -59,7 +59,7 @@ getpath_abspath(PyObject *Py_UNUSED(self), PyObject *args)
{
PyObject *r = NULL;
PyObject *pathobj;
- const wchar_t *path;
+ wchar_t *path;
if (!PyArg_ParseTuple(args, "U", &pathobj)) {
return NULL;
}
@@ -67,8 +67,8 @@ getpath_abspath(PyObject *Py_UNUSED(self), PyObject *args)
path = PyUnicode_AsWideCharString(pathobj, &len);
if (path) {
wchar_t *abs;
- if (_Py_abspath(path, &abs) == 0 && abs) {
- r = PyUnicode_FromWideChar(_Py_normpath(abs, -1), -1);
+ if (_Py_abspath((const wchar_t *)_Py_normpath(path, -1), &abs) == 0 && abs) {
+ r = PyUnicode_FromWideChar(abs, -1);
PyMem_RawFree((void *)abs);
} else {
PyErr_SetString(PyExc_OSError, "failed to make path absolute");
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 904f8bf..7b5c3ef 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -4240,6 +4240,48 @@ os_listdir_impl(PyObject *module, path_t *path)
}
#ifdef MS_WINDOWS
+int
+_PyOS_getfullpathname(const wchar_t *path, wchar_t **abspath_p)
+{
+ wchar_t woutbuf[MAX_PATH], *woutbufp = woutbuf;
+ DWORD result;
+
+ result = GetFullPathNameW(path,
+ Py_ARRAY_LENGTH(woutbuf), woutbuf,
+ NULL);
+ if (!result) {
+ return -1;
+ }
+
+ if (result >= Py_ARRAY_LENGTH(woutbuf)) {
+ if ((size_t)result <= (size_t)PY_SSIZE_T_MAX / sizeof(wchar_t)) {
+ woutbufp = PyMem_RawMalloc((size_t)result * sizeof(wchar_t));
+ }
+ else {
+ woutbufp = NULL;
+ }
+ if (!woutbufp) {
+ *abspath_p = NULL;
+ return 0;
+ }
+
+ result = GetFullPathNameW(path, result, woutbufp, NULL);
+ if (!result) {
+ PyMem_RawFree(woutbufp);
+ return -1;
+ }
+ }
+
+ if (woutbufp != woutbuf) {
+ *abspath_p = woutbufp;
+ return 0;
+ }
+
+ *abspath_p = _PyMem_RawWcsdup(woutbufp);
+ return 0;
+}
+
+
/* A helper function for abspath on win32 */
/*[clinic input]
os._getfullpathname
@@ -4255,8 +4297,7 @@ os__getfullpathname_impl(PyObject *module, path_t *path)
{
wchar_t *abspath;
- /* _Py_abspath() is implemented with GetFullPathNameW() on Windows */
- if (_Py_abspath(path->wide, &abspath) < 0) {
+ if (_PyOS_getfullpathname(path->wide, &abspath) < 0) {
return win32_error_object("GetFullPathNameW", path->object);
}
if (abspath == NULL) {