[libc-commits] [libc] [libc] Add `scanf` support to the GPU build (PR #104812)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Wed Aug 21 14:59:25 PDT 2024
================
@@ -12,17 +12,41 @@
#include "src/__support/File/file.h"
#include "src/__support/arg_list.h"
#include "src/__support/macros/config.h"
+#include "src/__support/macros/properties/architectures.h"
#include "src/stdio/scanf_core/reader.h"
#include "src/stdio/scanf_core/scanf_main.h"
+#if defined(LIBC_TARGET_ARCH_IS_GPU)
+#include "src/stdio/ferror.h"
+#include "src/stdio/getc.h"
+#include "src/stdio/ungetc.h"
+#endif
+
#include "hdr/types/FILE.h"
#include <stddef.h>
namespace LIBC_NAMESPACE_DECL {
namespace internal {
-#ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE
+#if defined(LIBC_TARGET_ARCH_IS_GPU)
+// Since ungetc_unlocked isn't always available, we don't acquire the lock for
+// system files.
+LIBC_INLINE void flockfile(::FILE *) { return; }
+
+LIBC_INLINE void funlockfile(::FILE *) { return; }
+
+LIBC_INLINE int getc(void *f) {
+ return LIBC_NAMESPACE::getc(reinterpret_cast<::FILE *>(f));
----------------
michaelrj-google wrote:
I'm okay with leaving it as just a comment, the thing I want is to make it clear that this is unusual and people shouldn't copy it. I'm willing to let the GPU functions be less independent since there's no existing libc to overlay, but I want to make sure the functions on other targets stay independent.
https://github.com/llvm/llvm-project/pull/104812
More information about the libc-commits
mailing list