This is an archive of the discontinued LLVM Phabricator instance.

[libc] add scanf current position conversion
ClosedPublic

Authored by michaelrj on Jan 24 2023, 11:31 AM.

Details

Summary

To add the current position (%n) conversion, some reorganization needed
to be done. The "write a number to this pointer using the length
modifier" utilities and a couple other shared parsing functions have
been moved into converter_utils.h. This made implementing
current_pos_converter very simple.

Diff Detail

Event Timeline

michaelrj created this revision.Jan 24 2023, 11:31 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 24 2023, 11:31 AM
michaelrj requested review of this revision.Jan 24 2023, 11:31 AM
lntue accepted this revision.Jan 25 2023, 6:57 AM
lntue added inline comments.
libc/src/stdio/scanf_core/converter_utils.h
24–34

For consistency, can you keep LIBC_INLINE before return types in the definitions.

libc/src/stdio/scanf_core/current_pos_converter.cpp
19 ↗(On Diff #491862)

This function is quite short. Will it get more complicated later? Otherwise you can inline it in the header instead.

This revision is now accepted and ready to land.Jan 25 2023, 6:57 AM
sivachandra added inline comments.Jan 25 2023, 8:48 AM
libc/src/stdio/scanf_core/converter_utils.h
24–34

Not just consistency, it is a requirement as we want to be able to add attributes. I will update the documentation with this information. It should be listed before constexpr also.

michaelrj marked 3 inline comments as done.

move inline annotations in function headers
remove current_pos_converter.cpp

libc/src/stdio/scanf_core/current_pos_converter.cpp
19 ↗(On Diff #491862)

I moved it to the header and also tagged it as LIBC_INLINE.

This revision was automatically updated to reflect the committed changes.