[llvm] [libc] Refactor scanf reader to match printf (PR #66023)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 12:44:21 PDT 2023


================
@@ -9,44 +9,61 @@
 #ifndef LLVM_LIBC_SRC_STDIO_SCANF_CORE_READER_H
 #define LLVM_LIBC_SRC_STDIO_SCANF_CORE_READER_H
 
-#include "src/stdio/scanf_core/file_reader.h"
-#include "src/stdio/scanf_core/string_reader.h"
+#include "src/__support/macros/attributes.h" // For LIBC_INLINE
 #include <stddef.h>
 
 namespace __llvm_libc {
 namespace scanf_core {
 
-enum class ReaderType { String, File };
+using StreamGetc = int (*)(void *);
+using StreamUngetc = void (*)(int, void *);
----------------
michaelrj-google wrote:

The reader isn't templated because it's passed to every converter. Templating the reader would mean having two copies of the conversion code in the resulting binary. This is why we have function pointers here (and in the printf writer), to give that runtime polymorphism. The string versions of the scanf (and printf) functions never call the function pointers though.

https://github.com/llvm/llvm-project/pull/66023


More information about the llvm-commits mailing list