hide-bignum-internal.patch

Akira Tanaka, 02/12/2014 11:45 AM

Download (4.66 KB)

View differences:

ext/-test-/bignum/bigzero.c (working copy)
1 1
#include "ruby.h"
2
#include "internal.h"
2 3

  
3 4
static VALUE
4 5
bug_big_zero(VALUE self, VALUE length)
include/ruby/ruby.h (working copy)
1072 1072
#define RSTRUCT_SET(st, idx, v) RB_OBJ_WRITE(st, &RSTRUCT_CONST_PTR(st)[idx], (v))
1073 1073
#define RSTRUCT_GET(st, idx)    (RSTRUCT_CONST_PTR(st)[idx])
1074 1074

  
1075
#define RBIGNUM_EMBED_LEN_NUMBITS 3
1076
#ifndef RBIGNUM_EMBED_LEN_MAX
1077
# if (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT) < (1 << RBIGNUM_EMBED_LEN_NUMBITS)-1
1078
#   define RBIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT)
1079
# else
1080
#   define RBIGNUM_EMBED_LEN_MAX ((1 << RBIGNUM_EMBED_LEN_NUMBITS)-1)
1081
# endif
1082
#endif
1083
struct RBignum {
1084
    struct RBasic basic;
1085
    union {
1086
        struct {
1087
            long len;
1088
            BDIGIT *digits;
1089
        } heap;
1090
        BDIGIT ary[RBIGNUM_EMBED_LEN_MAX];
1091
    } as;
1092
};
1093
#define RBIGNUM_SIGN_BIT FL_USER1
1094
/* sign: positive:1, negative:0 */
1095
#define RBIGNUM_SIGN(b) ((RBASIC(b)->flags & RBIGNUM_SIGN_BIT) != 0)
1096
#define RBIGNUM_SET_SIGN(b,sign) \
1097
  ((sign) ? (RBASIC(b)->flags |= RBIGNUM_SIGN_BIT) \
1098
          : (RBASIC(b)->flags &= ~RBIGNUM_SIGN_BIT))
1099
#define RBIGNUM_POSITIVE_P(b) RBIGNUM_SIGN(b)
1100
#define RBIGNUM_NEGATIVE_P(b) (!RBIGNUM_SIGN(b))
1101

  
1102
#define RBIGNUM_EMBED_FLAG FL_USER2
1103
#define RBIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3)
1104
#define RBIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+RBIGNUM_EMBED_LEN_NUMBITS)
1105
#define RBIGNUM_LEN(b) \
1106
    ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
1107
     (long)((RBASIC(b)->flags >> RBIGNUM_EMBED_LEN_SHIFT) & \
1108
            (RBIGNUM_EMBED_LEN_MASK >> RBIGNUM_EMBED_LEN_SHIFT)) : \
1109
     RBIGNUM(b)->as.heap.len)
1110
/* LSB:RBIGNUM_DIGITS(b)[0], MSB:RBIGNUM_DIGITS(b)[RBIGNUM_LEN(b)-1] */
1111
#define RBIGNUM_DIGITS(b) \
1112
    ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
1113
     RBIGNUM(b)->as.ary : \
1114
     RBIGNUM(b)->as.heap.digits)
1115
#define RBIGNUM_LENINT(b) rb_long2int(RBIGNUM_LEN(b))
1116

  
1117 1075
#define R_CAST(st)   (struct st*)
1118 1076
#define RBASIC(obj)  (R_CAST(RBasic)(obj))
1119 1077
#define ROBJECT(obj) (R_CAST(RObject)(obj))
......
1127 1085
#define RDATA(obj)   (R_CAST(RData)(obj))
1128 1086
#define RTYPEDDATA(obj)   (R_CAST(RTypedData)(obj))
1129 1087
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
1130
#define RBIGNUM(obj) (R_CAST(RBignum)(obj))
1131 1088
#define RFILE(obj)   (R_CAST(RFile)(obj))
1132 1089
#define RRATIONAL(obj) (R_CAST(RRational)(obj))
1133 1090
#define RCOMPLEX(obj) (R_CAST(RComplex)(obj))
internal.h (working copy)
305 305
    size_t serial;
306 306
};
307 307

  
308
#define RBIGNUM_EMBED_LEN_NUMBITS 3
309
#ifndef RBIGNUM_EMBED_LEN_MAX
310
# if (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT) < (1 << RBIGNUM_EMBED_LEN_NUMBITS)-1
311
#   define RBIGNUM_EMBED_LEN_MAX (SIZEOF_VALUE*3/SIZEOF_ACTUAL_BDIGIT)
312
# else
313
#   define RBIGNUM_EMBED_LEN_MAX ((1 << RBIGNUM_EMBED_LEN_NUMBITS)-1)
314
# endif
315
#endif
316

  
317
struct RBignum {
318
    struct RBasic basic;
319
    union {
320
        struct {
321
            long len;
322
            BDIGIT *digits;
323
        } heap;
324
        BDIGIT ary[RBIGNUM_EMBED_LEN_MAX];
325
    } as;
326
};
327
#define RBIGNUM_SIGN_BIT FL_USER1
328
/* sign: positive:1, negative:0 */
329
#define RBIGNUM_SIGN(b) ((RBASIC(b)->flags & RBIGNUM_SIGN_BIT) != 0)
330
#define RBIGNUM_SET_SIGN(b,sign) \
331
  ((sign) ? (RBASIC(b)->flags |= RBIGNUM_SIGN_BIT) \
332
          : (RBASIC(b)->flags &= ~RBIGNUM_SIGN_BIT))
333
#define RBIGNUM_POSITIVE_P(b) RBIGNUM_SIGN(b)
334
#define RBIGNUM_NEGATIVE_P(b) (!RBIGNUM_SIGN(b))
335

  
336
#define RBIGNUM_EMBED_FLAG FL_USER2
337
#define RBIGNUM_EMBED_LEN_MASK (FL_USER5|FL_USER4|FL_USER3)
338
#define RBIGNUM_EMBED_LEN_SHIFT (FL_USHIFT+RBIGNUM_EMBED_LEN_NUMBITS)
339
#define RBIGNUM_LEN(b) \
340
    ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
341
     (long)((RBASIC(b)->flags >> RBIGNUM_EMBED_LEN_SHIFT) & \
342
            (RBIGNUM_EMBED_LEN_MASK >> RBIGNUM_EMBED_LEN_SHIFT)) : \
343
     RBIGNUM(b)->as.heap.len)
344
/* LSB:RBIGNUM_DIGITS(b)[0], MSB:RBIGNUM_DIGITS(b)[RBIGNUM_LEN(b)-1] */
345
#define RBIGNUM_DIGITS(b) \
346
    ((RBASIC(b)->flags & RBIGNUM_EMBED_FLAG) ? \
347
     RBIGNUM(b)->as.ary : \
348
     RBIGNUM(b)->as.heap.digits)
349
#define RBIGNUM_LENINT(b) rb_long2int(RBIGNUM_LEN(b))
350

  
351
#define RBIGNUM(obj) (R_CAST(RBignum)(obj))
352

  
308 353
/* class.c */
309 354
void rb_class_subclass_add(VALUE super, VALUE klass);
310 355
void rb_class_remove_from_super_subclasses(VALUE);