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

« back to all changes in this revision

Viewing changes to ruby.h

  • 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:
1
 
/**********************************************************************
2
 
 
3
 
  ruby.h -
4
 
 
5
 
  $Author: nobu $
6
 
  created at: Thu Jun 10 14:26:32 JST 1993
7
 
 
8
 
  Copyright (C) 1993-2003 Yukihiro Matsumoto
9
 
  Copyright (C) 2000  Network Applied Communication Laboratory, Inc.
10
 
  Copyright (C) 2000  Information-technology Promotion Agency, Japan
11
 
 
12
 
**********************************************************************/
13
 
 
14
 
#ifndef RUBY_H
15
 
#define RUBY_H
16
 
 
17
 
#if defined(__cplusplus)
18
 
extern "C" {
19
 
#if 0
20
 
} /* satisfy cc-mode */
21
 
#endif
22
 
#endif
23
 
 
24
 
#include "config.h"
25
 
#ifdef RUBY_EXTCONF_H
26
 
#include RUBY_EXTCONF_H
27
 
#endif
28
 
 
29
 
#define NORETURN_STYLE_NEW 1
30
 
#ifndef NORETURN
31
 
# define NORETURN(x) x
32
 
#endif
33
 
#ifndef DEPRECATED
34
 
# define DEPRECATED(x) x
35
 
#endif
36
 
#ifndef NOINLINE
37
 
# define NOINLINE(x) x
38
 
#endif
39
 
 
40
 
#ifdef __GNUC__
41
 
#define PRINTF_ARGS(decl, string_index, first_to_check) \
42
 
  decl __attribute__((format(printf, string_index, first_to_check)))
43
 
#else
44
 
#define PRINTF_ARGS(decl, string_index, first_to_check) decl
45
 
#endif
46
 
 
47
 
#ifdef HAVE_STDLIB_H
48
 
# include <stdlib.h>
49
 
#endif
50
 
 
51
 
#ifdef HAVE_STRING_H
52
 
# include <string.h>
53
 
#else
54
 
# include <strings.h>
55
 
#endif
56
 
 
57
 
#ifdef HAVE_INTRINSICS_H
58
 
# include <intrinsics.h>
59
 
#endif
60
 
 
61
 
#include <stddef.h>
62
 
#include <stdio.h>
63
 
 
64
 
#include "defines.h"
65
 
 
66
 
/* need to include <ctype.h> to use these macros */
67
 
#ifndef ISPRINT
68
 
#define ISASCII(c) isascii((int)(unsigned char)(c))
69
 
#undef ISPRINT
70
 
#define ISPRINT(c) (ISASCII(c) && isprint((int)(unsigned char)(c)))
71
 
#define ISSPACE(c) (ISASCII(c) && isspace((int)(unsigned char)(c)))
72
 
#define ISUPPER(c) (ISASCII(c) && isupper((int)(unsigned char)(c)))
73
 
#define ISLOWER(c) (ISASCII(c) && islower((int)(unsigned char)(c)))
74
 
#define ISALNUM(c) (ISASCII(c) && isalnum((int)(unsigned char)(c)))
75
 
#define ISALPHA(c) (ISASCII(c) && isalpha((int)(unsigned char)(c)))
76
 
#define ISDIGIT(c) (ISASCII(c) && isdigit((int)(unsigned char)(c)))
77
 
#define ISXDIGIT(c) (ISASCII(c) && isxdigit((int)(unsigned char)(c)))
78
 
#endif
79
 
 
80
 
#if defined(HAVE_ALLOCA_H)
81
 
#include <alloca.h>
82
 
#else
83
 
#  ifdef _AIX
84
 
#pragma alloca
85
 
#  endif
86
 
#endif
87
 
 
88
 
#if defined(__VMS)
89
 
# pragma builtins
90
 
# define alloca __alloca
91
 
#endif
92
 
 
93
 
#if SIZEOF_LONG == SIZEOF_VOIDP
94
 
typedef unsigned long VALUE;
95
 
typedef unsigned long ID;
96
 
# define SIGNED_VALUE long
97
 
# define SIZEOF_VALUE SIZEOF_LONG
98
 
#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP
99
 
typedef unsigned LONG_LONG VALUE;
100
 
typedef unsigned LONG_LONG ID;
101
 
# define SIGNED_VALUE LONG_LONG
102
 
# define LONG_LONG_VALUE 1
103
 
# define SIZEOF_VALUE SIZEOF_LONG_LONG
104
 
#else
105
 
# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<----
106
 
#endif
107
 
 
108
 
 
109
 
#ifdef __STDC__
110
 
# include <limits.h>
111
 
#else
112
 
# ifndef LONG_MAX
113
 
#  ifdef HAVE_LIMITS_H
114
 
#   include <limits.h>
115
 
#  else
116
 
    /* assuming 32bit(2's compliment) long */
117
 
#   define LONG_MAX 2147483647
118
 
#  endif
119
 
# endif
120
 
# ifndef LONG_MIN
121
 
#  define LONG_MIN (-LONG_MAX-1)
122
 
# endif
123
 
# ifndef CHAR_BIT
124
 
#  define CHAR_BIT 8
125
 
# endif
126
 
#endif
127
 
 
128
 
#ifdef HAVE_LONG_LONG
129
 
# ifndef LLONG_MAX
130
 
#  ifdef LONG_LONG_MAX
131
 
#   define LLONG_MAX  LONG_LONG_MAX
132
 
#  else
133
 
#   ifdef _I64_MAX
134
 
#    define LLONG_MAX _I64_MAX
135
 
#   else
136
 
    /* assuming 64bit(2's complement) long long */
137
 
#    define LLONG_MAX 9223372036854775807LL
138
 
#   endif
139
 
#  endif
140
 
# endif
141
 
# ifndef LLONG_MIN
142
 
#  ifdef LONG_LONG_MIN
143
 
#   define LLONG_MIN  LONG_LONG_MIN
144
 
#  else
145
 
#   ifdef _I64_MIN
146
 
#    define LLONG_MIN _I64_MIN
147
 
#   else
148
 
#    define LLONG_MIN (-LLONG_MAX-1)
149
 
#   endif
150
 
#  endif
151
 
# endif
152
 
#endif
153
 
 
154
 
#ifdef LONG_LONG_VALUE
155
 
# define FIXNUM_MAX (LLONG_MAX>>1)
156
 
# define FIXNUM_MIN RSHIFT((LONG_LONG)LLONG_MIN,1)
157
 
#else
158
 
# define FIXNUM_MAX (LONG_MAX>>1)
159
 
# define FIXNUM_MIN RSHIFT((long)LONG_MIN,1)
160
 
#endif
161
 
 
162
 
#define FIXNUM_FLAG 0x01
163
 
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
164
 
#define LONG2FIX(i) INT2FIX(i)
165
 
#define rb_fix_new(v) INT2FIX(v)
166
 
VALUE rb_int2inum(SIGNED_VALUE);
167
 
#define INT2NUM(v) rb_int2inum(v)
168
 
#define LONG2NUM(v) INT2NUM(v)
169
 
#define rb_int_new(v) rb_int2inum(v)
170
 
VALUE rb_uint2inum(VALUE);
171
 
#define UINT2NUM(v) rb_uint2inum(v)
172
 
#define ULONG2NUM(v) UINT2NUM(v)
173
 
#define rb_uint_new(v) rb_uint2inum(v)
174
 
 
175
 
#ifdef HAVE_LONG_LONG
176
 
VALUE rb_ll2inum(LONG_LONG);
177
 
#define LL2NUM(v) rb_ll2inum(v)
178
 
VALUE rb_ull2inum(unsigned LONG_LONG);
179
 
#define ULL2NUM(v) rb_ull2inum(v)
180
 
#endif
181
 
 
182
 
#if SIZEOF_OFF_T > SIZEOF_LONG && defined(HAVE_LONG_LONG)
183
 
# define OFFT2NUM(v) LL2NUM(v)
184
 
#elif SIZEOF_OFF_T == SIZEOF_LONG
185
 
# define OFFT2NUM(v) LONG2NUM(v)
186
 
#else
187
 
# define OFFT2NUM(v) INT2NUM(v)
188
 
#endif
189
 
 
190
 
#ifndef PIDT2NUM
191
 
#define PIDT2NUM(v) LONG2NUM(v)
192
 
#endif
193
 
#ifndef NUM2PIDT
194
 
#define NUM2PIDT(v) NUM2LONG(v)
195
 
#endif
196
 
#ifndef UIDT2NUM
197
 
#define UIDT2NUM(v) LONG2NUM(v)
198
 
#endif
199
 
#ifndef NUM2UIDT
200
 
#define NUM2UIDT(v) NUM2LONG(v)
201
 
#endif
202
 
#ifndef GIDT2NUM
203
 
#define GIDT2NUM(v) LONG2NUM(v)
204
 
#endif
205
 
#ifndef NUM2GIDT
206
 
#define NUM2GIDT(v) NUM2LONG(v)
207
 
#endif
208
 
 
209
 
#define FIX2LONG(x) RSHIFT((SIGNED_VALUE)x,1)
210
 
#define FIX2ULONG(x) (((VALUE)(x))>>1)
211
 
#define FIXNUM_P(f) (((SIGNED_VALUE)(f))&FIXNUM_FLAG)
212
 
#define POSFIXABLE(f) ((f) <= FIXNUM_MAX)
213
 
#define NEGFIXABLE(f) ((f) >= FIXNUM_MIN)
214
 
#define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f))
215
 
 
216
 
#define IMMEDIATE_MASK 0x03
217
 
#define IMMEDIATE_P(x) ((VALUE)(x) & IMMEDIATE_MASK)
218
 
 
219
 
#define SYMBOL_FLAG 0x0e
220
 
#define SYMBOL_P(x) (((VALUE)(x)&0xff)==SYMBOL_FLAG)
221
 
#define ID2SYM(x) ((VALUE)(((long)(x))<<8|SYMBOL_FLAG))
222
 
#define SYM2ID(x) RSHIFT((unsigned long)x,8)
223
 
 
224
 
/* special contants - i.e. non-zero and non-fixnum constants */
225
 
#define Qfalse ((VALUE)0)
226
 
#define Qtrue  ((VALUE)2)
227
 
#define Qnil   ((VALUE)4)
228
 
#define Qundef ((VALUE)6)       /* undefined value for placeholder */
229
 
 
230
 
#define RTEST(v) (((VALUE)(v) & ~Qnil) != 0)
231
 
#define NIL_P(v) ((VALUE)(v) == Qnil)
232
 
 
233
 
#define CLASS_OF(v) rb_class_of((VALUE)(v))
234
 
 
235
 
#define T_NONE   0x00
236
 
 
237
 
#define T_NIL    0x01
238
 
#define T_OBJECT 0x02
239
 
#define T_CLASS  0x03
240
 
#define T_ICLASS 0x04
241
 
#define T_MODULE 0x05
242
 
#define T_FLOAT  0x06
243
 
#define T_STRING 0x07
244
 
#define T_REGEXP 0x08
245
 
#define T_ARRAY  0x09
246
 
#define T_FIXNUM 0x0a
247
 
#define T_HASH   0x0b
248
 
#define T_STRUCT 0x0c
249
 
#define T_BIGNUM 0x0d
250
 
#define T_FILE   0x0e
251
 
 
252
 
#define T_TRUE   0x10
253
 
#define T_FALSE  0x11
254
 
#define T_DATA   0x12
255
 
#define T_MATCH  0x13
256
 
#define T_SYMBOL 0x14
257
 
 
258
 
#define T_VALUES 0x1a
259
 
#define T_BLOCK  0x1b
260
 
#define T_UNDEF  0x1c
261
 
#define T_NODE   0x1f
262
 
 
263
 
#define T_MASK   0x1f
264
 
 
265
 
#define BUILTIN_TYPE(x) (((struct RBasic*)(x))->flags & T_MASK)
266
 
 
267
 
#define TYPE(x) rb_type((VALUE)(x))
268
 
 
269
 
void rb_check_type(VALUE,int);
270
 
#define Check_Type(v,t) rb_check_type((VALUE)(v),t)
271
 
 
272
 
VALUE rb_str_to_str(VALUE);
273
 
VALUE rb_string_value(volatile VALUE*);
274
 
char *rb_string_value_ptr(volatile VALUE*);
275
 
char *rb_string_value_cstr(volatile VALUE*);
276
 
 
277
 
#define StringValue(v) rb_string_value(&(v))
278
 
#define StringValuePtr(v) rb_string_value_ptr(&(v))
279
 
#define StringValueCStr(v) rb_string_value_cstr(&(v))
280
 
 
281
 
void rb_check_safe_obj(VALUE);
282
 
void rb_check_safe_str(VALUE);
283
 
#define SafeStringValue(v) do {\
284
 
    StringValue(v);\
285
 
    rb_check_safe_obj(v);\
286
 
} while (0)
287
 
/* obsolete macro - use SafeStringValue(v) */
288
 
#define Check_SafeStr(v) rb_check_safe_str((VALUE)(v))
289
 
 
290
 
VALUE rb_get_path(VALUE);
291
 
#define FilePathValue(v) ((v) = rb_get_path(v))
292
 
 
293
 
void rb_secure(int);
294
 
int rb_safe_level(void);
295
 
void rb_set_safe_level(int);
296
 
void rb_set_safe_level_force(int);
297
 
void rb_secure_update(VALUE);
298
 
 
299
 
VALUE rb_errinfo(void);
300
 
void rb_set_errinfo(VALUE);
301
 
 
302
 
SIGNED_VALUE rb_num2long(VALUE);
303
 
VALUE rb_num2ulong(VALUE);
304
 
#define NUM2LONG(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2long((VALUE)x))
305
 
#define NUM2ULONG(x) rb_num2ulong((VALUE)x)
306
 
#if SIZEOF_INT < SIZEOF_LONG
307
 
long rb_num2int(VALUE);
308
 
#define NUM2INT(x) (FIXNUM_P(x)?FIX2INT(x):rb_num2int((VALUE)x))
309
 
long rb_fix2int(VALUE);
310
 
#define FIX2INT(x) rb_fix2int((VALUE)x)
311
 
unsigned long rb_num2uint(VALUE);
312
 
#define NUM2UINT(x) rb_num2uint(x)
313
 
unsigned long rb_fix2uint(VALUE);
314
 
#define FIX2UINT(x) rb_fix2uint(x)
315
 
#else
316
 
#define NUM2INT(x) ((int)NUM2LONG(x))
317
 
#define NUM2UINT(x) ((unsigned int)NUM2ULONG(x))
318
 
#define FIX2INT(x) ((int)FIX2LONG(x))
319
 
#define FIX2UINT(x) ((unsigned int)FIX2ULONG(x))
320
 
#endif
321
 
 
322
 
#ifdef HAVE_LONG_LONG
323
 
LONG_LONG rb_num2ll(VALUE);
324
 
unsigned LONG_LONG rb_num2ull(VALUE);
325
 
# define NUM2LL(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2ll((VALUE)x))
326
 
# define NUM2ULL(x) rb_num2ull((VALUE)x)
327
 
#endif
328
 
 
329
 
#if defined(HAVE_LONG_LONG) && SIZEOF_OFF_T > SIZEOF_LONG
330
 
# define NUM2OFFT(x) ((off_t)NUM2LL(x))
331
 
#else
332
 
# define NUM2OFFT(x) NUM2LONG(x)
333
 
#endif
334
 
 
335
 
double rb_num2dbl(VALUE);
336
 
#define NUM2DBL(x) rb_num2dbl((VALUE)(x))
337
 
 
338
 
/* obsolete API - use StringValue() */
339
 
char *rb_str2cstr(VALUE,long*);
340
 
/* obsolete API - use StringValuePtr() */
341
 
#define STR2CSTR(x) rb_str2cstr((VALUE)(x),0)
342
 
 
343
 
#define NUM2CHR(x) (((TYPE(x) == T_STRING)&&(RSTRING_LEN(x)>=1))?\
344
 
                     RSTRING_PTR(x)[0]:(char)(NUM2INT(x)&0xff))
345
 
#define CHR2FIX(x) INT2FIX((long)((x)&0xff))
346
 
 
347
 
VALUE rb_newobj(void);
348
 
#define NEWOBJ(obj,type) type *obj = (type*)rb_newobj()
349
 
#define OBJSETUP(obj,c,t) do {\
350
 
    RBASIC(obj)->flags = (t);\
351
 
    RBASIC(obj)->klass = (c);\
352
 
    if (rb_safe_level() >= 3) FL_SET(obj, FL_TAINT);\
353
 
} while (0)
354
 
#define CLONESETUP(clone,obj) do {\
355
 
    OBJSETUP(clone,rb_singleton_class_clone((VALUE)obj),RBASIC(obj)->flags);\
356
 
    rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);\
357
 
    if (FL_TEST(obj, FL_EXIVAR)) rb_copy_generic_ivar((VALUE)clone,(VALUE)obj);\
358
 
} while (0)
359
 
#define DUPSETUP(dup,obj) do {\
360
 
    OBJSETUP(dup,rb_obj_class(obj),(RBASIC(obj)->flags)&(T_MASK|FL_EXIVAR|FL_TAINT));\
361
 
    if (FL_TEST(obj, FL_EXIVAR)) rb_copy_generic_ivar((VALUE)dup,(VALUE)obj);\
362
 
} while (0)
363
 
 
364
 
struct RBasic {
365
 
    VALUE flags;
366
 
    VALUE klass;
367
 
};
368
 
 
369
 
struct RObject {
370
 
    struct RBasic basic;
371
 
    struct st_table *iv_tbl;
372
 
};
373
 
 
374
 
struct RValues {
375
 
    struct RBasic basic;
376
 
    VALUE v1;
377
 
    VALUE v2;
378
 
    VALUE v3;
379
 
};
380
 
 
381
 
struct RClass {
382
 
    struct RBasic basic;
383
 
    struct st_table *iv_tbl;
384
 
    struct st_table *m_tbl;
385
 
    VALUE super;
386
 
};
387
 
 
388
 
struct RFloat {
389
 
    struct RBasic basic;
390
 
    double value;
391
 
};
392
 
 
393
 
#define ELTS_SHARED FL_USER2
394
 
 
395
 
#define RSTRING_EMBED_LEN_MAX ((sizeof(VALUE)*3)/sizeof(char)-1)
396
 
struct RString {
397
 
    struct RBasic basic;
398
 
    union {
399
 
        struct {
400
 
            long len;
401
 
            char *ptr;
402
 
            union {
403
 
                long capa;
404
 
                VALUE shared;
405
 
            } aux;
406
 
        } heap;
407
 
        char ary[RSTRING_EMBED_LEN_MAX];
408
 
    } as;
409
 
};
410
 
#define RSTRING_NOEMBED FL_USER1
411
 
#define RSTRING_EMBED_LEN_MASK (FL_USER2|FL_USER3|FL_USER4|FL_USER5|FL_USER6)
412
 
#define RSTRING_EMBED_LEN_SHIFT (FL_USHIFT+2)
413
 
#define RSTRING_LEN(str) \
414
 
    (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
415
 
     (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \
416
 
            (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT)) : \
417
 
     RSTRING(str)->as.heap.len)
418
 
#define RSTRING_PTR(str) \
419
 
    (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \
420
 
     RSTRING(str)->as.ary : \
421
 
     RSTRING(str)->as.heap.ptr)
422
 
 
423
 
struct RArray {
424
 
    struct RBasic basic;
425
 
    long len;
426
 
    union {
427
 
        long capa;
428
 
        VALUE shared;
429
 
    } aux;
430
 
    VALUE *ptr;
431
 
};
432
 
#define RARRAY_LEN(a) RARRAY(a)->len
433
 
#define RARRAY_PTR(a) RARRAY(a)->ptr
434
 
 
435
 
struct RRegexp {
436
 
    struct RBasic basic;
437
 
    struct re_pattern_buffer *ptr;
438
 
    long len;
439
 
    char *str;
440
 
};
441
 
 
442
 
struct RHash {
443
 
    struct RBasic basic;
444
 
    struct st_table *tbl;
445
 
    int iter_lev;
446
 
    VALUE ifnone;
447
 
};
448
 
 
449
 
struct RFile {
450
 
    struct RBasic basic;
451
 
    struct rb_io_t *fptr;
452
 
};
453
 
 
454
 
struct RData {
455
 
    struct RBasic basic;
456
 
    void (*dmark)(void*);
457
 
    void (*dfree)(void*);
458
 
    void *data;
459
 
};
460
 
 
461
 
#define DATA_PTR(dta) (RDATA(dta)->data)
462
 
 
463
 
/*
464
 
#define RUBY_DATA_FUNC(func) ((void (*)(void*))func)
465
 
*/
466
 
typedef void (*RUBY_DATA_FUNC)(void*);
467
 
 
468
 
VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC);
469
 
 
470
 
#define Data_Wrap_Struct(klass,mark,free,sval)\
471
 
    rb_data_object_alloc(klass,sval,(RUBY_DATA_FUNC)mark,(RUBY_DATA_FUNC)free)
472
 
 
473
 
#define Data_Make_Struct(klass,type,mark,free,sval) (\
474
 
    sval = ALLOC(type),\
475
 
    memset(sval, 0, sizeof(type)),\
476
 
    Data_Wrap_Struct(klass,mark,free,sval)\
477
 
)
478
 
 
479
 
#define Data_Get_Struct(obj,type,sval) do {\
480
 
    Check_Type(obj, T_DATA); \
481
 
    sval = (type*)DATA_PTR(obj);\
482
 
} while (0)
483
 
 
484
 
#define RSTRUCT_EMBED_LEN_MAX 3
485
 
struct RStruct {
486
 
    struct RBasic basic;
487
 
    union {
488
 
        struct {
489
 
            long len;
490
 
            VALUE *ptr;
491
 
        } heap;
492
 
        VALUE ary[RSTRUCT_EMBED_LEN_MAX];
493
 
    } as;
494
 
};
495
 
#define RSTRUCT_EMBED_LEN_MASK (FL_USER2|FL_USER1)
496
 
#define RSTRUCT_EMBED_LEN_SHIFT (FL_USHIFT+1)
497
 
#define RSTRUCT_LEN(st) \
498
 
    ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
499
 
     (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \
500
 
            (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT)) : \
501
 
     RSTRUCT(st)->as.heap.len)
502
 
#define RSTRUCT_PTR(st) \
503
 
    ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \
504
 
     RSTRUCT(st)->as.ary : \
505
 
     RSTRUCT(st)->as.heap.ptr)
506
 
 
507
 
struct RBignum {
508
 
    struct RBasic basic;
509
 
    char sign;
510
 
    long len;
511
 
    void *digits;
512
 
};
513
 
 
514
 
#define R_CAST(st)   (struct st*)
515
 
#define RBASIC(obj)  (R_CAST(RBasic)(obj))
516
 
#define ROBJECT(obj) (R_CAST(RObject)(obj))
517
 
#define RCLASS(obj)  (R_CAST(RClass)(obj))
518
 
#define RMODULE(obj) RCLASS(obj)
519
 
#define RFLOAT(obj)  (R_CAST(RFloat)(obj))
520
 
#define RSTRING(obj) (R_CAST(RString)(obj))
521
 
#define RREGEXP(obj) (R_CAST(RRegexp)(obj))
522
 
#define RARRAY(obj)  (R_CAST(RArray)(obj))
523
 
#define RHASH(obj)   (R_CAST(RHash)(obj))
524
 
#define RDATA(obj)   (R_CAST(RData)(obj))
525
 
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
526
 
#define RBIGNUM(obj) (R_CAST(RBignum)(obj))
527
 
#define RFILE(obj)   (R_CAST(RFile)(obj))
528
 
#define RVALUES(obj) (R_CAST(RValues)(obj))
529
 
 
530
 
#define FL_SINGLETON FL_USER0
531
 
#define FL_MARK      (1<<5)
532
 
#define FL_RESERVED  (1<<6)     /* will be used in the future GC */
533
 
#define FL_FINALIZE  (1<<7)
534
 
#define FL_TAINT     (1<<8)
535
 
#define FL_EXIVAR    (1<<9)
536
 
#define FL_FREEZE    (1<<10)
537
 
 
538
 
#define FL_USHIFT    11
539
 
 
540
 
#define FL_USER0     (1<<(FL_USHIFT+0))
541
 
#define FL_USER1     (1<<(FL_USHIFT+1))
542
 
#define FL_USER2     (1<<(FL_USHIFT+2))
543
 
#define FL_USER3     (1<<(FL_USHIFT+3))
544
 
#define FL_USER4     (1<<(FL_USHIFT+4))
545
 
#define FL_USER5     (1<<(FL_USHIFT+5))
546
 
#define FL_USER6     (1<<(FL_USHIFT+6))
547
 
#define FL_USER7     (1<<(FL_USHIFT+7))
548
 
 
549
 
#define SPECIAL_CONST_P(x) (IMMEDIATE_P(x) || !RTEST(x))
550
 
 
551
 
#define FL_ABLE(x) (!SPECIAL_CONST_P(x) && BUILTIN_TYPE(x) != T_NODE)
552
 
#define FL_TEST(x,f) (FL_ABLE(x)?(RBASIC(x)->flags&(f)):0)
553
 
#define FL_ANY(x,f) FL_TEST(x,f)
554
 
#define FL_ALL(x,f) (FL_TEST(x,f) == (f))
555
 
#define FL_SET(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags |= (f);} while (0)
556
 
#define FL_UNSET(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags &= ~(f);} while (0)
557
 
#define FL_REVERSE(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags ^= (f);} while (0)
558
 
 
559
 
#define OBJ_TAINTED(x) FL_TEST((x), FL_TAINT)
560
 
#define OBJ_TAINT(x) FL_SET((x), FL_TAINT)
561
 
#define OBJ_INFECT(x,s) do {if (FL_ABLE(x) && FL_ABLE(s)) RBASIC(x)->flags |= RBASIC(s)->flags & FL_TAINT;} while (0)
562
 
 
563
 
#define OBJ_FROZEN(x) FL_TEST((x), FL_FREEZE)
564
 
#define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE)
565
 
 
566
 
#define ALLOC_N(type,n) (type*)xmalloc2((n),sizeof(type))
567
 
#define ALLOC(type) (type*)xmalloc(sizeof(type))
568
 
#define REALLOC_N(var,type,n) (var)=(type*)xrealloc2((char*)(var),(n),sizeof(type))
569
 
 
570
 
#define ALLOCA_N(type,n) (type*)alloca(sizeof(type)*(n))
571
 
 
572
 
#define MEMZERO(p,type,n) memset((p), 0, sizeof(type)*(n))
573
 
#define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(n))
574
 
#define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(n))
575
 
#define MEMCMP(p1,p2,type,n) memcmp((p1), (p2), sizeof(type)*(n))
576
 
 
577
 
void rb_obj_infect(VALUE,VALUE);
578
 
 
579
 
typedef int ruby_glob_func(const char*,VALUE);
580
 
void rb_glob(const char*,void(*)(const char*,VALUE),VALUE);
581
 
int ruby_glob(const char*,int,ruby_glob_func*,VALUE);
582
 
int ruby_brace_expand(const char*,int,ruby_glob_func*,VALUE);
583
 
int ruby_brace_glob(const char*,int,ruby_glob_func*,VALUE);
584
 
 
585
 
VALUE rb_define_class(const char*,VALUE);
586
 
VALUE rb_define_module(const char*);
587
 
VALUE rb_define_class_under(VALUE, const char*, VALUE);
588
 
VALUE rb_define_module_under(VALUE, const char*);
589
 
 
590
 
void rb_include_module(VALUE,VALUE);
591
 
void rb_extend_object(VALUE,VALUE);
592
 
 
593
 
void rb_define_variable(const char*,VALUE*);
594
 
void rb_define_virtual_variable(const char*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
595
 
void rb_define_hooked_variable(const char*,VALUE*,VALUE(*)(ANYARGS),void(*)(ANYARGS));
596
 
void rb_define_readonly_variable(const char*,VALUE*);
597
 
void rb_define_const(VALUE,const char*,VALUE);
598
 
void rb_define_global_const(const char*,VALUE);
599
 
 
600
 
#define RUBY_METHOD_FUNC(func) ((VALUE (*)(ANYARGS))func)
601
 
void rb_define_method(VALUE,const char*,VALUE(*)(ANYARGS),int);
602
 
void rb_define_module_function(VALUE,const char*,VALUE(*)(ANYARGS),int);
603
 
void rb_define_global_function(const char*,VALUE(*)(ANYARGS),int);
604
 
 
605
 
void rb_undef_method(VALUE,const char*);
606
 
void rb_define_alias(VALUE,const char*,const char*);
607
 
void rb_define_attr(VALUE,const char*,int,int);
608
 
 
609
 
void rb_global_variable(VALUE*);
610
 
void rb_register_mark_object(VALUE);
611
 
void rb_gc_register_address(VALUE*);
612
 
void rb_gc_unregister_address(VALUE*);
613
 
 
614
 
ID rb_intern(const char*);
615
 
ID rb_intern2(const char*, long);
616
 
const char *rb_id2name(ID);
617
 
ID rb_to_id(VALUE);
618
 
VALUE rb_id2str(ID);
619
 
 
620
 
char *rb_class2name(VALUE);
621
 
char *rb_obj_classname(VALUE);
622
 
 
623
 
void rb_p(VALUE);
624
 
 
625
 
VALUE rb_eval_string(const char*);
626
 
VALUE rb_eval_string_protect(const char*, int*);
627
 
VALUE rb_eval_string_wrap(const char*, int*);
628
 
VALUE rb_funcall(VALUE, ID, int, ...);
629
 
VALUE rb_funcall2(VALUE, ID, int, const VALUE*);
630
 
VALUE rb_funcall3(VALUE, ID, int, const VALUE*);
631
 
int rb_scan_args(int, const VALUE*, const char*, ...);
632
 
VALUE rb_call_super(int, const VALUE*);
633
 
 
634
 
VALUE rb_gv_set(const char*, VALUE);
635
 
VALUE rb_gv_get(const char*);
636
 
VALUE rb_iv_get(VALUE, const char*);
637
 
VALUE rb_iv_set(VALUE, const char*, VALUE);
638
 
 
639
 
VALUE rb_equal(VALUE,VALUE);
640
 
 
641
 
RUBY_EXTERN VALUE ruby_verbose, ruby_debug;
642
 
 
643
 
PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
644
 
PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2);
645
 
PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2);
646
 
NORETURN(void rb_sys_fail(const char*));
647
 
NORETURN(void rb_iter_break(void));
648
 
NORETURN(void rb_exit(int));
649
 
NORETURN(void rb_notimplement(void));
650
 
 
651
 
/* reports if `-w' specified */
652
 
PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2);
653
 
PRINTF_ARGS(void rb_compile_warning(const char*, ...), 1, 2);
654
 
PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2);
655
 
/* reports always */
656
 
PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2);
657
 
PRINTF_ARGS(void rb_compile_warn(const char*, ...), 1, 2);
658
 
 
659
 
VALUE rb_each(VALUE);
660
 
VALUE rb_yield(VALUE);
661
 
VALUE rb_yield_values(int n, ...);
662
 
VALUE rb_yield_splat(VALUE);
663
 
int rb_block_given_p(void);
664
 
void rb_need_block(void);
665
 
VALUE rb_iterate(VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE);
666
 
VALUE rb_block_call(VALUE,ID,int,VALUE*,VALUE(*)(ANYARGS),VALUE);
667
 
VALUE rb_rescue(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
668
 
VALUE rb_rescue2(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE,...);
669
 
VALUE rb_ensure(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
670
 
VALUE rb_catch(const char*,VALUE(*)(ANYARGS),VALUE);
671
 
NORETURN(void rb_throw(const char*,VALUE));
672
 
 
673
 
VALUE rb_require(const char*);
674
 
 
675
 
#ifdef __ia64
676
 
void ruby_init_stack(VALUE*, void*);
677
 
#define RUBY_INIT_STACK \
678
 
    VALUE variable_in_this_stack_frame; \
679
 
    ruby_init_stack(&variable_in_this_stack_frame, rb_ia64_bsp());
680
 
#else
681
 
void ruby_init_stack(VALUE*);
682
 
#define RUBY_INIT_STACK \
683
 
    VALUE variable_in_this_stack_frame; \
684
 
    ruby_init_stack(&variable_in_this_stack_frame);
685
 
#endif
686
 
void ruby_init(void);
687
 
void ruby_options(int, char**);
688
 
NORETURN(void ruby_run(void));
689
 
 
690
 
RUBY_EXTERN VALUE rb_mKernel;
691
 
RUBY_EXTERN VALUE rb_mComparable;
692
 
RUBY_EXTERN VALUE rb_mEnumerable;
693
 
RUBY_EXTERN VALUE rb_mPrecision;
694
 
RUBY_EXTERN VALUE rb_mErrno;
695
 
RUBY_EXTERN VALUE rb_mFileTest;
696
 
RUBY_EXTERN VALUE rb_mGC;
697
 
RUBY_EXTERN VALUE rb_mMath;
698
 
RUBY_EXTERN VALUE rb_mProcess;
699
 
 
700
 
RUBY_EXTERN VALUE rb_cBasicObject;
701
 
RUBY_EXTERN VALUE rb_cObject;
702
 
RUBY_EXTERN VALUE rb_cArray;
703
 
RUBY_EXTERN VALUE rb_cBignum;
704
 
RUBY_EXTERN VALUE rb_cBinding;
705
 
RUBY_EXTERN VALUE rb_cClass;
706
 
RUBY_EXTERN VALUE rb_cCont;
707
 
RUBY_EXTERN VALUE rb_cDir;
708
 
RUBY_EXTERN VALUE rb_cData;
709
 
RUBY_EXTERN VALUE rb_cFalseClass;
710
 
RUBY_EXTERN VALUE rb_cFile;
711
 
RUBY_EXTERN VALUE rb_cFixnum;
712
 
RUBY_EXTERN VALUE rb_cFloat;
713
 
RUBY_EXTERN VALUE rb_cHash;
714
 
RUBY_EXTERN VALUE rb_cInteger;
715
 
RUBY_EXTERN VALUE rb_cIO;
716
 
RUBY_EXTERN VALUE rb_cMatch;
717
 
RUBY_EXTERN VALUE rb_cMethod;
718
 
RUBY_EXTERN VALUE rb_cModule;
719
 
RUBY_EXTERN VALUE rb_cNameErrorMesg;
720
 
RUBY_EXTERN VALUE rb_cNilClass;
721
 
RUBY_EXTERN VALUE rb_cNumeric;
722
 
RUBY_EXTERN VALUE rb_cProc;
723
 
RUBY_EXTERN VALUE rb_cRange;
724
 
RUBY_EXTERN VALUE rb_cRegexp;
725
 
RUBY_EXTERN VALUE rb_cStat;
726
 
RUBY_EXTERN VALUE rb_cString;
727
 
RUBY_EXTERN VALUE rb_cStruct;
728
 
RUBY_EXTERN VALUE rb_cSymbol;
729
 
RUBY_EXTERN VALUE rb_cThread;
730
 
RUBY_EXTERN VALUE rb_cTime;
731
 
RUBY_EXTERN VALUE rb_cTrueClass;
732
 
RUBY_EXTERN VALUE rb_cUnboundMethod;
733
 
RUBY_EXTERN VALUE rb_cISeq;
734
 
RUBY_EXTERN VALUE rb_cVM;
735
 
RUBY_EXTERN VALUE rb_cEnv;
736
 
 
737
 
RUBY_EXTERN VALUE rb_eException;
738
 
RUBY_EXTERN VALUE rb_eStandardError;
739
 
RUBY_EXTERN VALUE rb_eSystemExit;
740
 
RUBY_EXTERN VALUE rb_eInterrupt;
741
 
RUBY_EXTERN VALUE rb_eSignal;
742
 
RUBY_EXTERN VALUE rb_eFatal;
743
 
RUBY_EXTERN VALUE rb_eArgError;
744
 
RUBY_EXTERN VALUE rb_eEOFError;
745
 
RUBY_EXTERN VALUE rb_eIndexError;
746
 
RUBY_EXTERN VALUE rb_eKeyError;
747
 
RUBY_EXTERN VALUE rb_eRangeError;
748
 
RUBY_EXTERN VALUE rb_eIOError;
749
 
RUBY_EXTERN VALUE rb_eRuntimeError;
750
 
RUBY_EXTERN VALUE rb_eSecurityError;
751
 
RUBY_EXTERN VALUE rb_eSystemCallError;
752
 
RUBY_EXTERN VALUE rb_eThreadError;
753
 
RUBY_EXTERN VALUE rb_eTypeError;
754
 
RUBY_EXTERN VALUE rb_eZeroDivError;
755
 
RUBY_EXTERN VALUE rb_eNotImpError;
756
 
RUBY_EXTERN VALUE rb_eNoMemError;
757
 
RUBY_EXTERN VALUE rb_eNoMethodError;
758
 
RUBY_EXTERN VALUE rb_eFloatDomainError;
759
 
RUBY_EXTERN VALUE rb_eLocalJumpError;
760
 
RUBY_EXTERN VALUE rb_eSysStackError;
761
 
RUBY_EXTERN VALUE rb_eRegexpError;
762
 
 
763
 
RUBY_EXTERN VALUE rb_eScriptError;
764
 
RUBY_EXTERN VALUE rb_eNameError;
765
 
RUBY_EXTERN VALUE rb_eSyntaxError;
766
 
RUBY_EXTERN VALUE rb_eLoadError;
767
 
 
768
 
RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr;
769
 
 
770
 
static inline VALUE
771
 
rb_class_of(VALUE obj)
772
 
{
773
 
    if (IMMEDIATE_P(obj)) {
774
 
        if (FIXNUM_P(obj)) return rb_cFixnum;
775
 
        if (obj == Qtrue)  return rb_cTrueClass;
776
 
        if (SYMBOL_P(obj)) return rb_cSymbol;
777
 
    }
778
 
    else if (!RTEST(obj)) {
779
 
        if (obj == Qnil)   return rb_cNilClass;
780
 
        if (obj == Qfalse) return rb_cFalseClass;
781
 
    }
782
 
    return RBASIC(obj)->klass;
783
 
}
784
 
 
785
 
static inline int
786
 
rb_type(VALUE obj)
787
 
{
788
 
    if (IMMEDIATE_P(obj)) {
789
 
        if (FIXNUM_P(obj)) return T_FIXNUM;
790
 
        if (obj == Qtrue) return T_TRUE;
791
 
        if (SYMBOL_P(obj)) return T_SYMBOL;
792
 
        if (obj == Qundef) return T_UNDEF;
793
 
    }
794
 
    else if (!RTEST(obj)) {
795
 
        if (obj == Qnil) return T_NIL;
796
 
        if (obj == Qfalse) return T_FALSE;
797
 
    }
798
 
    return BUILTIN_TYPE(obj);
799
 
}
800
 
 
801
 
static inline int
802
 
rb_special_const_p(VALUE obj)
803
 
{
804
 
    if (SPECIAL_CONST_P(obj)) return Qtrue;
805
 
    return Qfalse;
806
 
}
807
 
 
808
 
#include "missing.h"
809
 
#include "intern.h"
810
 
 
811
 
#if defined(EXTLIB) && defined(USE_DLN_A_OUT)
812
 
/* hook for external modules */
813
 
static char *dln_libs_to_be_linked[] = { EXTLIB, 0 };
814
 
#endif
815
 
 
816
 
#define RUBY_VM 1 /* YARV */
817
 
#define HAVE_NATIVETHREAD
818
 
 
819
 
#if defined(__cplusplus)
820
 
#if 0
821
 
{ /* satisfy cc-mode */
822
 
#endif
823
 
}  /* extern "C" { */
824
 
#endif
825
 
 
826
 
#endif /* ifndef RUBY_H */