This is an archive of the discontinued LLVM Phabricator instance.

[libc] add scanf float converter
ClosedPublic

Authored by michaelrj on Jan 5 2023, 2:42 PM.

Details

Summary

This patch adds the %f/F/e/E/g/G/a/A conversions for scanf, as well as
accompanying tests. This implementation matches the definition set forth
in the standard, which may conflict with some other implementations.

Diff Detail

Event Timeline

michaelrj created this revision.Jan 5 2023, 2:42 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJan 5 2023, 2:42 PM
michaelrj requested review of this revision.Jan 5 2023, 2:42 PM
sivachandra added inline comments.Jan 6 2023, 1:16 AM
libc/src/stdio/scanf_core/float_converter.cpp
26

Isn't this an equivalent of std::string? If yes, may be you should move it to CPP and name it cpp::string.

37

This should be delete [] str?

But, I also think this is a case where realloc is the right allocator function to use instead of new/delete.

michaelrj updated this revision to Diff 486997.Jan 6 2023, 3:05 PM
michaelrj marked an inline comment as done.

split VectorString class into a separate patch (and file)

libc/src/stdio/scanf_core/float_converter.cpp
26

I've separated adding the string class into a separate patch, but I'll talk more about my thought process here:

I've kept the name VectorString for a couple reasons, the first being to make it clear that this can allocate. Next, due to it allocating it needs a way to report an error state in case allocation fails. The std::string class throws an exception when this happens, but we're not using exceptions so it has to be communicated in a different way. The way I have it currently is that when the append function is called to returns a boolean that represents if it has succeeded (as opposed to returning *this to allow for chained calls). This is a small but meaningful difference in API that I think is necessary but might confuse users if we used the existing name.

michaelrj updated this revision to Diff 490311.Jan 18 2023, 3:04 PM

rebase onto new string class name

sivachandra accepted this revision.Jan 19 2023, 12:14 AM
This revision is now accepted and ready to land.Jan 19 2023, 12:14 AM
This revision was landed with ongoing or failed builds.Jan 19 2023, 9:26 AM
This revision was automatically updated to reflect the committed changes.