From a65c205a1bce121821472c8e7658247a47e89047 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sat, 20 Jul 2024 02:59:39 +0000 Subject: [PATCH] [ruby/prism] Add explicit check for PRISM_HAS_NO_FILESYSTEM https://github.com/ruby/prism/commit/89c22f0e6c --- prism/defines.h | 9 +++++++++ prism/util/pm_string.c | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/prism/defines.h b/prism/defines.h index 849ca6d051..a4246e67c8 100644 --- a/prism/defines.h +++ b/prism/defines.h @@ -118,6 +118,15 @@ # endif #endif +/** + * If PRISM_HAS_NO_FILESYSTEM is defined, then we want to exclude all filesystem + * related code from the library. All filesystem related code should be guarded + * by PRISM_HAS_FILESYSTEM. + */ +#ifndef PRISM_HAS_NO_FILESYSTEM +# define PRISM_HAS_FILESYSTEM +#endif + /** * isinf on Windows is defined as accepting a float, but on POSIX systems it * accepts a float, a double, or a long double. We want to mirror this behavior diff --git a/prism/util/pm_string.c b/prism/util/pm_string.c index 6545bce319..0a67accd86 100644 --- a/prism/util/pm_string.c +++ b/prism/util/pm_string.c @@ -202,7 +202,7 @@ pm_string_file_init(pm_string_t *string, const char *filepath) { CloseHandle(file); *string = (pm_string_t) { .type = PM_STRING_OWNED, .source = source, .length = (size_t) file_size }; return true; -#else +#elif defined(PRISM_HAS_FILESYSTEM) FILE *file = fopen(filepath, "rb"); if (file == NULL) { return false; @@ -241,6 +241,11 @@ pm_string_file_init(pm_string_t *string, const char *filepath) { *string = (pm_string_t) { .type = PM_STRING_OWNED, .source = source, .length = length }; return true; +#else + (void) string; + (void) filepath; + perror("pm_string_file_init is not implemented for this platform"); + return false; #endif }