Ruby  1.9.3p551(2014-11-13revision48407)
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 = GC_GUARDED_PTR_REF((rb_block_t *)(th)->cfp->lfp[0]); \
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 #include <crt_externs.h>
32 #endif
33 
34 /* Make alloca work the best possible way. */
35 #ifdef __GNUC__
36 # ifndef atarist
37 # ifndef alloca
38 # define alloca __builtin_alloca
39 # endif
40 # endif /* atarist */
41 #else
42 # ifdef HAVE_ALLOCA_H
43 # include <alloca.h>
44 # else
45 # ifdef _AIX
46 #pragma alloca
47 # else
48 # ifndef alloca /* predefined by HP cc +Olibcalls */
49 void *alloca();
50 # endif
51 # endif /* AIX */
52 # endif /* HAVE_ALLOCA_H */
53 #endif /* __GNUC__ */
54 
55 #ifndef HAVE_STRING_H
56 char *strrchr(const char *, const char);
57 #endif
58 
59 #ifdef HAVE_UNISTD_H
60 #include <unistd.h>
61 #endif
62 
63 #ifdef HAVE_NET_SOCKET_H
64 #include <net/socket.h>
65 #endif
66 
67 #define ruby_setjmp(env) RUBY_SETJMP(env)
68 #define ruby_longjmp(env,val) RUBY_LONGJMP((env),(val))
69 #ifdef __CYGWIN__
70 # ifndef _setjmp
71 int _setjmp(jmp_buf);
72 # endif
73 # ifndef _longjmp
74 NORETURN(void _longjmp(jmp_buf, int));
75 # endif
76 #endif
77 
78 #include <sys/types.h>
79 #include <signal.h>
80 #include <errno.h>
81 
82 #ifdef HAVE_SYS_SELECT_H
83 #include <sys/select.h>
84 #endif
85 
86 /*
87  Solaris sys/select.h switches select to select_large_fdset to support larger
88  file descriptors if FD_SETSIZE is larger than 1024 on 32bit environment.
89  But Ruby doesn't change FD_SETSIZE because fd_set is allocated dynamically.
90  So following definition is required to use select_large_fdset.
91 */
92 #ifdef HAVE_SELECT_LARGE_FDSET
93 #define select(n, r, w, e, t) select_large_fdset((n), (r), (w), (e), (t))
94 extern int select_large_fdset(int, fd_set *, fd_set *, fd_set *, struct timeval *);
95 #endif
96 
97 #ifdef HAVE_SYS_PARAM_H
98 #include <sys/param.h>
99 #endif
100 
101 #include <sys/stat.h>
102 
103 #define SAVE_ROOT_JMPBUF(th, stmt) do \
104  if (ruby_setjmp((th)->root_jmpbuf) == 0) { \
105  stmt; \
106  } \
107  else { \
108  rb_fiber_start(); \
109  } while (0)
110 
111 #define TH_PUSH_TAG(th) do { \
112  rb_thread_t * const _th = (th); \
113  struct rb_vm_tag _tag; \
114  _tag.tag = 0; \
115  _tag.prev = _th->tag; \
116  _th->tag = &_tag;
117 
118 #define TH_POP_TAG() \
119  _th->tag = _tag.prev; \
120 } while (0)
121 
122 #define TH_POP_TAG2() \
123  _th->tag = _tag.prev
124 
125 #define PUSH_TAG() TH_PUSH_TAG(GET_THREAD())
126 #define POP_TAG() TH_POP_TAG()
127 
128 #define TH_EXEC_TAG() ruby_setjmp(_th->tag->buf)
129 
130 #define EXEC_TAG() \
131  TH_EXEC_TAG()
132 
133 #define TH_JUMP_TAG(th, st) do { \
134  ruby_longjmp((th)->tag->buf,(st)); \
135 } while (0)
136 
137 #define JUMP_TAG(st) TH_JUMP_TAG(GET_THREAD(), (st))
138 
139 #define INTERNAL_EXCEPTION_P(exc) FIXNUM_P(exc)
140 
151 };
152 #define TAG_RETURN RUBY_TAG_RETURN
153 #define TAG_BREAK RUBY_TAG_BREAK
154 #define TAG_NEXT RUBY_TAG_NEXT
155 #define TAG_RETRY RUBY_TAG_RETRY
156 #define TAG_REDO RUBY_TAG_REDO
157 #define TAG_RAISE RUBY_TAG_RAISE
158 #define TAG_THROW RUBY_TAG_THROW
159 #define TAG_FATAL RUBY_TAG_FATAL
160 #define TAG_MASK RUBY_TAG_MASK
161 
162 #define NEW_THROW_OBJECT(val, pt, st) \
163  ((VALUE)rb_node_newnode(NODE_LIT, (VALUE)(val), (VALUE)(pt), (VALUE)(st)))
164 #define SET_THROWOBJ_CATCH_POINT(obj, val) \
165  (RNODE((obj))->u2.value = (val))
166 #define SET_THROWOBJ_STATE(obj, val) \
167  (RNODE((obj))->u3.value = (val))
168 
169 #define GET_THROWOBJ_VAL(obj) ((VALUE)RNODE((obj))->u1.value)
170 #define GET_THROWOBJ_CATCH_POINT(obj) ((VALUE*)RNODE((obj))->u2.value)
171 #define GET_THROWOBJ_STATE(obj) ((int)RNODE((obj))->u3.value)
172 
173 #define SCOPE_TEST(f) (rb_vm_cref()->nd_visi & (f))
174 #define SCOPE_CHECK(f) (rb_vm_cref()->nd_visi == (f))
175 #define SCOPE_SET(f) (rb_vm_cref()->nd_visi = (f))
176 
177 #define CHECK_STACK_OVERFLOW(cfp, margin) do \
178  if ((VALUE *)((char *)(((VALUE *)(cfp)->sp) + (margin)) + sizeof(rb_control_frame_t)) >= ((VALUE *)(cfp))) { \
179  rb_exc_raise(sysstack_error); \
180  } \
181 while (0)
182 
183 void rb_thread_cleanup(void);
185 
186 enum {
190 };
193 #define rb_thread_raised_set(th, f) ((th)->raised_flag |= (f))
194 #define rb_thread_raised_reset(th, f) ((th)->raised_flag &= ~(f))
195 #define rb_thread_raised_p(th, f) (((th)->raised_flag & (f)) != 0)
196 #define rb_thread_raised_clear(th) ((th)->raised_flag = 0)
197 
198 VALUE rb_f_eval(int argc, VALUE *argv, VALUE self);
200 
201 NORETURN(void rb_fiber_start(void));
202 
203 NORETURN(void rb_print_undef(VALUE, ID, int));
204 NORETURN(void rb_vm_localjump_error(const char *,VALUE, int));
207  VALUE obj, int call_status));
208 
210 NODE *rb_vm_cref(void);
211 VALUE rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, const rb_block_t *blockptr, VALUE filename);
212 void rb_vm_set_progname(VALUE filename);
213 void rb_thread_terminate_all(void);
215 VALUE rb_vm_cbase(void);
216 void rb_trap_restore_mask(void);
217 
218 #ifndef CharNext /* defined as CharNext[AW] on Windows. */
219 #define CharNext(p) ((p) + mblen((p), RUBY_MBCHAR_MAXSIZE))
220 #endif
221 
222 #if defined DOSISH || defined __CYGWIN__
223 static inline void
224 translit_char(char *p, int from, int to)
225 {
226  while (*p) {
227  if ((unsigned char)*p == from)
228  *p = to;
229  p = CharNext(p);
230  }
231 }
232 #endif
233 
234 #endif /* RUBY_EVAL_INTERN_H */
static VALUE VALUE th
Definition: tcltklib.c:2937
#define CharNext(p)
Definition: eval_intern.h:219
VALUE rb_make_exception(int argc, VALUE *argv)
Definition: eval.c:574
void * alloca()
parser parser_yylval val
Definition: ripper.c:14289
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
SYMID SyckParser * p
Definition: yaml2byte.c:119
unsigned long VALUE
Definition: ruby.h:88
void rb_vm_jump_tag_but_local_jump(int state, VALUE val)
Definition: vm.c:1011
NODE * rb_vm_cref(void)
Definition: vm.c:902
void rb_vm_localjump_error(const char *mesg, VALUE value, int reason)
Definition: vm.c:972
ruby_tag_type
Definition: eval_intern.h:141
void rb_thread_terminate_all(void)
Definition: thread.c:370
Definition: ripper.y:236
#define NORETURN(x)
Definition: ruby.h:31
int rb_threadptr_set_raised(rb_thread_t *th)
Definition: thread.c:1433
void rb_raise_method_missing(rb_thread_t *th, int argc, VALUE *argv, VALUE obj, int call_status)
Definition: vm_eval.c:601
static VALUE VALUE obj
Definition: tcltklib.c:3147
void rb_fiber_start(void)
Definition: cont.c:1139
VALUE rb_vm_top_self()
Definition: vm.c:2259
VALUE rb_vm_call_cfunc(VALUE recv, VALUE(*func)(VALUE), VALUE arg, const rb_block_t *blockptr, VALUE filename)
Definition: vm.c:1544
VALUE * argv
Definition: tcltklib.c:1962
void rb_thread_cleanup(void)
VALUE rb_vm_cbase(void)
Definition: vm.c:926
void rb_thread_wait_other_threads(void)
unsigned long ID
Definition: ruby.h:89
int argc
Definition: tcltklib.c:1961
int rb_threadptr_reset_raised(rb_thread_t *th)
Definition: thread.c:1443
state
Definition: gb18030.c:213
arg
Definition: ripper.y:1287
void rb_trap_restore_mask(void)
Definition: signal.c:908
void rb_vm_set_progname(VALUE filename)
Definition: vm.c:2212
VALUE rb_f_eval(int argc, VALUE *argv, VALUE self)
Definition: vm_eval.c:1130
void rb_print_undef(VALUE klass, ID id, int scope)
Definition: eval_error.c:193
VALUE rb_vm_make_jump_tag_but_local_jump(int state, VALUE val)
Definition: vm.c:979
char * strrchr(const char *, const char)