binding_of_caller 0.8.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/test.yml +103 -0
  3. data/.gitignore +12 -7
  4. data/Gemfile +6 -1
  5. data/README.md +14 -5
  6. data/Rakefile +4 -132
  7. data/binding_of_caller.gemspec +33 -37
  8. data/lib/binding_of_caller.rb +7 -8
  9. data/lib/binding_of_caller/{mri2.rb → mri.rb} +0 -0
  10. data/lib/binding_of_caller/version.rb +1 -1
  11. metadata +26 -103
  12. data/.travis.yml +0 -35
  13. data/examples/benchmark.rb +0 -63
  14. data/examples/example.rb +0 -41
  15. data/ext/binding_of_caller/binding_of_caller.c +0 -225
  16. data/ext/binding_of_caller/extconf.rb +0 -28
  17. data/ext/binding_of_caller/ruby_headers/192/debug.h +0 -36
  18. data/ext/binding_of_caller/ruby_headers/192/dln.h +0 -41
  19. data/ext/binding_of_caller/ruby_headers/192/eval_intern.h +0 -232
  20. data/ext/binding_of_caller/ruby_headers/192/id.h +0 -173
  21. data/ext/binding_of_caller/ruby_headers/192/iseq.h +0 -104
  22. data/ext/binding_of_caller/ruby_headers/192/method.h +0 -103
  23. data/ext/binding_of_caller/ruby_headers/192/node.h +0 -483
  24. data/ext/binding_of_caller/ruby_headers/192/regenc.h +0 -211
  25. data/ext/binding_of_caller/ruby_headers/192/regint.h +0 -841
  26. data/ext/binding_of_caller/ruby_headers/192/regparse.h +0 -354
  27. data/ext/binding_of_caller/ruby_headers/192/rubys_gc.h +0 -77
  28. data/ext/binding_of_caller/ruby_headers/192/thread_pthread.h +0 -27
  29. data/ext/binding_of_caller/ruby_headers/192/thread_win32.h +0 -33
  30. data/ext/binding_of_caller/ruby_headers/192/timev.h +0 -21
  31. data/ext/binding_of_caller/ruby_headers/192/transcode_data.h +0 -109
  32. data/ext/binding_of_caller/ruby_headers/192/version.h +0 -55
  33. data/ext/binding_of_caller/ruby_headers/192/vm_core.h +0 -703
  34. data/ext/binding_of_caller/ruby_headers/192/vm_exec.h +0 -184
  35. data/ext/binding_of_caller/ruby_headers/192/vm_insnhelper.h +0 -208
  36. data/ext/binding_of_caller/ruby_headers/192/vm_opts.h +0 -51
  37. data/ext/binding_of_caller/ruby_headers/193/addr2line.h +0 -21
  38. data/ext/binding_of_caller/ruby_headers/193/atomic.h +0 -56
  39. data/ext/binding_of_caller/ruby_headers/193/constant.h +0 -34
  40. data/ext/binding_of_caller/ruby_headers/193/debug.h +0 -41
  41. data/ext/binding_of_caller/ruby_headers/193/dln.h +0 -50
  42. data/ext/binding_of_caller/ruby_headers/193/encdb.h +0 -167
  43. data/ext/binding_of_caller/ruby_headers/193/eval_intern.h +0 -234
  44. data/ext/binding_of_caller/ruby_headers/193/id.h +0 -175
  45. data/ext/binding_of_caller/ruby_headers/193/internal.h +0 -227
  46. data/ext/binding_of_caller/ruby_headers/193/iseq.h +0 -125
  47. data/ext/binding_of_caller/ruby_headers/193/method.h +0 -105
  48. data/ext/binding_of_caller/ruby_headers/193/node.h +0 -503
  49. data/ext/binding_of_caller/ruby_headers/193/parse.h +0 -186
  50. data/ext/binding_of_caller/ruby_headers/193/regenc.h +0 -219
  51. data/ext/binding_of_caller/ruby_headers/193/regint.h +0 -851
  52. data/ext/binding_of_caller/ruby_headers/193/regparse.h +0 -362
  53. data/ext/binding_of_caller/ruby_headers/193/revision.h +0 -1
  54. data/ext/binding_of_caller/ruby_headers/193/rubys_gc.h +0 -98
  55. data/ext/binding_of_caller/ruby_headers/193/thread_pthread.h +0 -51
  56. data/ext/binding_of_caller/ruby_headers/193/thread_win32.h +0 -40
  57. data/ext/binding_of_caller/ruby_headers/193/timev.h +0 -21
  58. data/ext/binding_of_caller/ruby_headers/193/transcode_data.h +0 -117
  59. data/ext/binding_of_caller/ruby_headers/193/transdb.h +0 -189
  60. data/ext/binding_of_caller/ruby_headers/193/version.h +0 -52
  61. data/ext/binding_of_caller/ruby_headers/193/vm_core.h +0 -755
  62. data/ext/binding_of_caller/ruby_headers/193/vm_exec.h +0 -184
  63. data/ext/binding_of_caller/ruby_headers/193/vm_insnhelper.h +0 -220
  64. data/ext/binding_of_caller/ruby_headers/193/vm_opts.h +0 -51
  65. data/test/test_binding_of_caller.rb +0 -161
@@ -1,35 +0,0 @@
1
- rvm:
2
- - 1.9.2
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.0
6
- - 2.2.6
7
- - 2.3.0
8
- - 2.4.0
9
- - 2.5.0
10
-
11
- notifications:
12
- irc: "irc.freenode.org#pry"
13
- recipients:
14
- - jrmair@gmail.com
15
-
16
- branches:
17
- only:
18
- - master
19
-
20
- matrix:
21
- include:
22
- - rvm: jruby
23
- env: JRUBY_OPTS=-X-C
24
- allow_failures:
25
- - rvm: jruby
26
- - rvm: 1.9.3
27
-
28
- #script: rake test --trace
29
- #
30
- before_install:
31
- - gem update --system
32
- # - gem --version
33
- # - gem install rake bacon
34
- # - rake gem
35
- # - gem install pkg/*.gem
@@ -1,63 +0,0 @@
1
- require 'benchmark'
2
-
3
- unless Object.const_defined? :BindingOfCaller
4
- $:.unshift File.expand_path '../../lib', __FILE__
5
- require 'binding_of_caller'
6
- require 'binding_of_caller/version'
7
- end
8
-
9
-
10
- n = 250000
11
-
12
- Benchmark.bm(10) do |x|
13
- x.report("#of_caller") do
14
- 1.upto(n) do
15
- 1.times do
16
- 1.times do
17
- binding.of_caller(2)
18
- binding.of_caller(1)
19
- end
20
- end
21
- end
22
- end
23
-
24
- x.report("#frame_count") do
25
- 1.upto(n) do
26
- 1.times do
27
- 1.times do
28
- binding.frame_count
29
- end
30
- end
31
- end
32
- end
33
-
34
- x.report("#callers") do
35
- 1.upto(n) do
36
- 1.times do
37
- 1.times do
38
- binding.callers
39
- end
40
- end
41
- end
42
- end
43
-
44
- x.report("#frame_description") do
45
- 1.upto(n) do
46
- 1.times do
47
- 1.times do
48
- binding.of_caller(1).frame_description
49
- end
50
- end
51
- end
52
- end
53
-
54
- x.report("#frame_type") do
55
- 1.upto(n) do
56
- 1.times do
57
- 1.times do
58
- binding.of_caller(1).frame_type
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -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 "rubys_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,28 +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_1_9?
8
- defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" &&
9
- RUBY_VERSION =~ /^1\.9/
10
- end
11
-
12
- if mri_1_9?
13
- require 'mkmf'
14
-
15
- $CFLAGS += " -O0"
16
- $CFLAGS += " -std=c99"
17
-
18
- case RUBY_VERSION
19
- when /1.9.2/
20
- $CFLAGS += " -I./ruby_headers/192/ -DRUBY_192"
21
- when /1.9.3/
22
- $CFLAGS += " -I./ruby_headers/193/ -DRUBY_193"
23
- end
24
-
25
- create_makefile('binding_of_caller')
26
- else
27
- fake_makefile
28
- end
@@ -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