From 886fc69b1cfb20141608eb1f461b93e5a5464cf9 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 11 Sep 2024 10:42:08 -0400 Subject: [PATCH] [ruby/prism] Parse tempfile https://github.com/ruby/prism/commit/31154a389a --- prism/util/pm_string.c | 4 ++-- test/prism/api/parse_test.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/prism/util/pm_string.c b/prism/util/pm_string.c index 0a67accd86..4bd3dd8ef2 100644 --- a/prism/util/pm_string.c +++ b/prism/util/pm_string.c @@ -62,7 +62,7 @@ PRISM_EXPORTED_FUNCTION bool pm_string_mapped_init(pm_string_t *string, const char *filepath) { #ifdef _WIN32 // Open the file for reading. - HANDLE file = CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE file = CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); if (file == INVALID_HANDLE_VALUE) { return false; @@ -156,7 +156,7 @@ PRISM_EXPORTED_FUNCTION bool pm_string_file_init(pm_string_t *string, const char *filepath) { #ifdef _WIN32 // Open the file for reading. - HANDLE file = CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE file = CreateFile(filepath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); if (file == INVALID_HANDLE_VALUE) { return false; diff --git a/test/prism/api/parse_test.rb b/test/prism/api/parse_test.rb index dda0d6959c..2e9722f5da 100644 --- a/test/prism/api/parse_test.rb +++ b/test/prism/api/parse_test.rb @@ -61,6 +61,14 @@ module Prism end end + def test_parse_tempfile + Tempfile.create(["test_parse_tempfile", ".rb"]) do |t| + t.puts ["begin\n", " end\n"] + t.flush + Prism.parse_file(t.path) + end + end + private def find_source_file_node(program)