racc.patch

Dirkjan Bussink, 05/13/2013 02:40 PM

Download (4.79 KB)

View differences:

w/ext/racc/cparse/cparse.c
91 91
}
92 92

  
93 93
#define AREF(s, idx) \
94
    ((0 <= idx && idx < RARRAY_LEN(s)) ? RARRAY_PTR(s)[idx] : Qnil)
94
    ((0 <= idx && idx < RARRAY_LEN(s)) ? rb_ary_entry(s, idx) : Qnil)
95 95

  
96 96
/* -----------------------------------------------------------------------
97 97
                        Parser Stack Interfaces
......
103 103
static VALUE
104 104
get_stack_tail(VALUE stack, long len)
105 105
{
106
    int i;
107
    VALUE ret;
106 108
    if (len < 0) return Qnil;  /* system error */
107 109
    if (len > RARRAY_LEN(stack)) len = RARRAY_LEN(stack);
108
    return rb_ary_new4(len, RARRAY_PTR(stack) + RARRAY_LEN(stack) - len);
110
    ret = rb_ary_new2(len);
111
    RB_GC_GUARD(ret);
112
    for(i = 0; i < len; i++) {
113
        rb_ary_push(ret, rb_ary_entry(stack, RARRAY_LEN(stack) - len + i));
114
    }
115
    return ret;
109 116
}
110 117

  
111 118
static void
......
122 129
#define PUSH(s, i) rb_ary_store(s, RARRAY_LEN(s), i)
123 130
#define POP(s) rb_ary_pop(s)
124 131
#define LAST_I(s) \
125
    ((RARRAY_LEN(s) > 0) ? RARRAY_PTR(s)[RARRAY_LEN(s) - 1] : Qnil)
132
    ((RARRAY_LEN(s) > 0) ? rb_ary_entry(s, RARRAY_LEN(s) - 1) : Qnil)
126 133
#define GET_TAIL(s, len) get_stack_tail(s, len)
127 134
#define CUT_TAIL(s, len) cut_stack_tail(s, len)
128 135

  
......
334 341
    Check_Type(arg, T_ARRAY);
335 342
    if (!(13 <= RARRAY_LEN(arg) && RARRAY_LEN(arg) <= 14))
336 343
        rb_raise(RaccBug, "[Racc Bug] wrong arg.size %ld", RARRAY_LEN(arg));
337
    v->action_table   = assert_array  (RARRAY_PTR(arg)[ 0]);
338
    v->action_check   = assert_array  (RARRAY_PTR(arg)[ 1]);
339
    v->action_default = assert_array  (RARRAY_PTR(arg)[ 2]);
340
    v->action_pointer = assert_array  (RARRAY_PTR(arg)[ 3]);
341
    v->goto_table     = assert_array  (RARRAY_PTR(arg)[ 4]);
342
    v->goto_check     = assert_array  (RARRAY_PTR(arg)[ 5]);
343
    v->goto_default   = assert_array  (RARRAY_PTR(arg)[ 6]);
344
    v->goto_pointer   = assert_array  (RARRAY_PTR(arg)[ 7]);
345
    v->nt_base        = assert_integer(RARRAY_PTR(arg)[ 8]);
346
    v->reduce_table   = assert_array  (RARRAY_PTR(arg)[ 9]);
347
    v->token_table    = assert_hash   (RARRAY_PTR(arg)[10]);
348
    v->shift_n        = assert_integer(RARRAY_PTR(arg)[11]);
349
    v->reduce_n       = assert_integer(RARRAY_PTR(arg)[12]);
344
    v->action_table   = assert_array  (rb_ary_entry(arg,  0));
345
    v->action_check   = assert_array  (rb_ary_entry(arg,  1));
346
    v->action_default = assert_array  (rb_ary_entry(arg,  2));
347
    v->action_pointer = assert_array  (rb_ary_entry(arg,  3));
348
    v->goto_table     = assert_array  (rb_ary_entry(arg,  4));
349
    v->goto_check     = assert_array  (rb_ary_entry(arg,  5));
350
    v->goto_default   = assert_array  (rb_ary_entry(arg,  6));
351
    v->goto_pointer   = assert_array  (rb_ary_entry(arg,  7));
352
    v->nt_base        = assert_integer(rb_ary_entry(arg,  8));
353
    v->reduce_table   = assert_array  (rb_ary_entry(arg,  9));
354
    v->token_table    = assert_hash   (rb_ary_entry(arg, 10));
355
    v->shift_n        = assert_integer(rb_ary_entry(arg, 11));
356
    v->reduce_n       = assert_integer(rb_ary_entry(arg, 12));
350 357
    if (RARRAY_LEN(arg) > 13) {
351
        v->use_result_var = RTEST(RARRAY_PTR(arg)[13]);
358
        v->use_result_var = RTEST(rb_ary_entry(arg, 13));
352 359
    }
353 360
    else {
354 361
        v->use_result_var = TRUE;
......
564 571

  
565 572
  accept:
566 573
    if (v->debug) rb_funcall(v->parser, id_d_accept, 0);
567
    v->retval = RARRAY_PTR(v->vstack)[0];
574
    v->retval = rb_ary_entry(v->vstack, 0);
568 575
    v->fin = CP_FIN_ACCEPT;
569 576
    return;
570 577

  
......
693 700
    VALUE goto_state;
694 701

  
695 702
    Data_Get_Struct(data, struct cparse_params, v);
696
    reduce_len = RARRAY_PTR(v->reduce_table)[v->ruleno];
697
    reduce_to  = RARRAY_PTR(v->reduce_table)[v->ruleno+1];
698
    method_id  = RARRAY_PTR(v->reduce_table)[v->ruleno+2];
703
    reduce_len = rb_ary_entry(v->reduce_table, v->ruleno);
704
    reduce_to  = rb_ary_entry(v->reduce_table, v->ruleno+1);
705
    method_id  = rb_ary_entry(v->reduce_table, v->ruleno+2);
699 706
    len = NUM2LONG(reduce_len);
700 707
    mid = value_to_id(method_id);
701 708

  
......
710 717
    else {
711 718
        if (mid != id_noreduce) {
712 719
            tmp_v = GET_TAIL(v->vstack, len);
713
            tmp = RARRAY_PTR(tmp_v)[0];
720
            tmp = rb_ary_entry(tmp_v, 0);
714 721
        }
715 722
        else {
716
            tmp = RARRAY_PTR(v->vstack)[ RARRAY_LEN(v->vstack) - len ];
723
            tmp = rb_ary_entry(v->vstack, RARRAY_LEN(v->vstack) - len);
717 724
        }
718 725
        CUT_TAIL(v->vstack, len);
719 726
        if (v->debug) {