Skip to content

Commit cf8d6ef

Browse files
bpo-39943: Fix MSVC warnings in sre extension (GH-20508)
(cherry picked from commit 06e3a27) Co-authored-by: Ammar Askar <[email protected]>
1 parent e6bf1e1 commit cf8d6ef

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Modules/_sre.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,10 @@ state_init(SRE_STATE* state, PatternObject* pattern, PyObject* string,
454454

455455
return string;
456456
err:
457-
PyMem_Del(state->mark);
457+
/* We add an explicit cast here because MSVC has a bug when
458+
compiling C code where it believes that `const void**` cannot be
459+
safely casted to `void*`, see bpo-39943 for details. */
460+
PyMem_Del((void*) state->mark);
458461
state->mark = NULL;
459462
if (state->buffer.buf)
460463
PyBuffer_Release(&state->buffer);
@@ -468,7 +471,8 @@ state_fini(SRE_STATE* state)
468471
PyBuffer_Release(&state->buffer);
469472
Py_XDECREF(state->string);
470473
data_stack_dealloc(state);
471-
PyMem_Del(state->mark);
474+
/* See above PyMem_Del for why we explicitly cast here. */
475+
PyMem_Del((void*) state->mark);
472476
state->mark = NULL;
473477
}
474478

Modules/sre_lib.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,12 +448,15 @@ do { \
448448
state->data_stack_base += size; \
449449
} while (0)
450450

451+
/* We add an explicit cast to memcpy here because MSVC has a bug when
452+
compiling C code where it believes that `const void**` cannot be
453+
safely casted to `void*`, see bpo-39943 for details. */
451454
#define DATA_STACK_POP(state, data, size, discard) \
452455
do { \
453456
TRACE(("copy data to %p from %" PY_FORMAT_SIZE_T "d " \
454457
"(%" PY_FORMAT_SIZE_T "d)\n", \
455458
data, state->data_stack_base-size, size)); \
456-
memcpy(data, state->data_stack+state->data_stack_base-size, size); \
459+
memcpy((void*) data, state->data_stack+state->data_stack_base-size, size); \
457460
if (discard) \
458461
state->data_stack_base -= size; \
459462
} while (0)

0 commit comments

Comments
 (0)