* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / eval_intern.h
blob201604a5b9dca127747bf53e52e24dc31da5378a
2 #ifndef RUBY_EVAL_INTERN_H
3 #define RUBY_EVAL_INTERN_H
5 #define PASS_PASSED_BLOCK_TH(th) do { \
6 (th)->passed_block = GC_GUARDED_PTR_REF((rb_block_t *)(th)->cfp->lfp[0]); \
7 (th)->cfp->flag |= VM_FRAME_FLAG_PASSED; \
8 } while (0)
10 #define PASS_PASSED_BLOCK() do { \
11 rb_thread_t * const __th__ = GET_THREAD(); \
12 PASS_PASSED_BLOCK_TH(__th__); \
13 } while (0)
15 #include "ruby/ruby.h"
16 #include "ruby/node.h"
17 #include "ruby/util.h"
18 #include "ruby/signal.h"
19 #include "vm_core.h"
21 #ifdef HAVE_STDLIB_H
22 #include <stdlib.h>
23 #endif
24 #ifndef EXIT_SUCCESS
25 #define EXIT_SUCCESS 0
26 #endif
27 #ifndef EXIT_FAILURE
28 #define EXIT_FAILURE 1
29 #endif
31 #include <stdio.h>
32 #include <setjmp.h>
34 #include "ruby/st.h"
35 #include "dln.h"
37 #ifdef __APPLE__
38 #include <crt_externs.h>
39 #endif
41 /* Make alloca work the best possible way. */
42 #ifdef __GNUC__
43 # ifndef atarist
44 # ifndef alloca
45 # define alloca __builtin_alloca
46 # endif
47 # endif /* atarist */
48 #else
49 # ifdef HAVE_ALLOCA_H
50 # include <alloca.h>
51 # else
52 # ifdef _AIX
53 #pragma alloca
54 # else
55 # ifndef alloca /* predefined by HP cc +Olibcalls */
56 void *alloca();
57 # endif
58 # endif /* AIX */
59 # endif /* HAVE_ALLOCA_H */
60 #endif /* __GNUC__ */
62 #ifdef HAVE_STDARG_PROTOTYPES
63 #include <stdarg.h>
64 #define va_init_list(a,b) va_start(a,b)
65 #else
66 #include <varargs.h>
67 #define va_init_list(a,b) va_start(a)
68 #endif
70 #ifndef HAVE_STRING_H
71 char *strrchr(const char *, const char);
72 #endif
74 #ifdef HAVE_UNISTD_H
75 #include <unistd.h>
76 #endif
78 #ifdef HAVE_NET_SOCKET_H
79 #include <net/socket.h>
80 #endif
82 #ifdef __MACOS__
83 #include "macruby_private.h"
84 #endif
86 #ifdef __VMS
87 #include "vmsruby_private.h"
88 #endif
90 #define ruby_setjmp(env) RUBY_SETJMP(env)
91 #define ruby_longjmp(env,val) RUBY_LONGJMP(env,val)
92 #ifdef __CYGWIN__
93 int _setjmp(), _longjmp();
94 #endif
96 #include <sys/types.h>
97 #include <signal.h>
98 #include <errno.h>
100 #if defined(__VMS)
101 #pragma nostandard
102 #endif
104 #ifdef HAVE_SYS_SELECT_H
105 #include <sys/select.h>
106 #endif
109 Solaris sys/select.h switches select to select_large_fdset to support larger
110 file descriptors if FD_SETSIZE is larger than 1024 on 32bit environment.
111 But Ruby doesn't change FD_SETSIZE because fd_set is allocated dynamically.
112 So following definition is required to use select_large_fdset.
114 #ifdef HAVE_SELECT_LARGE_FDSET
115 #define select(n, r, w, e, t) select_large_fdset(n, r, w, e, t)
116 #endif
118 #ifdef HAVE_SYS_PARAM_H
119 #include <sys/param.h>
120 #endif
122 #include <sys/stat.h>
124 #define SAVE_ROOT_JMPBUF(th, stmt) do \
125 if (ruby_setjmp((th)->root_jmpbuf) == 0) { \
126 stmt; \
128 else { \
129 rb_fiber_start(); \
130 } while (0)
132 #define TH_PUSH_TAG(th) do { \
133 rb_thread_t * const _th = th; \
134 struct rb_vm_tag _tag; \
135 _tag.tag = 0; \
136 _tag.prev = _th->tag; \
137 _th->tag = &_tag;
139 #define TH_POP_TAG() \
140 _th->tag = _tag.prev; \
141 } while (0)
143 #define TH_POP_TAG2() \
144 _th->tag = _tag.prev
146 #define PUSH_TAG() TH_PUSH_TAG(GET_THREAD())
147 #define POP_TAG() TH_POP_TAG()
149 #define TH_EXEC_TAG() ruby_setjmp(_th->tag->buf)
151 #define EXEC_TAG() \
152 TH_EXEC_TAG()
154 #define TH_JUMP_TAG(th, st) do { \
155 ruby_longjmp(th->tag->buf,(st)); \
156 } while (0)
158 #define JUMP_TAG(st) TH_JUMP_TAG(GET_THREAD(), st)
160 enum ruby_tag_type {
161 RUBY_TAG_RETURN = 0x1,
162 RUBY_TAG_BREAK = 0x2,
163 RUBY_TAG_NEXT = 0x3,
164 RUBY_TAG_RETRY = 0x4,
165 RUBY_TAG_REDO = 0x5,
166 RUBY_TAG_RAISE = 0x6,
167 RUBY_TAG_THROW = 0x7,
168 RUBY_TAG_FATAL = 0x8,
169 RUBY_TAG_MASK = 0xf
171 #define TAG_RETURN RUBY_TAG_RETURN
172 #define TAG_BREAK RUBY_TAG_BREAK
173 #define TAG_NEXT RUBY_TAG_NEXT
174 #define TAG_RETRY RUBY_TAG_RETRY
175 #define TAG_REDO RUBY_TAG_REDO
176 #define TAG_RAISE RUBY_TAG_RAISE
177 #define TAG_THROW RUBY_TAG_THROW
178 #define TAG_FATAL RUBY_TAG_FATAL
179 #define TAG_MASK RUBY_TAG_MASK
181 #define NEW_THROW_OBJECT(val, pt, st) \
182 ((VALUE)NEW_NODE(NODE_LIT, (val), (pt), (st)))
183 #define SET_THROWOBJ_CATCH_POINT(obj, val) \
184 (RNODE((obj))->u2.value = (val))
185 #define SET_THROWOBJ_STATE(obj, val) \
186 (RNODE((obj))->u3.value = (val))
188 #define GET_THROWOBJ_VAL(obj) ((VALUE)RNODE((obj))->u1.value)
189 #define GET_THROWOBJ_CATCH_POINT(obj) ((VALUE*)RNODE((obj))->u2.value)
190 #define GET_THROWOBJ_STATE(obj) ((int)RNODE((obj))->u3.value)
192 #define SCOPE_TEST(f) (vm_cref()->nd_visi & (f))
193 #define SCOPE_CHECK(f) (vm_cref()->nd_visi == (f))
194 #define SCOPE_SET(f) (vm_cref()->nd_visi = (f))
196 #define CHECK_STACK_OVERFLOW(cfp, margin) do \
197 if (((VALUE *)(cfp)->sp) + (margin) + sizeof(rb_control_frame_t) >= ((VALUE *)cfp)) { \
198 rb_exc_raise(sysstack_error); \
200 while (0)
202 void rb_thread_cleanup(void);
203 void rb_thread_wait_other_threads(void);
205 enum {
206 RAISED_EXCEPTION = 1,
207 RAISED_STACKOVERFLOW = 2,
208 RAISED_NOMEMORY = 4
210 int rb_thread_set_raised(rb_thread_t *th);
211 int rb_thread_reset_raised(rb_thread_t *th);
212 #define rb_thread_raised_set(th, f) ((th)->raised_flag |= (f))
213 #define rb_thread_raised_reset(th, f) ((th)->raised_flag &= ~(f))
214 #define rb_thread_raised_p(th, f) (((th)->raised_flag & (f)) != 0)
215 #define rb_thread_raised_clear(th) ((th)->raised_flag = 0)
217 VALUE rb_f_eval(int argc, VALUE *argv, VALUE self);
218 VALUE rb_make_exception(int argc, VALUE *argv);
220 NORETURN(void rb_fiber_start(void));
222 NORETURN(void rb_print_undef(VALUE, ID, int));
223 NORETURN(void vm_localjump_error(const char *,VALUE, int));
224 NORETURN(void vm_jump_tag_but_local_jump(int, VALUE));
226 VALUE vm_make_jump_tag_but_local_jump(int state, VALUE val);
227 NODE *vm_cref(void);
228 rb_control_frame_t *vm_get_ruby_level_caller_cfp(rb_thread_t *th, rb_control_frame_t *cfp);
229 VALUE rb_obj_is_proc(VALUE);
230 VALUE rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, const rb_block_t *blockptr, VALUE filename);
231 void rb_thread_terminate_all(void);
232 VALUE rb_vm_top_self();
233 VALUE rb_vm_cbase(void);
235 #endif /* RUBY_EVAL_INTERN_H */