summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Newton <kddnewton@gmail.com>2025-10-10 15:06:45 -0400
committerKevin Newton <kddnewton@gmail.com>2025-10-11 15:08:07 -0400
commitd036dc0a794d87309f912e7585749c681c2438f5 (patch)
tree8cd08a8787b12234a522b45b748b6201d1087173
parent10c0d7a839ef920ae77fbbb38d081795ecec9057 (diff)
For prism parser, do not update $_ from STDIN
Fixes [Bug #21635]
-rw-r--r--io.c10
-rw-r--r--prism_compile.c4
2 files changed, 11 insertions, 3 deletions
diff --git a/io.c b/io.c
index caa364a70b..d412d14963 100644
--- a/io.c
+++ b/io.c
@@ -4307,11 +4307,17 @@ rb_io_gets(VALUE io)
}
VALUE
-rb_io_gets_internal(VALUE io)
+rb_io_gets_limit_internal(VALUE io, long limit)
{
rb_io_t *fptr;
GetOpenFile(io, fptr);
- return rb_io_getline_0(rb_default_rs, -1, FALSE, fptr);
+ return rb_io_getline_0(rb_default_rs, limit, FALSE, fptr);
+}
+
+VALUE
+rb_io_gets_internal(VALUE io)
+{
+ return rb_io_gets_limit_internal(io, -1);
}
/*
diff --git a/prism_compile.c b/prism_compile.c
index 66bee579c9..86753c90cc 100644
--- a/prism_compile.c
+++ b/prism_compile.c
@@ -11466,6 +11466,8 @@ pm_parse_stdin_eof(void *stream)
return wrapped_stdin->eof_seen;
}
+VALUE rb_io_gets_limit_internal(VALUE io, long limit);
+
/**
* An implementation of fgets that is suitable for use with Ruby IO objects.
*/
@@ -11476,7 +11478,7 @@ pm_parse_stdin_fgets(char *string, int size, void *stream)
struct rb_stdin_wrapper * wrapped_stdin = (struct rb_stdin_wrapper *)stream;
- VALUE line = rb_funcall(wrapped_stdin->rb_stdin, rb_intern("gets"), 1, INT2FIX(size - 1));
+ VALUE line = rb_io_gets_limit_internal(wrapped_stdin->rb_stdin, size - 1);
if (NIL_P(line)) {
return NULL;
}