opaque-RStruct.patch

Shyouhei Urabe, 06/07/2014 12:05 PM

Download (6.16 KB)

View differences:

ChangeLog
1
Sat Jun  7 20:43:42 2014  URABE Shyouhei  <shyouhei@ruby-lang.org>
2

  
3
	* include/ruby/ruby.h (struct RStruct): no longer.
4

  
5
	* internal.h (struct RStruct): moved here.
6

  
7
	* struct.c (rb_struct_ptr): a compensation function for the lack
8
	  of RSTRUCT_PTR.  But now that we have RSTRUCT_GET/SET, that must
9
	  not be used anyway.  I mark this deprecated.  Dont use it.
10

  
1 11
Sat Jun  7 18:15:33 2014  Benoit Daloze  <eregontp@gmail.com>
2 12

  
3 13
	* numeric.c (bit_coerce): remove constant parameter `err'
include/ruby/intern.h
835 835
VALUE rb_struct_getmember(VALUE, ID);
836 836
VALUE rb_struct_s_members(VALUE);
837 837
VALUE rb_struct_members(VALUE);
838
VALUE rb_struct_size(VALUE s);
839
DEPRECATED(VALUE const* rb_struct_ptr(VALUE s));
838 840
VALUE rb_struct_alloc_noinit(VALUE);
839 841
VALUE rb_struct_define_without_accessor(const char *, VALUE, rb_alloc_func_t, ...);
840 842
VALUE rb_struct_define_without_accessor_under(VALUE outer, const char *class_name, VALUE super, rb_alloc_func_t alloc, ...);
include/ruby/ruby.h
1040 1040
    (sval) = (type*)rb_check_typeddata((obj), (data_type)); \
1041 1041
} while (0)
1042 1042

  
1043
#define RSTRUCT_EMBED_LEN_MAX 3
1044
struct RStruct {
1045
    struct RBasic basic;
1046
    union {
1047
	struct {
1048
	    long len;
1049
	    const VALUE *ptr;
1050
	} heap;
1051
	const VALUE ary[RSTRUCT_EMBED_LEN_MAX];
1052
    } as;
1053
};
1054
#define RSTRUCT_EMBED_LEN_MASK (FL_USER2|FL_USER1)
1055
#define RSTRUCT_EMBED_LEN_SHIFT (FL_USHIFT+1)
1056
#define RSTRUCT_LEN(st) \
1057
    ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
1058
     (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \
1059
            (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT)) : \
1060
     RSTRUCT(st)->as.heap.len)
1061
#define RSTRUCT_LENINT(st) rb_long2int(RSTRUCT_LEN(st))
1062
#define RSTRUCT_CONST_PTR(st) \
1063
  ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
1064
   RSTRUCT(st)->as.ary : \
1065
   RSTRUCT(st)->as.heap.ptr)
1066
#define RSTRUCT_PTR(st) ((VALUE *)RSTRUCT_CONST_PTR(RGENGC_WB_PROTECTED_STRUCT ? OBJ_WB_UNPROTECT((VALUE)st) : (VALUE)st))
1067

  
1068
#define RSTRUCT_SET(st, idx, v) RB_OBJ_WRITE(st, &RSTRUCT_CONST_PTR(st)[idx], (v))
1069
#define RSTRUCT_GET(st, idx)    (RSTRUCT_CONST_PTR(st)[idx])
1043
#define RSTRUCT_LEN(st)         rb_struct_size(st)
1044
#define RSTRUCT_PTR(st)         rb_struct_ptr(st)
1045
#define RSTRUCT_SET(st, idx, v) rb_struct_aset(st, INT2NUM(idx), (v))
1046
#define RSTRUCT_GET(st, idx)    rb_struct_aref(st, INT2NUM(idx))
1070 1047

  
1071 1048
#define RBIGNUM_SIGN(b) (FIX2LONG(rb_big_cmp((b), INT2FIX(0))) >= 0)
1072 1049
#define RBIGNUM_POSITIVE_P(b) (FIX2LONG(rb_big_cmp((b), INT2FIX(0))) >= 0)
......
1084 1061
#define RHASH(obj)   (R_CAST(RHash)(obj))
1085 1062
#define RDATA(obj)   (R_CAST(RData)(obj))
1086 1063
#define RTYPEDDATA(obj)   (R_CAST(RTypedData)(obj))
1087
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
1088 1064
#define RFILE(obj)   (R_CAST(RFile)(obj))
1089 1065
#define RCOMPLEX(obj) (R_CAST(RComplex)(obj))
1090 1066

  
internal.h
420 420

  
421 421
#define RSYMBOL(obj) (R_CAST(RSymbol)(obj))
422 422

  
423
#define RSTRUCT_EMBED_LEN_MAX 3
424
struct RStruct {
425
    struct RBasic basic;
426
    union {
427
	struct {
428
	    long len;
429
	    const VALUE *ptr;
430
	} heap;
431
	const VALUE ary[RSTRUCT_EMBED_LEN_MAX];
432
    } as;
433
};
434
#ifdef RSTRUCT_SET
435
#undef RSTRUCT_LEN
436
#undef RSTRUCT_PTR
437
#undef RSTRUCT_SET
438
#undef RSTRUCT_GET
439
#endif
440
#define RSTRUCT_EMBED_LEN_MASK (FL_USER2|FL_USER1)
441
#define RSTRUCT_EMBED_LEN_SHIFT (FL_USHIFT+1)
442
#define RSTRUCT_LEN(st) \
443
    ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
444
     (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \
445
            (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT)) : \
446
     RSTRUCT(st)->as.heap.len)
447
#define RSTRUCT_LENINT(st) rb_long2int(RSTRUCT_LEN(st))
448
#define RSTRUCT_CONST_PTR(st) \
449
  ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
450
   RSTRUCT(st)->as.ary : \
451
   RSTRUCT(st)->as.heap.ptr)
452
#define RSTRUCT_PTR(st) ((VALUE *)RSTRUCT_CONST_PTR(RGENGC_WB_PROTECTED_STRUCT ? OBJ_WB_UNPROTECT((VALUE)st) : (VALUE)st))
453

  
454
#define RSTRUCT_SET(st, idx, v) RB_OBJ_WRITE(st, &RSTRUCT_CONST_PTR(st)[idx], (v))
455
#define RSTRUCT_GET(st, idx)    (RSTRUCT_CONST_PTR(st)[idx])
456

  
457
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
458

  
423 459
/* class.c */
424 460
void rb_class_subclass_add(VALUE super, VALUE klass);
425 461
void rb_class_remove_from_super_subclasses(VALUE);
struct.c
515 515
}
516 516

  
517 517
static VALUE
518
rb_struct_size(VALUE s);
519

  
520
static VALUE
521 518
struct_enum_size(VALUE s, VALUE args, VALUE eobj)
522 519
{
523 520
    return rb_struct_size(s);
......
1032 1029
 *     joe.length   #=> 3
1033 1030
 */
1034 1031

  
1035
static VALUE
1032
VALUE
1036 1033
rb_struct_size(VALUE s)
1037 1034
{
1038 1035
    return LONG2FIX(RSTRUCT_LEN(s));
1039 1036
}
1040 1037

  
1038
VALUE const*
1039
rb_struct_ptr(VALUE s)
1040
{
1041
    return RSTRUCT_CONST_PTR(s);
1042
}
1043

  
1041 1044
/*
1042 1045
 *  A Struct is a convenient way to bundle a number of attributes together,
1043 1046
 *  using accessor methods, without having to write an explicit class.
1044
-