]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39943: Fix MSVC warnings in sre extension (GH-20508)
authorAmmar Askar <ammar@ammaraskar.com>
Mon, 1 Jun 2020 17:21:43 +0000 (17:21 +0000)
committerGitHub <noreply@github.com>
Mon, 1 Jun 2020 17:21:43 +0000 (19:21 +0200)
Modules/_sre.c
Modules/sre_lib.h

index 244e4f1f84dfff9e7b49778ac3fdfcb60a107c01..bdc427822d7e10a6e65a154633c5d7f152104d21 100644 (file)
@@ -454,7 +454,10 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string,
 
     return string;
   err:
-    PyMem_Del(state->mark);
+    /* We add an explicit cast here because MSVC has a bug when
+       compiling C code where it believes that `const void**` cannot be
+       safely casted to `void*`, see bpo-39943 for details. */
+    PyMem_Del((void*) state->mark);
     state->mark = NULL;
     if (state->buffer.buf)
         PyBuffer_Release(&state->buffer);
@@ -468,7 +471,8 @@ state_fini(SRE_STATE* state)
         PyBuffer_Release(&state->buffer);
     Py_XDECREF(state->string);
     data_stack_dealloc(state);
-    PyMem_Del(state->mark);
+    /* See above PyMem_Del for why we explicitly cast here. */
+    PyMem_Del((void*) state->mark);
     state->mark = NULL;
 }
 
index 9cc786321c560a7c8cca22f22855ad8cd030fd8c..2657d8d82c6f1cbc16990a67ebb36f1e37b67c4c 100644 (file)
@@ -448,12 +448,15 @@ do { \
     state->data_stack_base += size; \
 } while (0)
 
+/* We add an explicit cast to memcpy here because MSVC has a bug when
+   compiling C code where it believes that `const void**` cannot be
+   safely casted to `void*`, see bpo-39943 for details. */
 #define DATA_STACK_POP(state, data, size, discard) \
 do { \
     TRACE(("copy data to %p from %" PY_FORMAT_SIZE_T "d " \
            "(%" PY_FORMAT_SIZE_T "d)\n", \
            data, state->data_stack_base-size, size)); \
-    memcpy(data, state->data_stack+state->data_stack_base-size, size); \
+    memcpy((void*) data, state->data_stack+state->data_stack_base-size, size); \
     if (discard) \
         state->data_stack_base -= size; \
 } while (0)