8000 [3.9] bpo-39943: Fix MSVC warnings in sre extension (GH-20508) by miss-islington · Pull Request #24856 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.9] bpo-39943: Fix MSVC warnings in sre extension (GH-20508) #24856

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

Merged
merged 1 commit into from
Mar 14, 2021
Merged
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
8 changes: 6 additions & 2 deletions Modules/_sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down
5 changes: 4 additions & 1 deletion Modules/sre_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
0