Skip to content
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

bpo-45666: Use %S for MSVC and %s elsewhere for swprintf in _testembed.c #29341

Merged
merged 4 commits into from Nov 1, 2021

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Oct 31, 2021

@sobolevn
Copy link
Member Author

@serhiy-storchaka serhiy-storchaka changed the title Change %S -> %ls in swprintf in _testembed.c bpo-45666: Change %S -> %ls in swprintf in _testembed.c Oct 31, 2021
Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

%ls is not applicable here.

One possible solutions is to use %S on Windows and %s on Linux (it should be tested). Or maybe there is a portable way.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

Following Serhiy's suggestion, maybe this is better:

Programs/_testembed.c Outdated Show resolved Hide resolved
@serhiy-storchaka
Copy link
Member

You can also use Py_DecodeLocale() as in other tests.

const char *envvar = getenv("TESTFROZEN");
return check_use_frozen_modules(envvar);
wchar_t *frozen = Py_DecodeLocale(envvar, NULL);
Copy link
Member

Choose a reason for hiding this comment

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

If you are going to use Py_DecodeLocale(), you need to check its result for failure, and free the dynamic allocated memory after use. You should also add a special case for getenv() returning NULL.

@Fidget-Spinner's suggestion is much simpler.

sobolevn and others added 2 commits October 31, 2021 16:28
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
@sobolevn
Copy link
Member Author

Thank you @serhiy-storchaka and @Fidget-Spinner for your help! I am coming from Rust background and C is very hard for me! (no borrow checker 😬, you have to remember to deallocate memory!)

But, I will do my best to get used to it 🙂

@Fidget-Spinner Fidget-Spinner changed the title bpo-45666: Change %S -> %ls in swprintf in _testembed.c bpo-45666: Use %S for MSVC and %s elsewhere for swprintf in _testembed.c Nov 1, 2021
@Fidget-Spinner Fidget-Spinner merged commit 401d25e into python:main Nov 1, 2021
@Fidget-Spinner
Copy link
Member

@sobolevn glad to help. Your comment also reminded me I should seriously try out Rust one day :). I still suck at it.

@sobolevn
Copy link
Member Author

sobolevn commented Nov 1, 2021

@Fidget-Spinner you can take a look at RustPython project: https://github.com/RustPython/RustPython
I really like it! This was a project that motivated me to contribute to CPython.

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.

None yet

5 participants