[ruby/prism] Parse tempfile

https://github.com/ruby/prism/commit/31154a389a
This commit is contained in:
Kevin Newton 2024-09-11 10:42:08 -04:00 committed by git
parent 7facf23232
commit 886fc69b1c
2 changed files with 10 additions and 2 deletions

View File

@ -62,7 +62,7 @@ PRISM_EXPORTED_FUNCTION bool
pm_string_mapped_init(pm_string_t *string, const char *filepath) { pm_string_mapped_init(pm_string_t *string, const char *filepath) {
#ifdef _WIN32 #ifdef _WIN32
// Open the file for reading. // 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) { if (file == INVALID_HANDLE_VALUE) {
return false; return false;
@ -156,7 +156,7 @@ PRISM_EXPORTED_FUNCTION bool
pm_string_file_init(pm_string_t *string, const char *filepath) { pm_string_file_init(pm_string_t *string, const char *filepath) {
#ifdef _WIN32 #ifdef _WIN32
// Open the file for reading. // 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) { if (file == INVALID_HANDLE_VALUE) {
return false; return false;

View File

@ -61,6 +61,14 @@ module Prism
end end
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 private
def find_source_file_node(program) def find_source_file_node(program)