Feature #9863

Hide Float internal

Added by Shyouhei Urabe 9 months ago. Updated 8 months ago.

[ruby-core:62748]
Status:Closed
Priority:Normal
Assignee:-

Description

From 93f013d689abed19f4223f968e374046437b7fa7 Mon Sep 17 00:00:00 2001
From: "Urabe, Shyouhei" <shyouhei@ruby-lang.org>
Date: Sun, 25 May 2014 21:28:12 +0900
Subject: [PATCH] Hide Float internal
I'd like to make `struct RFloat` opaque.

We already have flonum.  Looking into struct RFloat's internals have (I believe) zero use.

The struct is already accessed via appropriate macros/functions so hiding it is super-duper easy (see the patch).  Passes test-all.

Signed-off-by: Urabe, Shyouhei <shyouhei@ruby-lang.org>
---
 ChangeLog           | 6 ++++++
 include/ruby/ruby.h | 6 +-----
 internal.h          | 7 +++++++
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7cc6e5b..3462eea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun May 25 21:12:15 2014  URABE Shyouhei  <shyouhei@ruby-lang.org>
+
+   * include/ruby/ruby.h (struct RFloat): no longer.
+
+   * internal.h (struct RFloat): moved here.
+
 Sun May 25 20:31:49 2014  Nobuyoshi Nakada  <nobu@ruby-lang.org>

    * configure.in (ac_cv_func_{getcontext,setcontext}): do not
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index a39b958..e99b6db 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -807,10 +807,7 @@ struct RClass {
 #define RMODULE_IS_REFINEMENT FL_USER3
 #define RMODULE_INCLUDED_INTO_REFINEMENT FL_USER4

-struct RFloat {
-    struct RBasic basic;
-    double float_value;
-};
+struct RFloat;

 double rb_float_value(VALUE);
 VALUE rb_float_new(double);
@@ -1083,7 +1080,6 @@ struct RStruct {
 #define ROBJECT(obj) (R_CAST(RObject)(obj))
 #define RCLASS(obj)  (R_CAST(RClass)(obj))
 #define RMODULE(obj) RCLASS(obj)
-#define RFLOAT(obj)  (R_CAST(RFloat)(obj))
 #define RSTRING(obj) (R_CAST(RString)(obj))
 #define RREGEXP(obj) (R_CAST(RRegexp)(obj))
 #define RARRAY(obj)  (R_CAST(RArray)(obj))
diff --git a/internal.h b/internal.h
index 071f3ed..bd2c4fd 100644
--- a/internal.h
+++ b/internal.h
@@ -412,6 +412,13 @@ struct RRational {

 #define RRATIONAL(obj) (R_CAST(RRational)(obj))

+struct RFloat {
+    struct RBasic basic;
+    double float_value;
+};
+
+#define RFLOAT(obj) (R_CAST(RFloat)(obj))
+
 /* class.c */
 void rb_class_subclass_add(VALUE super, VALUE klass);
 void rb_class_remove_from_super_subclasses(VALUE);
-- 
1.9.1

Associated revisions

Revision 46505
Added by Shyouhei Urabe 8 months ago

  • include/ruby/ruby.h (struct RFloat): no longer. [Feature #9863]

    • include/ruby/ruby.h (RFLOAT): ditto.
    • internal.h (struct RFloat): moved here.
    • internal.h (RFLOAT): ditto.

Revision 46505
Added by Shyouhei Urabe 8 months ago

  • include/ruby/ruby.h (struct RFloat): no longer. [Feature #9863]

    • include/ruby/ruby.h (RFLOAT): ditto.
    • internal.h (struct RFloat): moved here.
    • internal.h (RFLOAT): ditto.

History

#1 Updated by Eric Wong 9 months ago

shyouhei@ruby-lang.org wrote:

Feature #9863: Hide Float internal

Yes please. Probably a few more easy ones to hide:
RSymbol - new in 2.2, no compatibility risk?
RComplex - probably the same 3rd-party usage RRational

#2 Updated by Yukihiro Matsumoto 8 months ago

Approved.

Matz.

#3 Updated by Shyouhei Urabe 8 months ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r46505.


  • include/ruby/ruby.h (struct RFloat): no longer. [Feature #9863]

    • include/ruby/ruby.h (RFLOAT): ditto.
    • internal.h (struct RFloat): moved here.
    • internal.h (RFLOAT): ditto.

Also available in: Atom PDF