Skip to content

Commit 6a4e53f

Browse files
Earlopainmatzbot
authored andcommitted
[ruby/prism] Directly use ruby_version from ruby/version.h
When I initially wrote this, I used `RUBY_VERSION` so it's easier to stub in tests But turns out that doesn't work in CRuby tests ruby/prism@e30e2591de
1 parent ebef4db commit 6a4e53f

2 files changed

Lines changed: 2 additions & 9 deletions

File tree

prism/extension.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +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-
VALUE ruby_version_string = rb_const_get(rb_cObject, rb_intern("RUBY_VERSION"));
205-
const char *ruby_version = RSTRING_PTR(ruby_version_string);
206204
if (!pm_options_version_set(options, ruby_version, 3)) {
207-
rb_exc_raise(rb_exc_new_str(rb_cPrismCurrentVersionError, ruby_version_string));
205+
rb_exc_raise(rb_exc_new_cstr(rb_cPrismCurrentVersionError, ruby_version));
208206
}
209-
210-
RB_GC_GUARD(ruby_version_string); // Do not move ruby_version while running the code above
211207
} else if (RSTRING_LEN(value) == 7 && strncmp(version, "nearest", 7) == 0) {
212-
VALUE ruby_version_string = rb_const_get(rb_cObject, rb_intern("RUBY_VERSION"));
213-
const char *ruby_version = RSTRING_PTR(ruby_version_string);
214208
const char *nearest_version;
215209

216210
if (ruby_version[0] < '3' || (ruby_version[0] == '3' && ruby_version[2] < '3')) {
@@ -224,8 +218,6 @@ build_options_i(VALUE key, VALUE value, VALUE argument) {
224218
if (!pm_options_version_set(options, nearest_version, 3)) {
225219
rb_raise(rb_eArgError, "invalid nearest version: %s", nearest_version);
226220
}
227-
228-
RB_GC_GUARD(ruby_version_string); // Do not move ruby_version while running the code above
229221
} else if (!pm_options_version_set(options, version, RSTRING_LEN(value))) {
230222
rb_raise(rb_eArgError, "invalid version: %" PRIsVALUE, value);
231223
}

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)