Skip to content

bpo-39943: Fix MSVC warnings in sre extension #20508

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
Jun 1, 2020

Conversation

ammaraskar
Copy link
Member

@ammaraskar ammaraskar commented May 29, 2020

While the PyMem_Del change seems harmless enough, I'm a little bit uneasy about the memcpy one. This file is pretty old and unlikely to change in the future but it seems like it opens up the possibility of someone making a mistake like DATA_STACK_POP(state, 5, ...) and have it not caught by the type checker because of the explicit cast.

For that particular one we could guard the explicitly casted version with #ifdef _MSC_VER or something so it's harder to make that mistake and not have it be caught by the CI.

https://bugs.python.org/issue39943

@ammaraskar
Copy link
Member Author

@petdance Your review here would be appreciated as well.

@@ -453,7 +453,10 @@ 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); \
/* We add an explicit cast to memcpy here because MSVC has a bug when
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that it's ok to put a comment into a #define macro. Maybe convert the macro to a static inline function, or put the comment outside (before) the #define.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, this works but it might lead to weird situations like

/*
  some_commented_out_code();
  MACRO;
*/

and then the comment suddenly gets stopped in the middle due to macro expansion.

@ammaraskar ammaraskar force-pushed the sre_msvc_warnings branch from e021e49 to 0f5ec74 Compare May 29, 2020 18:27
@ammaraskar ammaraskar force-pushed the sre_msvc_warnings branch from 0f5ec74 to e9d75be Compare May 29, 2020 18:28
@petdance
Copy link
Contributor

Looks fine to me. Good catch on the comments-in-a-macro.

@vstinner
Copy link
Member

vstinner commented Jun 1, 2020

I checked Windows x64 job and I confirm that this PR fix all compiler warnings in sre files.

@miss-islington
Copy link
Contributor

Thanks @ammaraskar for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-24856 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Mar 14, 2021
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 14, 2021
(cherry picked from commit 06e3a27)

Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
@serhiy-storchaka
Copy link
Member

It needs to be backpoted to 3.9.

miss-islington added a commit that referenced this pull request Mar 14, 2021
(cherry picked from commit 06e3a27)

Co-authored-by: Ammar Askar <ammar@ammaraskar.com>
@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Mar 16, 2021

See also bpo-43499.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants