binding_of_caller 0.7.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gemtest +0 -0
- data/.github/workflows/test.yml +103 -0
- data/.gitignore +13 -7
- data/.yardopts +0 -0
- data/Gemfile +6 -1
- data/HISTORY +35 -0
- data/LICENSE +0 -0
- data/README.md +19 -7
- data/Rakefile +4 -132
- data/binding_of_caller.gemspec +33 -35
- data/lib/binding_of_caller.rb +9 -10
- data/lib/binding_of_caller/jruby_interpreted.rb +123 -0
- data/lib/binding_of_caller/{mri2.rb → mri.rb} +9 -15
- data/lib/binding_of_caller/rubinius.rb +26 -36
- data/lib/binding_of_caller/version.rb +1 -1
- metadata +34 -109
- data/.travis.yml +0 -22
- data/examples/example.rb +0 -41
- data/ext/binding_of_caller/binding_of_caller.c +0 -225
- data/ext/binding_of_caller/extconf.rb +0 -33
- data/ext/binding_of_caller/ruby_headers/192/debug.h +0 -36
- data/ext/binding_of_caller/ruby_headers/192/dln.h +0 -41
- data/ext/binding_of_caller/ruby_headers/192/eval_intern.h +0 -232
- data/ext/binding_of_caller/ruby_headers/192/gc.h +0 -77
- data/ext/binding_of_caller/ruby_headers/192/id.h +0 -173
- data/ext/binding_of_caller/ruby_headers/192/iseq.h +0 -104
- data/ext/binding_of_caller/ruby_headers/192/method.h +0 -103
- data/ext/binding_of_caller/ruby_headers/192/node.h +0 -483
- data/ext/binding_of_caller/ruby_headers/192/regenc.h +0 -211
- data/ext/binding_of_caller/ruby_headers/192/regint.h +0 -841
- data/ext/binding_of_caller/ruby_headers/192/regparse.h +0 -354
- data/ext/binding_of_caller/ruby_headers/192/thread_pthread.h +0 -27
- data/ext/binding_of_caller/ruby_headers/192/thread_win32.h +0 -33
- data/ext/binding_of_caller/ruby_headers/192/timev.h +0 -21
- data/ext/binding_of_caller/ruby_headers/192/transcode_data.h +0 -109
- data/ext/binding_of_caller/ruby_headers/192/version.h +0 -63
- data/ext/binding_of_caller/ruby_headers/192/vm_core.h +0 -703
- data/ext/binding_of_caller/ruby_headers/192/vm_exec.h +0 -184
- data/ext/binding_of_caller/ruby_headers/192/vm_insnhelper.h +0 -208
- data/ext/binding_of_caller/ruby_headers/192/vm_opts.h +0 -51
- data/ext/binding_of_caller/ruby_headers/193/addr2line.h +0 -21
- data/ext/binding_of_caller/ruby_headers/193/atomic.h +0 -56
- data/ext/binding_of_caller/ruby_headers/193/constant.h +0 -34
- data/ext/binding_of_caller/ruby_headers/193/debug.h +0 -41
- data/ext/binding_of_caller/ruby_headers/193/dln.h +0 -50
- data/ext/binding_of_caller/ruby_headers/193/encdb.h +0 -167
- data/ext/binding_of_caller/ruby_headers/193/eval_intern.h +0 -234
- data/ext/binding_of_caller/ruby_headers/193/gc.h +0 -98
- data/ext/binding_of_caller/ruby_headers/193/id.h +0 -175
- data/ext/binding_of_caller/ruby_headers/193/internal.h +0 -227
- data/ext/binding_of_caller/ruby_headers/193/iseq.h +0 -125
- data/ext/binding_of_caller/ruby_headers/193/method.h +0 -105
- data/ext/binding_of_caller/ruby_headers/193/node.h +0 -503
- data/ext/binding_of_caller/ruby_headers/193/parse.h +0 -186
- data/ext/binding_of_caller/ruby_headers/193/regenc.h +0 -219
- data/ext/binding_of_caller/ruby_headers/193/regint.h +0 -851
- data/ext/binding_of_caller/ruby_headers/193/regparse.h +0 -362
- data/ext/binding_of_caller/ruby_headers/193/revision.h +0 -1
- data/ext/binding_of_caller/ruby_headers/193/thread_pthread.h +0 -51
- data/ext/binding_of_caller/ruby_headers/193/thread_win32.h +0 -40
- data/ext/binding_of_caller/ruby_headers/193/timev.h +0 -21
- data/ext/binding_of_caller/ruby_headers/193/transcode_data.h +0 -117
- data/ext/binding_of_caller/ruby_headers/193/transdb.h +0 -189
- data/ext/binding_of_caller/ruby_headers/193/version.h +0 -52
- data/ext/binding_of_caller/ruby_headers/193/vm_core.h +0 -755
- data/ext/binding_of_caller/ruby_headers/193/vm_exec.h +0 -184
- data/ext/binding_of_caller/ruby_headers/193/vm_insnhelper.h +0 -220
- data/ext/binding_of_caller/ruby_headers/193/vm_opts.h +0 -51
- data/test/test_binding_of_caller.rb +0 -149
data/.travis.yml
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
rvm:
|
2
|
-
- 1.9.2
|
3
|
-
- 1.9.3
|
4
|
-
- ruby-head
|
5
|
-
|
6
|
-
notifications:
|
7
|
-
irc: "irc.freenode.org#pry"
|
8
|
-
recipients:
|
9
|
-
- jrmair@gmail.com
|
10
|
-
|
11
|
-
branches:
|
12
|
-
only:
|
13
|
-
- master
|
14
|
-
|
15
|
-
#script: rake test --trace
|
16
|
-
#
|
17
|
-
#before_install:
|
18
|
-
# - gem update --system
|
19
|
-
# - gem --version
|
20
|
-
# - gem install rake bacon
|
21
|
-
# - rake gem
|
22
|
-
# - gem install pkg/*.gem
|
data/examples/example.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
unless Object.const_defined? :BindingOfCaller
|
2
|
-
$:.unshift File.expand_path '../../lib', __FILE__
|
3
|
-
require 'binding_of_caller'
|
4
|
-
require 'binding_of_caller/version'
|
5
|
-
end
|
6
|
-
|
7
|
-
outer = 10
|
8
|
-
|
9
|
-
class Z
|
10
|
-
def z
|
11
|
-
u = 10
|
12
|
-
A.new.a
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class A
|
17
|
-
def a
|
18
|
-
y = 10
|
19
|
-
B.new.b
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class B
|
24
|
-
def b
|
25
|
-
x = 10
|
26
|
-
puts binding.of_caller(0).eval('local_variables')
|
27
|
-
puts binding.of_caller(1).eval('local_variables')
|
28
|
-
puts binding.of_caller(2).eval('local_variables')
|
29
|
-
puts binding.of_caller(3).eval('local_variables')
|
30
|
-
puts binding.of_caller(400).eval('local_variables')
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
Z.new.z
|
35
|
-
|
36
|
-
# output:
|
37
|
-
# => x
|
38
|
-
# => y
|
39
|
-
# => u
|
40
|
-
# => outer
|
41
|
-
# Exception
|
@@ -1,225 +0,0 @@
|
|
1
|
-
/* (c) 2011 John Mair (banisterfiend), MIT license */
|
2
|
-
|
3
|
-
#include <ruby.h>
|
4
|
-
#include "vm_core.h"
|
5
|
-
#include "gc.h"
|
6
|
-
|
7
|
-
typedef enum { false, true } bool;
|
8
|
-
|
9
|
-
static VALUE
|
10
|
-
string2sym(const char * string)
|
11
|
-
{
|
12
|
-
return ID2SYM(rb_intern(string));
|
13
|
-
}
|
14
|
-
|
15
|
-
static inline const rb_data_type_t *
|
16
|
-
threadptr_data_type(void)
|
17
|
-
{
|
18
|
-
static const rb_data_type_t *thread_data_type;
|
19
|
-
if (!thread_data_type) {
|
20
|
-
VALUE current_thread = rb_thread_current();
|
21
|
-
thread_data_type = RTYPEDDATA_TYPE(current_thread);
|
22
|
-
}
|
23
|
-
return thread_data_type;
|
24
|
-
}
|
25
|
-
|
26
|
-
#define ruby_thread_data_type *threadptr_data_type()
|
27
|
-
#define ruby_threadptr_data_type *threadptr_data_type()
|
28
|
-
|
29
|
-
#define ruby_current_thread ((rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current()))
|
30
|
-
|
31
|
-
static size_t
|
32
|
-
binding_memsize(const void *ptr)
|
33
|
-
{
|
34
|
-
return ptr ? sizeof(rb_binding_t) : 0;
|
35
|
-
}
|
36
|
-
|
37
|
-
static void
|
38
|
-
binding_free(void *ptr)
|
39
|
-
{
|
40
|
-
rb_binding_t *bind;
|
41
|
-
RUBY_FREE_ENTER("binding");
|
42
|
-
if (ptr) {
|
43
|
-
bind = ptr;
|
44
|
-
ruby_xfree(ptr);
|
45
|
-
}
|
46
|
-
RUBY_FREE_LEAVE("binding");
|
47
|
-
}
|
48
|
-
|
49
|
-
static void
|
50
|
-
binding_mark(void *ptr)
|
51
|
-
{
|
52
|
-
rb_binding_t *bind;
|
53
|
-
RUBY_MARK_ENTER("binding");
|
54
|
-
if (ptr) {
|
55
|
-
bind = ptr;
|
56
|
-
RUBY_MARK_UNLESS_NULL(bind->env);
|
57
|
-
|
58
|
-
#ifdef RUBY_192
|
59
|
-
RUBY_MARK_UNLESS_NULL(bind->filename);
|
60
|
-
#endif
|
61
|
-
|
62
|
-
}
|
63
|
-
RUBY_MARK_LEAVE("binding");
|
64
|
-
}
|
65
|
-
|
66
|
-
static const rb_data_type_t binding_data_type = {
|
67
|
-
"binding",
|
68
|
-
binding_mark,
|
69
|
-
binding_free,
|
70
|
-
binding_memsize,
|
71
|
-
};
|
72
|
-
|
73
|
-
static VALUE
|
74
|
-
binding_alloc(VALUE klass)
|
75
|
-
{
|
76
|
-
VALUE obj;
|
77
|
-
rb_binding_t *bind;
|
78
|
-
obj = TypedData_Make_Struct(klass, rb_binding_t, &binding_data_type, bind);
|
79
|
-
return obj;
|
80
|
-
}
|
81
|
-
|
82
|
-
static bool ifunc_p(rb_control_frame_t * cfp) {
|
83
|
-
return (cfp->flag & VM_FRAME_MAGIC_MASK) == VM_FRAME_MAGIC_IFUNC;
|
84
|
-
}
|
85
|
-
|
86
|
-
static bool valid_frame_p(rb_control_frame_t * cfp, rb_control_frame_t * limit_cfp) {
|
87
|
-
return cfp->iseq && !ifunc_p(cfp) && !NIL_P(cfp->self);
|
88
|
-
}
|
89
|
-
|
90
|
-
static rb_control_frame_t * find_valid_frame(rb_control_frame_t * cfp, rb_control_frame_t * limit_cfp) {
|
91
|
-
while (cfp < limit_cfp) {
|
92
|
-
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
|
93
|
-
|
94
|
-
if (cfp >= limit_cfp)
|
95
|
-
return NULL;
|
96
|
-
|
97
|
-
if (valid_frame_p(cfp, limit_cfp))
|
98
|
-
return cfp;
|
99
|
-
}
|
100
|
-
|
101
|
-
// beyond end of stack
|
102
|
-
return NULL;
|
103
|
-
}
|
104
|
-
|
105
|
-
static VALUE
|
106
|
-
frametype_name(VALUE flag)
|
107
|
-
{
|
108
|
-
switch (flag & VM_FRAME_MAGIC_MASK) {
|
109
|
-
case VM_FRAME_MAGIC_METHOD: return string2sym("method");
|
110
|
-
case VM_FRAME_MAGIC_BLOCK: return string2sym("block");
|
111
|
-
case VM_FRAME_MAGIC_CLASS: return string2sym("class");
|
112
|
-
case VM_FRAME_MAGIC_TOP: return string2sym("top");
|
113
|
-
case VM_FRAME_MAGIC_CFUNC: return string2sym("cfunc");
|
114
|
-
case VM_FRAME_MAGIC_PROC: return string2sym("proc");
|
115
|
-
case VM_FRAME_MAGIC_IFUNC: return string2sym("ifunc");
|
116
|
-
case VM_FRAME_MAGIC_EVAL: return string2sym("eval");
|
117
|
-
case VM_FRAME_MAGIC_LAMBDA: return string2sym("lambda");
|
118
|
-
default:
|
119
|
-
rb_raise(rb_eRuntimeError, "Unknown frame type! got flag: %d", FIX2INT(flag));
|
120
|
-
}
|
121
|
-
}
|
122
|
-
|
123
|
-
static VALUE binding_of_caller(VALUE self, VALUE rb_level)
|
124
|
-
{
|
125
|
-
rb_thread_t *th;
|
126
|
-
GetThreadPtr(rb_thread_current(), th);
|
127
|
-
|
128
|
-
rb_control_frame_t *cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
|
129
|
-
rb_control_frame_t *limit_cfp = (void *)(th->stack + th->stack_size);
|
130
|
-
int level = FIX2INT(rb_level);
|
131
|
-
|
132
|
-
// attempt to locate the nth parent control frame
|
133
|
-
for (int i = 0; i < level; i++) {
|
134
|
-
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
|
135
|
-
|
136
|
-
if (cfp >= limit_cfp)
|
137
|
-
rb_raise(rb_eRuntimeError, "Invalid frame, gone beyond end of stack!");
|
138
|
-
|
139
|
-
// skip invalid frames
|
140
|
-
if (!valid_frame_p(cfp, limit_cfp))
|
141
|
-
cfp = find_valid_frame(cfp, limit_cfp);
|
142
|
-
}
|
143
|
-
|
144
|
-
VALUE bindval = binding_alloc(rb_cBinding);
|
145
|
-
rb_binding_t *bind;
|
146
|
-
|
147
|
-
if (cfp == 0)
|
148
|
-
rb_raise(rb_eRuntimeError, "Can't create Binding Object on top of Fiber.");
|
149
|
-
|
150
|
-
GetBindingPtr(bindval, bind);
|
151
|
-
|
152
|
-
bind->env = rb_vm_make_env_object(th, cfp);
|
153
|
-
bind->filename = cfp->iseq->filename;
|
154
|
-
bind->line_no = rb_vm_get_sourceline(cfp);
|
155
|
-
|
156
|
-
rb_iv_set(bindval, "@frame_type", frametype_name(cfp->flag));
|
157
|
-
rb_iv_set(bindval, "@frame_description", cfp->iseq->name);
|
158
|
-
|
159
|
-
return bindval;
|
160
|
-
}
|
161
|
-
|
162
|
-
static VALUE
|
163
|
-
frame_type(VALUE self)
|
164
|
-
{
|
165
|
-
return rb_iv_get(self, "@frame_type");
|
166
|
-
}
|
167
|
-
|
168
|
-
static VALUE
|
169
|
-
frame_description(VALUE self)
|
170
|
-
{
|
171
|
-
return rb_iv_get(self, "@frame_description");
|
172
|
-
}
|
173
|
-
|
174
|
-
static VALUE frame_count(VALUE self)
|
175
|
-
{
|
176
|
-
rb_thread_t *th;
|
177
|
-
GetThreadPtr(rb_thread_current(), th);
|
178
|
-
|
179
|
-
rb_control_frame_t *cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
|
180
|
-
rb_control_frame_t *limit_cfp = (void *)(th->stack + th->stack_size);
|
181
|
-
|
182
|
-
int i = 1;
|
183
|
-
while (cfp < limit_cfp) {
|
184
|
-
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
|
185
|
-
|
186
|
-
if (cfp >= limit_cfp)
|
187
|
-
return INT2FIX(i);
|
188
|
-
|
189
|
-
// skip invalid frames
|
190
|
-
if (!valid_frame_p(cfp, limit_cfp))
|
191
|
-
cfp = find_valid_frame(cfp, limit_cfp);
|
192
|
-
|
193
|
-
if (!cfp)
|
194
|
-
break;
|
195
|
-
|
196
|
-
i++;
|
197
|
-
}
|
198
|
-
|
199
|
-
return INT2FIX(i);
|
200
|
-
}
|
201
|
-
|
202
|
-
static VALUE
|
203
|
-
callers(VALUE self)
|
204
|
-
{
|
205
|
-
VALUE ary = rb_ary_new();
|
206
|
-
|
207
|
-
for (int i = 0; i < FIX2INT(frame_count(self)); i++)
|
208
|
-
rb_ary_push(ary, binding_of_caller(self, INT2FIX(i)));
|
209
|
-
|
210
|
-
return ary;
|
211
|
-
}
|
212
|
-
|
213
|
-
void
|
214
|
-
Init_binding_of_caller()
|
215
|
-
{
|
216
|
-
VALUE mBindingOfCaller = rb_define_module("BindingOfCaller");
|
217
|
-
|
218
|
-
rb_define_method(mBindingOfCaller, "of_caller", binding_of_caller, 1);
|
219
|
-
rb_define_method(mBindingOfCaller, "frame_count", frame_count, 0);
|
220
|
-
rb_define_method(mBindingOfCaller, "frame_type", frame_type, 0);
|
221
|
-
rb_define_method(mBindingOfCaller, "frame_description", frame_description, 0);
|
222
|
-
rb_define_method(mBindingOfCaller, "callers", callers, 0);
|
223
|
-
rb_include_module(rb_cBinding, mBindingOfCaller);
|
224
|
-
}
|
225
|
-
|
@@ -1,33 +0,0 @@
|
|
1
|
-
def fake_makefile
|
2
|
-
File.open(File.join(File.dirname(__FILE__), "Makefile"), "w") do |f|
|
3
|
-
f.puts %[install:\n\techo "Nada."]
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
def mri_2?
|
8
|
-
defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" &&
|
9
|
-
RUBY_VERSION =~ /^2/
|
10
|
-
end
|
11
|
-
|
12
|
-
def rbx?
|
13
|
-
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
|
14
|
-
end
|
15
|
-
|
16
|
-
if mri_2? || rbx?
|
17
|
-
fake_makefile
|
18
|
-
else
|
19
|
-
require 'mkmf'
|
20
|
-
|
21
|
-
$CFLAGS += " -O0"
|
22
|
-
$CFLAGS += " -std=c99"
|
23
|
-
|
24
|
-
case RUBY_VERSION
|
25
|
-
when /1.9.2/
|
26
|
-
$CFLAGS += " -I./ruby_headers/192/ -DRUBY_192"
|
27
|
-
when /1.9.3/
|
28
|
-
$CFLAGS += " -I./ruby_headers/193/ -DRUBY_193"
|
29
|
-
end
|
30
|
-
|
31
|
-
create_makefile('binding_of_caller')
|
32
|
-
end
|
33
|
-
|
@@ -1,36 +0,0 @@
|
|
1
|
-
/**********************************************************************
|
2
|
-
|
3
|
-
debug.h - YARV Debug function interface
|
4
|
-
|
5
|
-
$Author$
|
6
|
-
created at: 04/08/25 02:33:49 JST
|
7
|
-
|
8
|
-
Copyright (C) 2004-2007 Koichi Sasada
|
9
|
-
|
10
|
-
**********************************************************************/
|
11
|
-
|
12
|
-
#ifndef RUBY_DEBUG_H
|
13
|
-
#define RUBY_DEBUG_H
|
14
|
-
|
15
|
-
#include "ruby/ruby.h"
|
16
|
-
#include "node.h"
|
17
|
-
|
18
|
-
#define dpv(h,v) ruby_debug_print_value(-1, 0, h, v)
|
19
|
-
#define dp(v) ruby_debug_print_value(-1, 0, "", v)
|
20
|
-
#define dpi(i) ruby_debug_print_id(-1, 0, "", i)
|
21
|
-
#define dpn(n) ruby_debug_print_node(-1, 0, "", n)
|
22
|
-
|
23
|
-
#define bp() ruby_debug_breakpoint()
|
24
|
-
|
25
|
-
VALUE ruby_debug_print_value(int level, int debug_level, const char *header, VALUE v);
|
26
|
-
ID ruby_debug_print_id(int level, int debug_level, const char *header, ID id);
|
27
|
-
NODE *ruby_debug_print_node(int level, int debug_level, const char *header, const NODE *node);
|
28
|
-
int ruby_debug_print_indent(int level, int debug_level, int indent_level);
|
29
|
-
void ruby_debug_breakpoint(void);
|
30
|
-
void ruby_debug_gc_check_func(void);
|
31
|
-
|
32
|
-
#ifdef RUBY_DEBUG_ENV
|
33
|
-
void ruby_set_debug_option(const char *str);
|
34
|
-
#endif
|
35
|
-
|
36
|
-
#endif /* RUBY_DEBUG_H */
|
@@ -1,41 +0,0 @@
|
|
1
|
-
/**********************************************************************
|
2
|
-
|
3
|
-
dln.h -
|
4
|
-
|
5
|
-
$Author$
|
6
|
-
created at: Wed Jan 19 16:53:09 JST 1994
|
7
|
-
|
8
|
-
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
9
|
-
|
10
|
-
**********************************************************************/
|
11
|
-
|
12
|
-
#ifndef DLN_H
|
13
|
-
#define DLN_H
|
14
|
-
|
15
|
-
#ifdef __cplusplus
|
16
|
-
# ifndef HAVE_PROTOTYPES
|
17
|
-
# define HAVE_PROTOTYPES 1
|
18
|
-
# endif
|
19
|
-
# ifndef HAVE_STDARG_PROTOTYPES
|
20
|
-
# define HAVE_STDARG_PROTOTYPES 1
|
21
|
-
# endif
|
22
|
-
#endif
|
23
|
-
|
24
|
-
#undef _
|
25
|
-
#ifdef HAVE_PROTOTYPES
|
26
|
-
# define _(args) args
|
27
|
-
#else
|
28
|
-
# define _(args) ()
|
29
|
-
#endif
|
30
|
-
|
31
|
-
DEPRECATED(char *dln_find_exe(const char*,const char*));
|
32
|
-
DEPRECATED(char *dln_find_file(const char*,const char*));
|
33
|
-
char *dln_find_exe_r(const char*,const char*,char*,size_t);
|
34
|
-
char *dln_find_file_r(const char*,const char*,char*,size_t);
|
35
|
-
|
36
|
-
#ifdef USE_DLN_A_OUT
|
37
|
-
extern char *dln_argv0;
|
38
|
-
#endif
|
39
|
-
|
40
|
-
void *dln_load(const char*);
|
41
|
-
#endif
|
@@ -1,232 +0,0 @@
|
|
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
|
-
#endif
|
95
|
-
|
96
|
-
#ifdef HAVE_SYS_PARAM_H
|
97
|
-
#include <sys/param.h>
|
98
|
-
#endif
|
99
|
-
|
100
|
-
#include <sys/stat.h>
|
101
|
-
|
102
|
-
#define SAVE_ROOT_JMPBUF(th, stmt) do \
|
103
|
-
if (ruby_setjmp((th)->root_jmpbuf) == 0) { \
|
104
|
-
stmt; \
|
105
|
-
} \
|
106
|
-
else { \
|
107
|
-
rb_fiber_start(); \
|
108
|
-
} while (0)
|
109
|
-
|
110
|
-
#define TH_PUSH_TAG(th) do { \
|
111
|
-
rb_thread_t * const _th = th; \
|
112
|
-
struct rb_vm_tag _tag; \
|
113
|
-
_tag.tag = 0; \
|
114
|
-
_tag.prev = _th->tag; \
|
115
|
-
_th->tag = &_tag;
|
116
|
-
|
117
|
-
#define TH_POP_TAG() \
|
118
|
-
_th->tag = _tag.prev; \
|
119
|
-
} while (0)
|
120
|
-
|
121
|
-
#define TH_POP_TAG2() \
|
122
|
-
_th->tag = _tag.prev
|
123
|
-
|
124
|
-
#define PUSH_TAG() TH_PUSH_TAG(GET_THREAD())
|
125
|
-
#define POP_TAG() TH_POP_TAG()
|
126
|
-
|
127
|
-
#define TH_EXEC_TAG() ruby_setjmp(_th->tag->buf)
|
128
|
-
|
129
|
-
#define EXEC_TAG() \
|
130
|
-
TH_EXEC_TAG()
|
131
|
-
|
132
|
-
#define TH_JUMP_TAG(th, st) do { \
|
133
|
-
ruby_longjmp(th->tag->buf,(st)); \
|
134
|
-
} while (0)
|
135
|
-
|
136
|
-
#define JUMP_TAG(st) TH_JUMP_TAG(GET_THREAD(), st)
|
137
|
-
|
138
|
-
enum ruby_tag_type {
|
139
|
-
RUBY_TAG_RETURN = 0x1,
|
140
|
-
RUBY_TAG_BREAK = 0x2,
|
141
|
-
RUBY_TAG_NEXT = 0x3,
|
142
|
-
RUBY_TAG_RETRY = 0x4,
|
143
|
-
RUBY_TAG_REDO = 0x5,
|
144
|
-
RUBY_TAG_RAISE = 0x6,
|
145
|
-
RUBY_TAG_THROW = 0x7,
|
146
|
-
RUBY_TAG_FATAL = 0x8,
|
147
|
-
RUBY_TAG_MASK = 0xf
|
148
|
-
};
|
149
|
-
#define TAG_RETURN RUBY_TAG_RETURN
|
150
|
-
#define TAG_BREAK RUBY_TAG_BREAK
|
151
|
-
#define TAG_NEXT RUBY_TAG_NEXT
|
152
|
-
#define TAG_RETRY RUBY_TAG_RETRY
|
153
|
-
#define TAG_REDO RUBY_TAG_REDO
|
154
|
-
#define TAG_RAISE RUBY_TAG_RAISE
|
155
|
-
#define TAG_THROW RUBY_TAG_THROW
|
156
|
-
#define TAG_FATAL RUBY_TAG_FATAL
|
157
|
-
#define TAG_MASK RUBY_TAG_MASK
|
158
|
-
|
159
|
-
#define NEW_THROW_OBJECT(val, pt, st) \
|
160
|
-
((VALUE)rb_node_newnode(NODE_LIT, (VALUE)(val), (VALUE)(pt), (VALUE)(st)))
|
161
|
-
#define SET_THROWOBJ_CATCH_POINT(obj, val) \
|
162
|
-
(RNODE((obj))->u2.value = (val))
|
163
|
-
#define SET_THROWOBJ_STATE(obj, val) \
|
164
|
-
(RNODE((obj))->u3.value = (val))
|
165
|
-
|
166
|
-
#define GET_THROWOBJ_VAL(obj) ((VALUE)RNODE((obj))->u1.value)
|
167
|
-
#define GET_THROWOBJ_CATCH_POINT(obj) ((VALUE*)RNODE((obj))->u2.value)
|
168
|
-
#define GET_THROWOBJ_STATE(obj) ((int)RNODE((obj))->u3.value)
|
169
|
-
|
170
|
-
#define SCOPE_TEST(f) (rb_vm_cref()->nd_visi & (f))
|
171
|
-
#define SCOPE_CHECK(f) (rb_vm_cref()->nd_visi == (f))
|
172
|
-
#define SCOPE_SET(f) (rb_vm_cref()->nd_visi = (f))
|
173
|
-
|
174
|
-
#define CHECK_STACK_OVERFLOW(cfp, margin) do \
|
175
|
-
if (((VALUE *)(cfp)->sp) + (margin) + sizeof(rb_control_frame_t) >= ((VALUE *)cfp)) { \
|
176
|
-
rb_exc_raise(sysstack_error); \
|
177
|
-
} \
|
178
|
-
while (0)
|
179
|
-
|
180
|
-
void rb_thread_cleanup(void);
|
181
|
-
void rb_thread_wait_other_threads(void);
|
182
|
-
|
183
|
-
enum {
|
184
|
-
RAISED_EXCEPTION = 1,
|
185
|
-
RAISED_STACKOVERFLOW = 2,
|
186
|
-
RAISED_NOMEMORY = 4
|
187
|
-
};
|
188
|
-
int rb_threadptr_set_raised(rb_thread_t *th);
|
189
|
-
int rb_threadptr_reset_raised(rb_thread_t *th);
|
190
|
-
#define rb_thread_raised_set(th, f) ((th)->raised_flag |= (f))
|
191
|
-
#define rb_thread_raised_reset(th, f) ((th)->raised_flag &= ~(f))
|
192
|
-
#define rb_thread_raised_p(th, f) (((th)->raised_flag & (f)) != 0)
|
193
|
-
#define rb_thread_raised_clear(th) ((th)->raised_flag = 0)
|
194
|
-
|
195
|
-
VALUE rb_f_eval(int argc, VALUE *argv, VALUE self);
|
196
|
-
VALUE rb_make_exception(int argc, VALUE *argv);
|
197
|
-
|
198
|
-
NORETURN(void rb_fiber_start(void));
|
199
|
-
|
200
|
-
NORETURN(void rb_print_undef(VALUE, ID, int));
|
201
|
-
NORETURN(void rb_vm_localjump_error(const char *,VALUE, int));
|
202
|
-
NORETURN(void rb_vm_jump_tag_but_local_jump(int, VALUE));
|
203
|
-
NORETURN(void rb_raise_method_missing(rb_thread_t *th, int argc, VALUE *argv,
|
204
|
-
VALUE obj, int call_status));
|
205
|
-
|
206
|
-
VALUE rb_vm_make_jump_tag_but_local_jump(int state, VALUE val);
|
207
|
-
NODE *rb_vm_cref(void);
|
208
|
-
VALUE rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, const rb_block_t *blockptr, VALUE filename, VALUE filepath);
|
209
|
-
void rb_vm_set_progname(VALUE filename);
|
210
|
-
void rb_thread_terminate_all(void);
|
211
|
-
VALUE rb_vm_top_self();
|
212
|
-
VALUE rb_vm_cbase(void);
|
213
|
-
int rb_vm_get_sourceline(const rb_control_frame_t *);
|
214
|
-
void rb_trap_restore_mask(void);
|
215
|
-
|
216
|
-
#ifndef CharNext /* defined as CharNext[AW] on Windows. */
|
217
|
-
#define CharNext(p) ((p) + mblen(p, RUBY_MBCHAR_MAXSIZE))
|
218
|
-
#endif
|
219
|
-
|
220
|
-
#if defined DOSISH || defined __CYGWIN__
|
221
|
-
static inline void
|
222
|
-
translit_char(char *p, int from, int to)
|
223
|
-
{
|
224
|
-
while (*p) {
|
225
|
-
if ((unsigned char)*p == from)
|
226
|
-
*p = to;
|
227
|
-
p = CharNext(p);
|
228
|
-
}
|
229
|
-
}
|
230
|
-
#endif
|
231
|
-
|
232
|
-
#endif /* RUBY_EVAL_INTERN_H */
|