This patch adds the headers for printf. It contains minimal actual code,
and is more intended to be used for design review. The code is not built
yet, and may have minor errors.
Details
- Reviewers
sivachandra lntue - Commits
- rGc4a1b07d0979: [libc][NFC] add outline of printf
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
libc/src/stdio/printf_files/core_structs.h | ||
---|---|---|
35 | Is Float missing or not needed? |
libc/src/stdio/printf_files/core_structs.h | ||
---|---|---|
35 | Float is not needed. %f uses double and %Lf uses long double, but there's no float option. |
libc/src/stdio/printf_files/core_structs.h | ||
---|---|---|
49 | Type names should be of the form TypeName. | |
libc/src/stdio/printf_files/parser.h | ||
19 | Do we really need an internal namespace here? You normally introduce an internal namespace to indicate that the interface declared in such a namespace is not to be used by clients of the higher level namespace. If we do need something internal, ISTM that the nesting should be reversed? As in, internal should be nested inside printf_core? | |
libc/src/stdio/printf_files/writer.h | ||
21 | Is this class envisioned to be a final class? If yes, then we should have documentation of the expectations. For example, what is output, raw_write etc. If not also, we should add documentation about how it is to be specialized. | |
34 | Why is size required at all? |
libc/src/stdio/printf_files/parser.h | ||
---|---|---|
19 | I've removed the internal namespace and moved everything to printf_core. | |
libc/src/stdio/printf_files/writer.h | ||
21 | I was under the impression that virtual functions were disallowed in libc, so all classes were implicitly final. I've added comments with more explanation on how this specialization works. | |
34 | the number of chars written is the return value for printf, as well as the value written by %n. |
LGTM but we might tweak as we go.
libc/src/stdio/printf_files/writer.h | ||
---|---|---|
21 | Couple of things:
| |
29 | What is max_length? | |
38 | These functions should be implemented inline to avoid multiple indirections? |
make Writer a final class.
libc/src/stdio/printf_files/writer.h | ||
---|---|---|
21 | I've marked it as final for clarity. | |
29 | for snprintf there is a limit on the maximum number of characters that can be written. This represents that maximum length. In other cases it will be set to a default (probably size_t maximum). | |
38 | Could you clarify what you mean by implementing this inline? This function won't just be calling the raw_write function. If length + chars_written > max_length then the length passed to raw_write will be max_length - chars_written, so that this doesn't overrun the buffer. |
libc/src/stdio/printf_files/writer.h | ||
---|---|---|
38 | This class is essentially a convenience wrapper to call raw_write, albeit with some logic before and after potentially. What I mean is that, if make these functions inline, then we avoid unnecessary function call indirections. You don't have to implement them in this patch of course. |
Is Float missing or not needed?