[libc-commits] [libc] [libc] Template the writing mode for the writer class (PR #111559)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Wed Feb 19 10:23:33 PST 2025
https://github.com/michaelrj-google commented:
>From the most recent libc meeting I've been convinced that this patch is useful and we should move forward with it.
That being said there are some changes that to make before it lands:
1) Rebase and update the `strftime` internals, since those use the printf writer.
2) Create a template of `Writer` and `WriteBuffer` that does runtime dispatch based on an enum.
3) Create a compile flag that switches `printf_main` to take a specific templated writer and create a runtime dispatch version of it. A rough outline of what I'm thinking below:
```
#ifdef PRINTF_MAIN_RUNTIME_DISPATCH //name TBD
template <WriteMode write_mode>
int printf_main(Writer<write_mode> *writer, const char *__restrict str,
internal::ArgList &args) {
WriteBuffer<RUNTIME_DISPATCH> generic_wb(writer->wb.buff, ..., write_mode); //TODO: handle the fprintf overflow_write at the end
Writer<RUNTIME_DISPATCH> generic_writer(generic_wb);
Parser<internal::ArgList> parser(str, args);
int result = 0;
for (FormatSection cur_section = parser.get_next_section();
!cur_section.raw_string.empty();
cur_section = parser.get_next_section()) {
if (cur_section.has_conv)
result = convert(generic_writer, cur_section);
else
result = generic_writer->write(cur_section.raw_string);
if (result < 0)
return result;
}
return generic_writer->get_chars_written();
}
```
What do you think of this as a plan to move forward?
https://github.com/llvm/llvm-project/pull/111559
More information about the libc-commits
mailing list