Skip to content

gh-112301: Use literal format strings in unicode_fromformat_arg #124203

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 3 commits into from
Sep 25, 2024

Conversation

encukou
Copy link
Member

@encukou encukou commented Sep 18, 2024

This switches sprintf format strings in unicode_fromformat_arg to compile-time literals, avoiding -Wformat-nonliteral warnings and maybe even allowing optimizing the sprintf calls.

The macros aren't too readable so I'm generous with comments.

(Another option would be code generation, see the first commit.)

@rruuaanng
Copy link
Contributor

Maybe you should add NEWS.

@vstinner
Copy link
Member

Maybe you should add NEWS.

This change doesn't impact end users. I don't think that a NEWS entry is needed.

sprintf(buffer, fmt, va_arg(*vargs, int)) :
sprintf(buffer, fmt, va_arg(*vargs, unsigned int));
break;
case F_LONG: DO_SPRINTS("l", long, unsigned long)
Copy link
Member

Choose a reason for hiding this comment

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

Can you put the break here? Something like:

Suggested change
case F_LONG: DO_SPRINTS("l", long, unsigned long)
case F_LONG: DO_SPRINTS("l", long, unsigned long); break;

Copy link
Member Author

Choose a reason for hiding this comment

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

OK!
One line is 85 characters now, but I think it's most readable this way.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@encukou encukou merged commit da5855e into python:main Sep 25, 2024
37 checks passed
@encukou encukou deleted the sizemod branch September 25, 2024 17:46
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.

3 participants