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

« back to all changes in this revision

Viewing changes to eval_load.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:
4
4
 
5
5
#include "eval_intern.h"
6
6
 
7
 
extern VALUE ruby_top_self;
8
 
 
9
7
VALUE ruby_dln_librefs;
10
8
 
11
9
#define IS_SOEXT(e) (strcmp(e, ".so") == 0 || strcmp(e, ".o") == 0)
130
128
 
131
129
NORETURN(static void load_failed _((VALUE)));
132
130
 
133
 
RUBY_EXTERN NODE *ruby_eval_tree;
134
 
 
135
 
static VALUE
136
 
rb_load_internal(char *file)
137
 
{
138
 
    NODE *node;
139
 
    VALUE iseq;
140
 
    rb_thread_t *th = GET_THREAD();
141
 
 
142
 
    {
143
 
        th->parse_in_eval++;
144
 
        node = (NODE *)rb_load_file(file);
145
 
        th->parse_in_eval--;
146
 
        node = ruby_eval_tree;
147
 
    }
148
 
 
149
 
    if (ruby_nerrs > 0) {
150
 
        return 0;
151
 
    }
152
 
 
153
 
    iseq = rb_iseq_new(node, rb_str_new2("<top (required)>"),
154
 
                       rb_str_new2(file), Qfalse, ISEQ_TYPE_TOP);
155
 
 
156
 
    rb_thread_eval(GET_THREAD(), iseq);
157
 
    return 0;
158
 
}
159
 
 
160
131
void
161
132
rb_load(VALUE fname, int wrap)
162
133
{
165
136
    rb_thread_t *th = GET_THREAD();
166
137
    VALUE wrapper = th->top_wrapper;
167
138
    VALUE self = th->top_self;
 
139
    volatile int parse_in_eval;
 
140
    volatile int loaded = Qfalse;
168
141
 
169
142
    FilePathValue(fname);
170
143
    fname = rb_str_new4(fname);
172
145
    if (!tmp) {
173
146
        load_failed(fname);
174
147
    }
175
 
    fname = tmp;
 
148
    RB_GC_GUARD(fname) = rb_str_new4(tmp);
176
149
 
177
150
    th->errinfo = Qnil; /* ensure */
178
151
 
182
155
    }
183
156
    else {
184
157
        /* load in anonymous module as toplevel */
185
 
        th->top_self = rb_obj_clone(ruby_top_self);
 
158
        th->top_self = rb_obj_clone(rb_vm_top_self());
186
159
        th->top_wrapper = rb_module_new();
187
160
        rb_extend_object(th->top_self, th->top_wrapper);
188
161
    }
189
162
 
 
163
    parse_in_eval = th->parse_in_eval;
190
164
    PUSH_TAG();
191
165
    state = EXEC_TAG();
192
166
    if (state == 0) {
193
 
        rb_load_internal(RSTRING_PTR(fname));
 
167
        NODE *node;
 
168
        VALUE iseq;
 
169
 
 
170
        th->parse_in_eval++;
 
171
        node = (NODE *)rb_load_file(RSTRING_PTR(fname));
 
172
        th->parse_in_eval--;
 
173
        loaded = Qtrue;
 
174
        iseq = rb_iseq_new(node, rb_str_new2("<top (required)>"),
 
175
                           fname, Qfalse, ISEQ_TYPE_TOP);
 
176
        rb_iseq_eval(iseq);
194
177
    }
195
178
    POP_TAG();
196
179
 
 
180
    th->parse_in_eval = parse_in_eval;
197
181
    th->top_self = self;
198
182
    th->top_wrapper = wrapper;
199
183
 
200
 
    if (ruby_nerrs > 0) {
201
 
        ruby_nerrs = 0;
 
184
    if (!loaded) {
202
185
        rb_exc_raise(GET_THREAD()->errinfo);
203
186
    }
204
187
    if (state) {
205
 
        th_jump_tag_but_local_jump(state, Qundef);
 
188
        vm_jump_tag_but_local_jump(state, Qundef);
206
189
    }
207
190
 
208
191
    if (!NIL_P(GET_THREAD()->errinfo)) {
318
301
}
319
302
 
320
303
static int
321
 
search_required(VALUE fname, VALUE *path)
 
304
search_required(VALUE fname, volatile VALUE *path)
322
305
{
323
306
    VALUE tmp;
324
307
    char *ext, *ftptr;
330
313
        if (strcmp(".rb", ext) == 0) {
331
314
            if (rb_feature_p(ftptr, ext, Qtrue))
332
315
                return 'r';
333
 
            if (tmp = rb_find_file(fname)) {
 
316
            if ((tmp = rb_find_file(fname)) != 0) {
334
317
                tmp = rb_file_expand_path(tmp, Qnil);
335
318
                ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
336
319
                if (!rb_feature_p(ftptr, ext, Qtrue))
355
338
#else
356
339
            rb_str_cat2(tmp, DLEXT);
357
340
            OBJ_FREEZE(tmp);
358
 
            if (tmp = rb_find_file(tmp)) {
 
341
            if ((tmp = rb_find_file(tmp)) != 0) {
359
342
                tmp = rb_file_expand_path(tmp, Qnil);
360
343
                ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
361
344
                if (!rb_feature_p(ftptr, ext, Qfalse))
367
350
        else if (IS_DLEXT(ext)) {
368
351
            if (rb_feature_p(ftptr, ext, Qfalse))
369
352
                return 's';
370
 
            if (tmp = rb_find_file(fname)) {
 
353
            if ((tmp = rb_find_file(fname)) != 0) {
371
354
                tmp = rb_file_expand_path(tmp, Qnil);
372
355
                ext = strrchr(ftptr = RSTRING_PTR(tmp), '.');
373
356
                if (!rb_feature_p(ftptr, ext, Qfalse))
408
391
             RSTRING_PTR(fname));
409
392
}
410
393
 
 
394
static VALUE
 
395
load_ext(VALUE path)
 
396
{
 
397
    SCOPE_SET(NOEX_PUBLIC);
 
398
    return (VALUE)dln_load(RSTRING_PTR(path));
 
399
}
 
400
 
411
401
VALUE
412
402
rb_require_safe(VALUE fname, int safe)
413
403
{
416
406
    volatile VALUE errinfo = th->errinfo;
417
407
    int state;
418
408
    struct {
419
 
        NODE *node;
420
409
        int safe;
421
410
    } volatile saved;
422
411
    char *volatile ftptr = 0;
423
412
 
424
413
    PUSH_TAG();
425
 
    saved.node = ruby_current_node;
426
414
    saved.safe = rb_safe_level();
427
415
    if ((state = EXEC_TAG()) == 0) {
428
416
        VALUE path;
445
433
                    break;
446
434
 
447
435
                  case 's':
448
 
                    ruby_current_node = 0;
449
 
                    ruby_sourcefile = rb_source_filename(RSTRING_PTR(path));
450
 
                    ruby_sourceline = 0;
451
 
                    /* SCOPE_SET(NOEX_PUBLIC); */
452
 
                    handle = (long)dln_load(RSTRING_PTR(path));
 
436
                    handle = (long)rb_vm_call_cfunc(rb_vm_top_self(), load_ext,
 
437
                                                    path, 0, path);
453
438
                    rb_ary_push(ruby_dln_librefs, LONG2NUM(handle));
454
439
                    break;
455
440
                }
461
446
    POP_TAG();
462
447
    load_unlock(ftptr);
463
448
 
464
 
    ruby_current_node = saved.node;
465
449
    rb_set_safe_level_force(saved.safe);
466
450
    if (state) {
467
451
        JUMP_TAG(state);
484
468
    return rb_require_safe(fn, rb_safe_level());
485
469
}
486
470
 
 
471
static VALUE
 
472
init_ext_call(VALUE arg)
 
473
{
 
474
    SCOPE_SET(NOEX_PUBLIC);
 
475
    (*(void (*)(void))arg)();
 
476
    return Qnil;
 
477
}
 
478
 
487
479
void
488
480
ruby_init_ext(const char *name, void (*init)(void))
489
481
{
490
 
    rb_control_frame_t *frame = GET_THREAD()->cfp;
491
 
 
492
 
    ruby_current_node = 0;
493
 
    ruby_sourcefile = rb_source_filename(name);
494
 
    ruby_sourceline = 0;
495
 
    frame->method_id = 0;
496
 
    SCOPE_SET(NOEX_PUBLIC);
497
482
    if (load_lock(name)) {
498
 
        (*init)();
 
483
        rb_vm_call_cfunc(rb_vm_top_self(), init_ext_call, (VALUE)init,
 
484
                         0, rb_str_new2(name));
499
485
        rb_provide(name);
500
486
        load_unlock(name);
501
487
    }
574
560
void
575
561
Init_load()
576
562
{
577
 
    rb_load_path = rb_ary_new();
578
563
    rb_define_readonly_variable("$:", &rb_load_path);
579
564
    rb_define_readonly_variable("$-I", &rb_load_path);
580
565
    rb_define_readonly_variable("$LOAD_PATH", &rb_load_path);
 
566
    rb_load_path = rb_ary_new();
581
567
 
582
568
    rb_define_virtual_variable("$\"", get_loaded_features, 0);
583
569
    rb_define_virtual_variable("$LOADED_FEATURES", get_loaded_features, 0);