ruby-changes:59718
From: Kenta <ko1@a...>
Date: Fri, 17 Jan 2020 10:05:26 +0900 (JST)
Subject: [ruby-changes:59718] 019a0ed0c7 (master): Make RATIONAL_SET_{NUM, DEN} static inline functions
https://git.ruby-lang.org/ruby.git/commit/?id=019a0ed0c7 From 019a0ed0c78ccd0eb694d09c6a226761261ec15d Mon Sep 17 00:00:00 2001 From: Kenta Murata <mrkn@m...> Date: Fri, 17 Jan 2020 09:05:17 +0900 Subject: Make RATIONAL_SET_{NUM,DEN} static inline functions diff --git a/internal/rational.h b/internal/rational.h index c783c51..028fc4c 100644 --- a/internal/rational.h +++ b/internal/rational.h @@ -11,6 +11,7 @@ https://github.com/ruby/ruby/blob/trunk/internal/rational.h#L11 */ #include "ruby/config.h" /* for HAVE_LIBGMP */ #include "ruby/ruby.h" /* for struct RBasic */ +#include "internal/gc.h" /* for RB_OBJ_WRITE */ struct RRational { struct RBasic basic; @@ -19,8 +20,6 @@ struct RRational { https://github.com/ruby/ruby/blob/trunk/internal/rational.h#L20 }; #define RRATIONAL(obj) (R_CAST(RRational)(obj)) -#define RRATIONAL_SET_NUM(rat, n) RB_OBJ_WRITE((rat), &RRATIONAL(rat)->num, (n)) -#define RRATIONAL_SET_DEN(rat, d) RB_OBJ_WRITE((rat), &RRATIONAL(rat)->den, (d)) /* rational.c */ VALUE rb_rational_canonicalize(VALUE x); @@ -37,6 +36,9 @@ VALUE rb_numeric_quo(VALUE x, VALUE y); https://github.com/ruby/ruby/blob/trunk/internal/rational.h#L36 VALUE rb_float_numerator(VALUE x); VALUE rb_float_denominator(VALUE x); +static inline void RATIONAL_SET_NUM(VALUE r, VALUE n); +static inline void RATIONAL_SET_DEN(VALUE r, VALUE d); + RUBY_SYMBOL_EXPORT_BEGIN /* rational.c (export) */ VALUE rb_gcd(VALUE x, VALUE y); @@ -46,4 +48,16 @@ VALUE rb_gcd_gmp(VALUE x, VALUE y); https://github.com/ruby/ruby/blob/trunk/internal/rational.h#L48 #endif RUBY_SYMBOL_EXPORT_END +static inline void +RATIONAL_SET_NUM(VALUE r, VALUE n) +{ + RB_OBJ_WRITE(r, &RRATIONAL(r)->num, n); +} + +static inline void +RATIONAL_SET_DEN(VALUE r, VALUE d) +{ + RB_OBJ_WRITE(r, &RRATIONAL(r)->den, d); +} + #endif /* INTERNAL_RATIONAL_H */ diff --git a/parse.y b/parse.y index 1facda5..c0d4639 100644 --- a/parse.y +++ b/parse.y @@ -11240,7 +11240,7 @@ negate_lit(struct parser_params *p, VALUE lit) https://github.com/ruby/ruby/blob/trunk/parse.y#L11240 lit = rb_big_norm(lit); break; case T_RATIONAL: - RRATIONAL_SET_NUM(lit, negate_lit(p, RRATIONAL(lit)->num)); + RATIONAL_SET_NUM(lit, negate_lit(p, RRATIONAL(lit)->num)); break; case T_COMPLEX: RCOMPLEX_SET_REAL(lit, negate_lit(p, RCOMPLEX(lit)->real)); diff --git a/rational.c b/rational.c index 8b4a394..4ae872b 100644 --- a/rational.c +++ b/rational.c @@ -403,8 +403,8 @@ nurat_s_new_internal(VALUE klass, VALUE num, VALUE den) https://github.com/ruby/ruby/blob/trunk/rational.c#L403 { NEWOBJ_OF(obj, struct RRational, klass, T_RATIONAL | (RGENGC_WB_PROTECTED_RATIONAL ? FL_WB_PROTECTED : 0)); - RRATIONAL_SET_NUM(obj, num); - RRATIONAL_SET_DEN(obj, den); + RATIONAL_SET_NUM((VALUE)obj, num); + RATIONAL_SET_DEN((VALUE)obj, den); OBJ_FREEZE_RAW(obj); return (VALUE)obj; @@ -1836,8 +1836,8 @@ nurat_loader(VALUE self, VALUE a) https://github.com/ruby/ruby/blob/trunk/rational.c#L1836 nurat_int_check(num); nurat_int_check(den); nurat_canonicalize(&num, &den); - RRATIONAL_SET_NUM(dat, num); - RRATIONAL_SET_DEN(dat, den); + RATIONAL_SET_NUM((VALUE)dat, num); + RATIONAL_SET_DEN((VALUE)dat, den); OBJ_FREEZE_RAW(self); return self; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/