Ruby 2.1.5p273(2014-11-13revision48405)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

eval_intern.h
Go to the documentation of this file.
1 #ifndef RUBY_EVAL_INTERN_H
2 #define RUBY_EVAL_INTERN_H
3
4 #include "ruby/ruby.h"
5 #include "vm_core.h"
6
7 #define PASS_PASSED_BLOCK_TH(th) do { \
8 (th)->passed_block = rb_vm_control_frame_block_ptr(th->cfp); \
9 (th)->cfp->flag |= VM_FRAME_FLAG_PASSED; \
10 } while (0)
11
12 #define PASS_PASSED_BLOCK() do { \
13 rb_thread_t * const __th__ = GET_THREAD(); \
14 PASS_PASSED_BLOCK_TH(__th__); \
15 } while (0)
16
17 #ifdef HAVE_STDLIB_H
18 #include <stdlib.h>
19 #endif
20 #ifndef EXIT_SUCCESS
21 #define EXIT_SUCCESS 0
22 #endif
23 #ifndef EXIT_FAILURE
24 #define EXIT_FAILURE 1
25 #endif
26
27 #include <stdio.h>
28 #include <setjmp.h>
29
30 #ifdef __APPLE__
31 # ifdef HAVE_CRT_EXTERNS_H
32 # include <crt_externs.h>
33 # else
34 # include "missing/crt_externs.h"
35 # endif
36 #endif
37
38 #ifndef HAVE_STRING_H
39 char *strrchr(const char *, const char);
40 #endif
41
42 #ifdef HAVE_UNISTD_H
43 #include <unistd.h>
44 #endif
45
46 #ifdef HAVE_NET_SOCKET_H
47 #include <net/socket.h>
48 #endif
49
50 #define ruby_setjmp(env) RUBY_SETJMP(env)
51 #define ruby_longjmp(env,val) RUBY_LONGJMP((env),(val))
52 #ifdef __CYGWIN__
53 # ifndef _setjmp
54 int _setjmp(jmp_buf);
55 # endif
56 # ifndef _longjmp
57 NORETURN(void _longjmp(jmp_buf, int));
58 # endif
59 #endif
60
61 #include <sys/types.h>
62 #include <signal.h>
63 #include <errno.h>
64
65 #ifdef HAVE_SYS_SELECT_H
66 #include <sys/select.h>
67 #endif
68
69 /*
70 Solaris sys/select.h switches select to select_large_fdset to support larger
71 file descriptors if FD_SETSIZE is larger than 1024 on 32bit environment.
72 But Ruby doesn't change FD_SETSIZE because fd_set is allocated dynamically.
73 So following definition is required to use select_large_fdset.
74 */
75 #ifdef HAVE_SELECT_LARGE_FDSET
76 #define select(n, r, w, e, t) select_large_fdset((n), (r), (w), (e), (t))
77 extern int select_large_fdset(int, fd_set *, fd_set *, fd_set *, struct timeval *);
78 #endif
79
80 #ifdef HAVE_SYS_PARAM_H
81 #include <sys/param.h>
82 #endif
83
84 #include <sys/stat.h>
85
86 #ifdef _MSC_VER
87 #define SAVE_ROOT_JMPBUF_BEFORE_STMT \
88 __try {
89 #define SAVE_ROOT_JMPBUF_AFTER_STMT \
90 } \
91 __except (GetExceptionCode() == EXCEPTION_STACK_OVERFLOW ? \
92 (rb_thread_raised_set(GET_THREAD(), RAISED_STACKOVERFLOW), \
93 raise(SIGSEGV), \
94 EXCEPTION_EXECUTE_HANDLER) : \
95 EXCEPTION_CONTINUE_SEARCH) { \
96 /* never reaches here */ \
97 }
98 #elif defined(__MINGW32__)
99 LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *);
100 #define SAVE_ROOT_JMPBUF_BEFORE_STMT \
101 do { \
102 PVOID _handler = AddVectoredExceptionHandler(1, rb_w32_stack_overflow_handler);
103
104 #define SAVE_ROOT_JMPBUF_AFTER_STMT \
105 RemoveVectoredExceptionHandler(_handler); \
106 } while (0);
107 #else
108 #define SAVE_ROOT_JMPBUF_BEFORE_STMT
109 #define SAVE_ROOT_JMPBUF_AFTER_STMT
110 #endif
111
112 #define SAVE_ROOT_JMPBUF(th, stmt) do \
113 if (ruby_setjmp((th)->root_jmpbuf) == 0) { \
114 SAVE_ROOT_JMPBUF_BEFORE_STMT \
115 stmt; \
116 SAVE_ROOT_JMPBUF_AFTER_STMT \
117 } \
118 else { \
119 rb_fiber_start(); \
120 } while (0)
121
122 #define TH_PUSH_TAG(th) do { \
123 rb_thread_t * const _th = (th); \
124 struct rb_vm_tag _tag; \
125 _tag.tag = 0; \
126 _tag.prev = _th->tag;
127
128 #define TH_POP_TAG() \
129 _th->tag = _tag.prev; \
130 } while (0)
131
132 #define TH_POP_TAG2() \
133 _th->tag = _tag.prev
134
135 #define TH_PUSH_TAG2() (_th->tag = &_tag, 0)
136
137 #define TH_TMPPOP_TAG() TH_POP_TAG2()
138
139 #define TH_REPUSH_TAG() TH_PUSH_TAG2()
140
141 #define PUSH_TAG() TH_PUSH_TAG(GET_THREAD())
142 #define POP_TAG() TH_POP_TAG()
143
144 /* clear th->state, and return the value */
145 static inline int
146 rb_threadptr_tag_state(rb_thread_t *th)
147 {
148 int state = th->state;
149 th->state = 0;
150 return state;
151 }
152
153 NORETURN(static inline void rb_threadptr_tag_jump(rb_thread_t *, int));
154 static inline void
155 rb_threadptr_tag_jump(rb_thread_t *th, int st)
156 {
157 th->state = st;
158 ruby_longjmp(th->tag->buf, 1);
159 }
160
161 /*
162 setjmp() in assignment expression rhs is undefined behavior
163 [ISO/IEC 9899:1999] 7.13.1.1
164 */
165 #define TH_EXEC_TAG() \
166 (ruby_setjmp(_tag.buf) ? rb_threadptr_tag_state(_th) : TH_PUSH_TAG2())
167
168 #define EXEC_TAG() \
169 TH_EXEC_TAG()
170
171 #define TH_JUMP_TAG(th, st) rb_threadptr_tag_jump(th, st)
172
173 #define JUMP_TAG(st) TH_JUMP_TAG(GET_THREAD(), (st))
174
175 #define INTERNAL_EXCEPTION_P(exc) FIXNUM_P(exc)
176
177 enum ruby_tag_type {
178 RUBY_TAG_RETURN = 0x1,
179 RUBY_TAG_BREAK = 0x2,
180 RUBY_TAG_NEXT = 0x3,
181 RUBY_TAG_RETRY = 0x4,
182 RUBY_TAG_REDO = 0x5,
183 RUBY_TAG_RAISE = 0x6,
184 RUBY_TAG_THROW = 0x7,
185 RUBY_TAG_FATAL = 0x8,
186 RUBY_TAG_MASK = 0xf
187 };
188 #define TAG_RETURN RUBY_TAG_RETURN
189 #define TAG_BREAK RUBY_TAG_BREAK
190 #define TAG_NEXT RUBY_TAG_NEXT
191 #define TAG_RETRY RUBY_TAG_RETRY
192 #define TAG_REDO RUBY_TAG_REDO
193 #define TAG_RAISE RUBY_TAG_RAISE
194 #define TAG_THROW RUBY_TAG_THROW
195 #define TAG_FATAL RUBY_TAG_FATAL
196 #define TAG_MASK RUBY_TAG_MASK
197
198 #define NEW_THROW_OBJECT(val, pt, st) \
199 ((VALUE)rb_node_newnode(NODE_LIT, (VALUE)(val), (VALUE)(pt), (VALUE)(st)))
200 #define SET_THROWOBJ_CATCH_POINT(obj, val) \
201 (RNODE((obj))->u2.value = (val))
202 #define SET_THROWOBJ_STATE(obj, val) \
203 (RNODE((obj))->u3.value = (val))
204
205 #define GET_THROWOBJ_VAL(obj) ((VALUE)RNODE((obj))->u1.value)
206 #define GET_THROWOBJ_CATCH_POINT(obj) ((VALUE*)RNODE((obj))->u2.value)
207 #define GET_THROWOBJ_STATE(obj) ((int)RNODE((obj))->u3.value)
208
209 #define SCOPE_TEST(f) (rb_vm_cref()->nd_visi & (f))
210 #define SCOPE_CHECK(f) (rb_vm_cref()->nd_visi == (f))
211 #define SCOPE_SET(f) (rb_vm_cref()->nd_visi = (f))
212
213 void rb_thread_cleanup(void);
214 void rb_thread_wait_other_threads(void);
215
216 enum {
217 RAISED_EXCEPTION = 1,
218 RAISED_STACKOVERFLOW = 2,
219 RAISED_NOMEMORY = 4
220 };
221 int rb_threadptr_set_raised(rb_thread_t *th);
222 int rb_threadptr_reset_raised(rb_thread_t *th);
223 #define rb_thread_raised_set(th, f) ((th)->raised_flag |= (f))
224 #define rb_thread_raised_reset(th, f) ((th)->raised_flag &= ~(f))
225 #define rb_thread_raised_p(th, f) (((th)->raised_flag & (f)) != 0)
226 #define rb_thread_raised_clear(th) ((th)->raised_flag = 0)
227
228 VALUE rb_f_eval(int argc, VALUE *argv, VALUE self);
229 VALUE rb_make_exception(int argc, VALUE *argv);
230
231 NORETURN(void rb_method_name_error(VALUE, VALUE));
232
233 NORETURN(void rb_fiber_start(void));
234
235 NORETURN(void rb_print_undef(VALUE, ID, int));
236 NORETURN(void rb_print_undef_str(VALUE, VALUE));
237 NORETURN(void rb_vm_localjump_error(const char *,VALUE, int));
238 NORETURN(void rb_vm_jump_tag_but_local_jump(int));
239 NORETURN(void rb_raise_method_missing(rb_thread_t *th, int argc, VALUE *argv,
240 VALUE obj, int call_status));
241
242 VALUE rb_vm_make_jump_tag_but_local_jump(int state, VALUE val);
243 NODE *rb_vm_cref(void);
244 VALUE rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, const rb_block_t *blockptr, VALUE filename);
245 void rb_vm_set_progname(VALUE filename);
246 void rb_thread_terminate_all(void);
247 VALUE rb_vm_top_self();
248 VALUE rb_vm_cbase(void);
249
250 #ifndef CharNext /* defined as CharNext[AW] on Windows. */
251 # ifdef HAVE_MBLEN
252 # define CharNext(p) ((p) + mblen((p), RUBY_MBCHAR_MAXSIZE))
253 # else
254 # define CharNext(p) ((p) + 1)
255 # endif
256 #endif
257
258 #if defined DOSISH || defined __CYGWIN__
259 static inline void
260 translit_char(char *p, int from, int to)
261 {
262 while (*p) {
263 if ((unsigned char)*p == from)
264 *p = to;
265 p = CharNext(p);
266 }
267 }
268 #endif
269
270 #endif /* RUBY_EVAL_INTERN_H */
NORETURN
NORETURN(static inline void rb_threadptr_tag_jump(rb_thread_t *, int))
ruby_longjmp
#define ruby_longjmp(env, val)
Definition: eval_intern.h:51
CharNext
#define CharNext(p)
Definition: eval_intern.h:254
RAISED_NOMEMORY
Definition: eval_intern.h:219
ruby.h
RUBY_TAG_NEXT
Definition: eval_intern.h:180
RUBY_TAG_MASK
Definition: eval_intern.h:186
rb_block_struct
Definition: vm_core.h:462
RUBY_TAG_REDO
Definition: eval_intern.h:182
RUBY_TAG_RAISE
Definition: eval_intern.h:183
rb_print_undef_str
void rb_print_undef_str(VALUE klass, VALUE name)
Definition: eval_error.c:229
rb_vm_cref
NODE * rb_vm_cref(void)
Definition: vm.c:1015
rb_vm_localjump_error
void rb_vm_localjump_error(const char *mesg, VALUE value, int reason)
Definition: vm.c:1094
rb_method_name_error
void rb_method_name_error(VALUE klass, VALUE str)
Definition: proc.c:1388
ruby_tag_type
ruby_tag_type
Definition: eval_intern.h:177
RUBY_TAG_RETURN
Definition: eval_intern.h:178
rb_thread_struct
Definition: vm_core.h:524
rb_thread_terminate_all
void rb_thread_terminate_all(void)
Definition: thread.c:421
RNode
Definition: node.h:239
rb_threadptr_set_raised
int rb_threadptr_set_raised(rb_thread_t *th)
Definition: thread.c:2096
RUBY_TAG_BREAK
Definition: eval_intern.h:179
val
#define val
rb_raise_method_missing
void rb_raise_method_missing(rb_thread_t *th, int argc, VALUE *argv, VALUE obj, int call_status)
Definition: vm_eval.c:730
unistd.h
signal.h
rb_make_exception
VALUE rb_make_exception(int argc, VALUE *argv)
Definition: eval.c:682
argc
int argc
Definition: ruby.c:131
rb_fiber_start
void rb_fiber_start(void)
Definition: cont.c:1270
rb_vm_top_self
VALUE rb_vm_top_self()
Definition: vm.c:2826
rb_vm_call_cfunc
VALUE rb_vm_call_cfunc(VALUE recv, VALUE(*func)(VALUE), VALUE arg, const rb_block_t *blockptr, VALUE filename)
Definition: vm.c:1732
RUBY_TAG_THROW
Definition: eval_intern.h:184
timeval
Definition: ossl_asn1.c:16
func
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
rb_thread_cleanup
void rb_thread_cleanup(void)
rb_vm_cbase
VALUE rb_vm_cbase(void)
Definition: vm.c:1048
rb_thread_wait_other_threads
void rb_thread_wait_other_threads(void)
ID
unsigned long ID
Definition: ruby.h:89
vm_core.h
VALUE
unsigned long VALUE
Definition: ruby.h:88
rb_threadptr_reset_raised
int rb_threadptr_reset_raised(rb_thread_t *th)
Definition: thread.c:2106
RUBY_TAG_RETRY
Definition: eval_intern.h:181
rb_threadptr_tag_jump
static void rb_threadptr_tag_jump(rb_thread_t *th, int st)
Definition: eval_intern.h:155
rb_threadptr_tag_state
static int rb_threadptr_tag_state(rb_thread_t *th)
Definition: eval_intern.h:146
RAISED_STACKOVERFLOW
Definition: eval_intern.h:218
RAISED_EXCEPTION
Definition: eval_intern.h:217
rb_thread_struct::state
int state
Definition: vm_core.h:537
RUBY_TAG_FATAL
Definition: eval_intern.h:185
rb_vm_set_progname
void rb_vm_set_progname(VALUE filename)
Definition: vm.c:2779
rb_f_eval
VALUE rb_f_eval(int argc, VALUE *argv, VALUE self)
Definition: vm_eval.c:1342
rb_vm_tag::buf
rb_jmpbuf_t buf
Definition: vm_core.h:491
rb_thread_struct::tag
struct rb_vm_tag * tag
Definition: vm_core.h:593
rb_print_undef
void rb_print_undef(VALUE klass, ID id, int scope)
Definition: eval_error.c:212
rb_vm_make_jump_tag_but_local_jump
VALUE rb_vm_make_jump_tag_but_local_jump(int state, VALUE val)
Definition: vm.c:1101
rb_vm_jump_tag_but_local_jump
void rb_vm_jump_tag_but_local_jump(int state)
Definition: vm.c:1133
crt_externs.h
strrchr
char * strrchr(const char *, const char)
argv
char ** argv
Definition: ruby.c:132