Ruby  2.1.10p492(2016-04-01revision54464)
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
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
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 
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);
215 
216 enum {
220 };
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);
230 
232 
233 NORETURN(void rb_fiber_start(void));
234 
235 NORETURN(void rb_print_undef(VALUE, ID, int));
237 NORETURN(void rb_vm_localjump_error(const char *,VALUE, int));
240  VALUE obj, int call_status));
241 
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);
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 */
#define ruby_longjmp(env, val)
Definition: eval_intern.h:51
static VALUE VALUE th
Definition: tcltklib.c:2944
#define CharNext(p)
Definition: eval_intern.h:254
VALUE rb_make_exception(int argc, VALUE *argv)
Definition: eval.c:682
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
void rb_print_undef_str(VALUE klass, VALUE name)
Definition: eval_error.c:229
NODE * rb_vm_cref(void)
Definition: vm.c:1015
void rb_vm_localjump_error(const char *mesg, VALUE value, int reason)
Definition: vm.c:1094
void rb_method_name_error(VALUE klass, VALUE str)
Definition: proc.c:1399
ruby_tag_type
Definition: eval_intern.h:177
memo state
Definition: enum.c:2432
void rb_thread_terminate_all(void)
Definition: thread.c:421
Definition: ripper.y:240
#define NORETURN(x)
Definition: ruby.h:33
int rb_threadptr_set_raised(rb_thread_t *th)
Definition: thread.c:2100
#define val
Definition: tcltklib.c:1935
void rb_raise_method_missing(rb_thread_t *th, int argc, VALUE *argv, VALUE obj, int call_status)
Definition: vm_eval.c:736
unsigned long ID
Definition: ripper.y:89
static VALUE VALUE obj
Definition: tcltklib.c:3150
void rb_fiber_start(void)
Definition: cont.c:1279
VALUE rb_vm_top_self()
Definition: vm.c:2834
VALUE arg
Definition: enum.c:2427
VALUE rb_vm_call_cfunc(VALUE recv, VALUE(*func)(VALUE), VALUE arg, const rb_block_t *blockptr, VALUE filename)
Definition: vm.c:1736
VALUE * argv
Definition: tcltklib.c:1969
void rb_thread_cleanup(void)
VALUE rb_vm_cbase(void)
Definition: vm.c:1048
void rb_thread_wait_other_threads(void)
int argc
Definition: tcltklib.c:1968
int rb_threadptr_reset_raised(rb_thread_t *th)
Definition: thread.c:2110
static void rb_threadptr_tag_jump(rb_thread_t *th, int st)
Definition: eval_intern.h:155
static int rb_threadptr_tag_state(rb_thread_t *th)
Definition: eval_intern.h:146
register C_block * p
Definition: crypt.c:309
void rb_vm_set_progname(VALUE filename)
Definition: vm.c:2787
VALUE rb_f_eval(int argc, VALUE *argv, VALUE self)
Definition: vm_eval.c:1349
rb_jmpbuf_t buf
Definition: vm_core.h:491
struct rb_vm_tag * tag
Definition: vm_core.h:593
unsigned long VALUE
Definition: ripper.y:88
void rb_print_undef(VALUE klass, ID id, int scope)
Definition: eval_error.c:212
VALUE rb_vm_make_jump_tag_but_local_jump(int state, VALUE val)
Definition: vm.c:1101
void rb_vm_jump_tag_but_local_jump(int state)
Definition: vm.c:1133
Tcl_Interp *int * st
Definition: stubs.c:510
char * strrchr(const char *, const char)