Skip to content

Commit 7caa659

Browse files
authored
Merge pull request ruby#3892 from eregon/ensure-RUBY_VERSION-does-not-move
RB_GC_GUARD() the VALUE for RSTRING_PTR() to ensure the char* does not move
2 parents 8fff847 + e30e259 commit 7caa659

2 files changed

Lines changed: 1 addition & 2 deletions

File tree

ext/prism/extension.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,10 @@ build_options_i(VALUE key, VALUE value, VALUE argument) {
201201
const char *version = check_string(value);
202202

203203
if (RSTRING_LEN(value) == 7 && strncmp(version, "current", 7) == 0) {
204-
const char *ruby_version = RSTRING_PTR(rb_const_get(rb_cObject, rb_intern("RUBY_VERSION")));
205204
if (!pm_options_version_set(options, ruby_version, 3)) {
206205
rb_exc_raise(rb_exc_new_cstr(rb_cPrismCurrentVersionError, ruby_version));
207206
}
208207
} else if (RSTRING_LEN(value) == 7 && strncmp(version, "nearest", 7) == 0) {
209-
const char *ruby_version = RSTRING_PTR(rb_const_get(rb_cObject, rb_intern("RUBY_VERSION")));
210208
const char *nearest_version;
211209

212210
if (ruby_version[0] < '3' || (ruby_version[0] == '3' && ruby_version[2] < '3')) {

ext/prism/extension.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <ruby.h>
77
#include <ruby/encoding.h>
8+
#include <ruby/version.h>
89
#include "prism.h"
910

1011
VALUE pm_source_new(const pm_parser_t *parser, rb_encoding *encoding, bool freeze);

0 commit comments

Comments
 (0)