[前][次][番号順一覧][スレッド一覧]

ruby-changes:35764

From: nobu <ko1@a...>
Date: Wed, 8 Oct 2014 17:27:58 +0900 (JST)
Subject: [ruby-changes:35764] nobu:r47846 (trunk): constant.h: constant visibilities

nobu	2014-10-08 17:27:51 +0900 (Wed, 08 Oct 2014)

  New Revision: 47846

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47846

  Log:
    constant.h: constant visibilities
    
    * constant.h (RB_CONST_PRIVATE_P, RB_CONST_PUBLIC_P): macros to
      predicate constant visibilities.

  Modified files:
    trunk/constant.h
    trunk/variable.c
Index: variable.c
===================================================================
--- variable.c	(revision 47845)
+++ variable.c	(revision 47846)
@@ -1836,7 +1836,7 @@ rb_const_get_0(VALUE klass, ID id, int e https://github.com/ruby/ruby/blob/trunk/variable.c#L1836
 	rb_const_entry_t *ce;
 
 	while ((ce = rb_const_lookup(tmp, id))) {
-	    if (visibility && ce->flag == CONST_PRIVATE) {
+	    if (visibility && RB_CONST_PRIVATE_P(ce)) {
 		rb_name_error(id, "private constant %"PRIsVALUE"::%"PRIsVALUE" referenced",
 			      rb_class_name(klass), QUOTE_ID(id));
 	    }
@@ -2029,7 +2029,7 @@ list_i(st_data_t key, st_data_t value, V https://github.com/ruby/ruby/blob/trunk/variable.c#L2029
 {
     ID sym = (ID)key;
     rb_const_entry_t *ce = (rb_const_entry_t *)value;
-    if (ce->flag != CONST_PRIVATE) rb_ary_push(ary, ID2SYM(sym));
+    if (RB_CONST_PUBLIC_P(ce)) rb_ary_push(ary, ID2SYM(sym));
     return ST_CONTINUE;
 }
 
@@ -2093,7 +2093,7 @@ rb_const_defined_0(VALUE klass, ID id, i https://github.com/ruby/ruby/blob/trunk/variable.c#L2093
   retry:
     while (tmp) {
 	if ((ce = rb_const_lookup(tmp, id))) {
-	    if (visibility && ce->flag == CONST_PRIVATE) {
+	    if (visibility && RB_CONST_PRIVATE_P(ce)) {
 		return (int)Qfalse;
 	    }
 	    if (ce->value == Qundef && !check_autoload_required(tmp, id, 0) && !rb_autoloading_value(tmp, id, 0))
Index: constant.h
===================================================================
--- constant.h	(revision 47845)
+++ constant.h	(revision 47846)
@@ -13,9 +13,15 @@ https://github.com/ruby/ruby/blob/trunk/constant.h#L13
 
 typedef enum {
     CONST_PUBLIC    = 0x00,
-    CONST_PRIVATE   = 0x01
+    CONST_PRIVATE,
+    CONST_VISIBILITY_MAX
 } rb_const_flag_t;
 
+#define RB_CONST_PRIVATE_P(ce) \
+    ((ce)->flag == CONST_PRIVATE)
+#define RB_CONST_PUBLIC_P(ce) \
+    ((ce)->flag == CONST_PUBLIC)
+
 typedef struct rb_const_entry_struct {
     rb_const_flag_t flag;
     int line;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]