~ubuntu-branches/ubuntu/intrepid/ruby1.9/intrepid-updates

« back to all changes in this revision

Viewing changes to proc.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-09-04 16:01:17 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070904160117-i15zckg2nhxe9fyw
Tags: 1.9.0+20070830-2ubuntu1
* Sync from Debian; remaining changes:
  - Add -g to CFLAGS.
* Fixes build failure on ia64.
* Fixes build failure with gcc-4.2 on lpia.
* Robustify check for target_os, fixing build failure on lpia.
* Set Ubuntu maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
  proc.c - Proc, Bindng, Env
4
4
 
5
5
  $Author: ko1 $
6
 
  $Date: 2007-06-06 02:26:00 +0900 (水, 06  6月 2007) $
 
6
  $Date: 2007-08-19 13:02:21 +0900 (日, 19  8月 2007) $
7
7
  created at: Wed Jan 17 12:13:14 2007
8
8
 
9
9
  Copyright (C) 2004-2007 Koichi Sasada
34
34
static void
35
35
proc_free(void *ptr)
36
36
{
37
 
    FREE_REPORT_ENTER("proc");
 
37
    RUBY_FREE_ENTER("proc");
38
38
    if (ptr) {
39
39
        ruby_xfree(ptr);
40
40
    }
41
 
    FREE_REPORT_LEAVE("proc");
 
41
    RUBY_FREE_LEAVE("proc");
42
42
}
43
43
 
44
44
static void
45
45
proc_mark(void *ptr)
46
46
{
47
47
    rb_proc_t *proc;
48
 
    MARK_REPORT_ENTER("proc");
 
48
    RUBY_MARK_ENTER("proc");
49
49
    if (ptr) {
50
50
        proc = ptr;
51
 
        MARK_UNLESS_NULL(proc->envval);
52
 
        MARK_UNLESS_NULL(proc->blockprocval);
53
 
        MARK_UNLESS_NULL((VALUE)proc->special_cref_stack);
54
 
        MARK_UNLESS_NULL(proc->block.proc);
 
51
        RUBY_MARK_UNLESS_NULL(proc->envval);
 
52
        RUBY_MARK_UNLESS_NULL(proc->blockprocval);
 
53
        RUBY_MARK_UNLESS_NULL((VALUE)proc->special_cref_stack);
 
54
        RUBY_MARK_UNLESS_NULL(proc->block.proc);
55
55
        if (proc->block.iseq && RUBY_VM_IFUNC_P(proc->block.iseq)) {
56
 
            MARK_UNLESS_NULL((VALUE)(proc->block.iseq));
 
56
            RUBY_MARK_UNLESS_NULL((VALUE)(proc->block.iseq));
57
57
        }
58
58
    }
59
 
    MARK_REPORT_LEAVE("proc");
 
59
    RUBY_MARK_LEAVE("proc");
60
60
}
61
61
 
62
 
static VALUE
63
 
proc_alloc(VALUE klass)
 
62
VALUE
 
63
rb_proc_alloc(VALUE klass)
64
64
{
65
65
    VALUE obj;
66
66
    rb_proc_t *proc;
70
70
}
71
71
 
72
72
VALUE
73
 
rb_proc_alloc(void)
74
 
{
75
 
    return proc_alloc(rb_cProc);
76
 
}
77
 
 
78
 
VALUE
79
73
rb_obj_is_proc(VALUE proc)
80
74
{
81
75
    if (TYPE(proc) == T_DATA &&
90
84
static VALUE
91
85
proc_dup(VALUE self)
92
86
{
93
 
    VALUE procval = proc_alloc(rb_cProc);
 
87
    VALUE procval = rb_proc_alloc(rb_cProc);
94
88
    rb_proc_t *src, *dst;
95
89
    GetProcPtr(self, src);
96
90
    GetProcPtr(procval, dst);
126
120
binding_free(void *ptr)
127
121
{
128
122
    rb_binding_t *bind;
129
 
    FREE_REPORT_ENTER("binding");
 
123
    RUBY_FREE_ENTER("binding");
130
124
    if (ptr) {
131
125
        bind = ptr;
132
126
        ruby_xfree(ptr);
133
127
    }
134
 
    FREE_REPORT_LEAVE("binding");
 
128
    RUBY_FREE_LEAVE("binding");
135
129
}
136
130
 
137
131
static void
138
132
binding_mark(void *ptr)
139
133
{
140
134
    rb_binding_t *bind;
141
 
    MARK_REPORT_ENTER("binding");
 
135
    RUBY_MARK_ENTER("binding");
142
136
    if (ptr) {
143
137
        bind = ptr;
144
 
        MARK_UNLESS_NULL(bind->env);
145
 
        MARK_UNLESS_NULL((VALUE)bind->cref_stack);
 
138
        RUBY_MARK_UNLESS_NULL(bind->env);
 
139
        RUBY_MARK_UNLESS_NULL((VALUE)bind->cref_stack);
146
140
    }
147
 
    MARK_REPORT_LEAVE("binding");
 
141
    RUBY_MARK_LEAVE("binding");
148
142
}
149
143
 
150
144
static VALUE
182
176
rb_binding_new(void)
183
177
{
184
178
    rb_thread_t *th = GET_THREAD();
185
 
    rb_control_frame_t *cfp = th_get_ruby_level_cfp(th, th->cfp);
 
179
    rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp);
186
180
    VALUE bindval = binding_alloc(rb_cBinding);
187
181
    rb_binding_t *bind;
188
182
 
189
183
    GetBindingPtr(bindval, bind);
190
 
    bind->env = th_make_env_object(th, cfp);
 
184
    bind->env = vm_make_env_object(th, cfp);
191
185
    bind->cref_stack = ruby_cref();
192
186
    return bindval;
193
187
}
240
234
    return rb_f_eval(argc+1, args, Qnil /* self will be searched in eval */);
241
235
}
242
236
 
243
 
#define PROC_TSHIFT (FL_USHIFT+1)
244
 
#define PROC_TMASK  (FL_USER1|FL_USER2|FL_USER3)
245
 
#define PROC_TMAX   (PROC_TMASK >> PROC_TSHIFT)
246
 
#define PROC_NOSAFE FL_USER4
247
 
 
248
 
#define SAFE_LEVEL_MAX PROC_TMASK
249
 
 
250
237
static VALUE
251
238
proc_new(VALUE klass, int is_lambda)
252
239
{
284
271
        }
285
272
    }
286
273
 
287
 
    procval = th_make_proc(th, cfp, block);
 
274
    if (block->proc) {
 
275
        return block->proc;
 
276
    }
 
277
 
 
278
    procval = vm_make_proc(th, cfp, block);
288
279
 
289
280
    if (is_lambda) {
290
281
        rb_proc_t *proc;
364
355
    GetProcPtr(self, proc);
365
356
 
366
357
    /* ignore self and klass */
367
 
    return th_invoke_proc(GET_THREAD(), proc, proc->block.self,
 
358
    return vm_invoke_proc(GET_THREAD(), proc, proc->block.self,
368
359
                          RARRAY_LEN(args), RARRAY_PTR(args));
369
360
}
370
361
 
408
399
    rb_proc_t *proc;
409
400
    GetProcPtr(procval, proc);
410
401
 
411
 
    return th_invoke_proc(GET_THREAD(), proc, proc->block.self, argc, argv);
 
402
    return vm_invoke_proc(GET_THREAD(), proc, proc->block.self, argc, argv);
412
403
}
413
404
 
414
405
static VALUE
416
407
{
417
408
    rb_proc_t *proc;
418
409
    GetProcPtr(procval, proc);
419
 
    return th_invoke_proc(GET_THREAD(), proc, proc->block.self, argc, argv);
 
410
    return vm_invoke_proc(GET_THREAD(), proc, proc->block.self, argc, argv);
420
411
}
421
412
 
422
413
VALUE
542
533
    rb_proc_t *proc;
543
534
    char *cname = rb_obj_classname(self);
544
535
    rb_iseq_t *iseq;
 
536
    const char *is_lambda;
545
537
    
546
538
    GetProcPtr(self, proc);
547
539
    iseq = proc->block.iseq;
 
540
    is_lambda = proc->is_lambda ? " (lambda)" : "";
548
541
 
549
542
    if (RUBY_VM_NORMAL_ISEQ_P(iseq)) {
550
543
        int line_no = 0;
551
544
        
552
 
        if (iseq->insn_info_tbl) {
553
 
            line_no = iseq->insn_info_tbl[0].line_no;
 
545
        if (iseq->insn_info_table) {
 
546
            line_no = iseq->insn_info_table[0].line_no;
554
547
        }
555
 
        str = rb_sprintf("#<%s:%lx@%s:%d>", cname, self,
 
548
        str = rb_sprintf("#<%s:%p@%s:%d%s>", cname, (void *)self,
556
549
                         RSTRING_PTR(iseq->filename),
557
 
                         line_no);
 
550
                         line_no, is_lambda);
558
551
    }
559
552
    else {
560
 
        str = rb_sprintf("#<%s:%p>", cname, proc->block.iseq);
 
553
        str = rb_sprintf("#<%s:%p%s>", cname, proc->block.iseq,
 
554
                         is_lambda);
561
555
    }
562
556
 
563
557
    if (OBJ_TAINTED(self)) {
963
957
            proc->block.iseq->defined_method_id = id;
964
958
            proc->block.iseq->klass = mod;
965
959
            proc->is_lambda = Qtrue;
 
960
            proc->is_from_method = Qtrue;
966
961
        }
967
962
        node = NEW_BMETHOD(body);
968
963
    }
1031
1026
    }
1032
1027
    if ((state = EXEC_TAG()) == 0) {
1033
1028
        PASS_PASSED_BLOCK();
1034
 
        result = th_call0(GET_THREAD(),
 
1029
        result = vm_call0(GET_THREAD(),
1035
1030
                          data->klass, data->recv, data->id, data->oid,
1036
1031
                          argc, argv, data->body, 0);
1037
1032
    }
1162
1157
int
1163
1158
rb_node_arity(NODE* body)
1164
1159
{
1165
 
    int n;
1166
 
 
1167
1160
    switch (nd_type(body)) {
1168
 
    case NODE_CFUNC:
 
1161
      case NODE_CFUNC:
1169
1162
        if (body->nd_argc < 0)
1170
1163
            return -1;
1171
1164
        return body->nd_argc;
1172
 
    case NODE_ZSUPER:
 
1165
      case NODE_ZSUPER:
1173
1166
        return -1;
1174
 
    case NODE_ATTRSET:
 
1167
      case NODE_ATTRSET:
1175
1168
        return 1;
1176
 
    case NODE_IVAR:
 
1169
      case NODE_IVAR:
1177
1170
        return 0;
1178
 
    case NODE_BMETHOD:
 
1171
      case NODE_BMETHOD:
1179
1172
        return rb_proc_arity(body->nd_cval);
1180
 
    case RUBY_VM_METHOD_NODE:{
 
1173
      case RUBY_VM_METHOD_NODE:
 
1174
        {
1181
1175
            rb_iseq_t *iseq;
1182
1176
            GetISeqPtr((VALUE)body->nd_body, iseq);
1183
1177
            if (iseq->arg_rest == -1 && iseq->arg_opts == 0) {
1187
1181
                return -(iseq->argc + 1 + iseq->arg_post_len);
1188
1182
            }
1189
1183
        }
1190
 
    default:
 
1184
      default:
1191
1185
        rb_raise(rb_eArgError, "invalid node 0x%x", nd_type(body));
1192
1186
    }
1193
1187
}
1318
1312
}
1319
1313
 
1320
1314
static VALUE
 
1315
mlambda(VALUE method)
 
1316
{
 
1317
    return rb_funcall(Qnil, rb_intern("lambda"), 0);
 
1318
}
 
1319
 
 
1320
static VALUE
1321
1321
bmcall(VALUE args, VALUE method)
1322
1322
{
1323
1323
    volatile VALUE a;
 
1324
 
1324
1325
    if (CLASS_OF(args) != rb_cArray) {
1325
1326
        args = rb_ary_new3(1, args);
1326
1327
    }
1351
1352
static VALUE
1352
1353
method_proc(VALUE method)
1353
1354
{
1354
 
    VALUE proc;
 
1355
    VALUE procval;
 
1356
    rb_proc_t *proc;
1355
1357
    /*
1356
1358
     * class Method
1357
1359
     *   def to_proc
1361
1363
     *   end
1362
1364
     * end
1363
1365
     */
1364
 
    proc = rb_iterate((VALUE (*)(VALUE))mproc, 0, bmcall, method);
1365
 
    return proc;
 
1366
    procval = rb_iterate((VALUE (*)(VALUE))mlambda, 0, bmcall, method);
 
1367
    GetProcPtr(procval, proc);
 
1368
    proc->is_from_method = 1;
 
1369
    return procval;
1366
1370
}
1367
1371
 
1368
1372
static VALUE
1443
1447
    rb_eLocalJumpError = rb_define_class("LocalJumpError", rb_eStandardError);
1444
1448
    rb_define_method(rb_eLocalJumpError, "exit_value", localjump_xvalue, 0);
1445
1449
    rb_define_method(rb_eLocalJumpError, "reason", localjump_reason, 0);
1446
 
    exception_error = rb_exc_new2(rb_eFatal, "exception reentered");
1447
 
    rb_register_mark_object(exception_error);
1448
1450
 
1449
1451
    rb_eSysStackError = rb_define_class("SystemStackError", rb_eException);
1450
1452
    sysstack_error = rb_exc_new2(rb_eSysStackError, "stack level too deep");