aboutsummaryrefslogtreecommitdiffstats
path: root/iseq.c
diff options
context:
space:
mode:
authorMatt Valentine-House <matt@eightbitraptor.com>2024-01-22 22:28:51 +0000
committerAaron Patterson <aaron.patterson@gmail.com>2024-01-22 15:15:32 -0800
commitd054904cad7f0889f545d47bc637829a510c1d4b (patch)
tree525d9c233f6a09cdcfb702c641816295cddc7e05 /iseq.c
parent4592fdc545284a0cbf55bd1ada17d0b98a3ae685 (diff)
downloadruby-d054904cad7f0889f545d47bc637829a510c1d4b.tar.gz
[Prism] Don't change file after setting it.
This causes the Iseq file names to be wrong, which is affecting Tracepoint events in certain cases. because we're taking a pointer to the string and using it in `pm_string_mapped_pointer` we also need to `RB_GC_GUARD` the relevant Ruby object to ensure it's not moved or swept before the parser has been free'd.
Diffstat (limited to 'iseq.c')
-rw-r--r--iseq.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/iseq.c b/iseq.c
index 706629d52b..babc7948de 100644
--- a/iseq.c
+++ b/iseq.c
@@ -1475,12 +1475,12 @@ iseqw_s_compile_prism(int argc, VALUE *argv, VALUE self)
pm_parser_t parser;
+ VALUE file_path = Qnil;
pm_string_t input;
if (RB_TYPE_P(src, T_FILE)) {
- FilePathValue(src);
- file = rb_fstring(src); /* rb_io_t->pathv gets frozen anyways */
+ file_path = rb_io_path(src); /* rb_io_t->pathv gets frozen anyways */
- pm_string_mapped_init(&input, RSTRING_PTR(file));
+ pm_string_mapped_init(&input, RSTRING_PTR(file_path));
}
else {
Check_Type(src, T_STRING);
@@ -1493,6 +1493,7 @@ iseqw_s_compile_prism(int argc, VALUE *argv, VALUE self)
rb_iseq_t *iseq = iseq_alloc();
iseqw_s_compile_prism_compile(&parser, opt, iseq, file, path, start_line);
+ RB_GC_GUARD(file_path);
pm_parser_free(&parser);
pm_options_free(&options);
pm_string_free(&input);