diff options
author | HASUMI Hitoshi <[email protected]> | 2024-01-22 15:17:40 +0900 |
---|---|---|
committer | git <[email protected]> | 2024-02-20 14:21:16 +0000 |
commit | 15b53e901c15225bdb2d67abb6f2aabf2e93cc4e (patch) | |
tree | 7b217108323944eeaeb1b1c1e67fa7e1f9ac4bc9 /prism/util/pm_string.c | |
parent | c22cb960cf5333e4789489be16db42dc805395b0 (diff) |
[ruby/prism] Use `_POSIX_MAPPED_FILES` and `_WIN32` to know if memory map interface is available in the target platform
https://github.com/ruby/prism/commit/88e2ff52d4
Diffstat (limited to 'prism/util/pm_string.c')
-rw-r--r-- | prism/util/pm_string.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/prism/util/pm_string.c b/prism/util/pm_string.c index 8f3ef92c9b..4589f1e8c6 100644 --- a/prism/util/pm_string.c +++ b/prism/util/pm_string.c @@ -102,7 +102,7 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) { *string = (pm_string_t) { .type = PM_STRING_MAPPED, .source = source, .length = (size_t) file_size }; return true; -#else +#elif defined(_POSIX_MAPPED_FILES) // Open the file for reading int fd = open(filepath, O_RDONLY); if (fd == -1) { @@ -135,6 +135,11 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) { close(fd); *string = (pm_string_t) { .type = PM_STRING_MAPPED, .source = source, .length = size }; return true; +#else + (void) string; + (void) filepath; + perror("pm_string_mapped_init is not implemented for this platform"); + return false; #endif } @@ -213,11 +218,13 @@ pm_string_free(pm_string_t *string) { if (string->type == PM_STRING_OWNED) { free(memory); +#ifdef PRISM_HAS_MMAP } else if (string->type == PM_STRING_MAPPED && string->length) { #if defined(_WIN32) UnmapViewOfFile(memory); -#else +#elif defined(_POSIX_MAPPED_FILES) munmap(memory, string->length); #endif +#endif /* PRISM_HAS_MMAP */ } } |