binding_of_caller 0.2.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb405aa7190a04a128baff727db90ef40ae1468c
4
+ data.tar.gz: 43cc746def25b335c279df78b070d926bdb43ebc
5
+ SHA512:
6
+ metadata.gz: 2352e3c209510a9bed92399403425165c3b18bdaa559803d6a042ff5b98b52e70fb9b299236dad9d9895e06b533bcee7a3f1952bd8e7fea972d944b244e8e345
7
+ data.tar.gz: 7e47b06c1867cec238f1a772a8659acc738b328fd4425601b7a0bb7ce55925be0ebbbee43709bc453efef4ba41e989eed560d6ed7232fc030b83b2c17185910a
data/.gemtest ADDED
File without changes
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ Makefile
2
+ *.so
3
+ *.o
4
+ *.def
5
+ doc/
6
+ pkg/
7
+ .yardoc/
data/.travis.yml ADDED
@@ -0,0 +1,22 @@
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/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ License
2
+ -------
3
+
4
+ (The MIT License)
5
+
6
+ Copyright (c) 2011 John Mair (banisterfiend)
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining
9
+ a copy of this software and associated documentation files (the
10
+ 'Software'), to deal in the Software without restriction, including
11
+ without limitation the rights to use, copy, modify, merge, publish,
12
+ distribute, sublicense, and/or sell copies of the Software, and to
13
+ permit persons to whom the Software is furnished to do so, subject to
14
+ the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,27 +1,59 @@
1
+ [![Build Status](https://secure.travis-ci.org/banister/binding_of_caller.png)](http://travis-ci.org/banister/binding_of_caller)
2
+
1
3
  binding_of_caller
2
4
  ===========
3
5
 
4
6
  (C) John Mair (banisterfiend) 2011
5
7
 
6
- FIXME: _tagline_
8
+ _Retrieve the binding of a method's caller in MRI 1.9.2+, and RBX (Rubinius)_
9
+
10
+ The `binding_of_caller` gem provides the `Binding#of_caller` method.
11
+
12
+ Using `binding_of_caller` we can grab bindings from higher up the call
13
+ stack and evaluate code in that context. Allows access to bindings arbitrarily far up the
14
+ call stack, not limited to just the immediate caller.
7
15
 
8
- FIXME: _description goes here_
16
+ **Recommended for use only in debugging situations. Do not use this in production apps.**
17
+
18
+ **Only works in MRI Ruby 1.9.2, 1.9.3 and RBX (Rubinius)**
9
19
 
10
20
  * Install the [gem](https://rubygems.org/gems/binding_of_caller): `gem install binding_of_caller`
11
- * Read the [documentation](http://rdoc.info/github/banister/binding_of_caller/master/file/README.markdown)
12
21
  * See the [source code](http://github.com/banister/binding_of_caller)
13
22
 
14
- Example: Example description
23
+ Example: Modifying a local inside the caller of a caller
15
24
  --------
16
25
 
17
- Example preamble
26
+ ```ruby
27
+ def a
28
+ var = 10
29
+ b
30
+ puts var
31
+ end
32
+
33
+ def b
34
+ c
35
+ end
36
+
37
+ def c
38
+ binding.of_caller(2).eval('var = :hello')
39
+ end
40
+
41
+ a()
42
+
43
+ # OUTPUT
44
+ # => hello
45
+ ```
46
+
47
+ Spinoff project
48
+ -------
18
49
 
19
- puts "example code"
50
+ This project is a spinoff from the [Pry REPL project.](http://pry.github.com)
20
51
 
21
52
  Features and limitations
22
53
  -------------------------
23
54
 
24
- Feature List Preamble
55
+ * Only works with MRI 1.9.2, 1.9.3 and RBX (Rubinius)
56
+ * Does not work in 1.8.7, but there is a well known (continuation-based) hack to get a `Binding#of_caller` there.
25
57
 
26
58
  Contact
27
59
  -------
@@ -32,7 +64,7 @@ Problems or questions contact me at [github](http://github.com/banister)
32
64
  License
33
65
  -------
34
66
 
35
- (The MIT License)
67
+ (The MIT License)
36
68
 
37
69
  Copyright (c) 2011 (John Mair)
38
70
 
data/Rakefile CHANGED
@@ -1,99 +1,134 @@
1
- dlext = Config::CONFIG['DLEXT']
2
- direc = File.dirname(__FILE__)
3
-
4
- PROJECT_NAME = "binding_of_caller"
5
-
6
- require 'rake/clean'
7
- require 'rake/gempackagetask'
8
- require "#{direc}/lib/#{PROJECT_NAME}/version"
9
-
10
- CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
11
- CLEAN.include("ext/**/*.#{dlext}", "ext/**/*.log", "ext/**/*.o",
12
- "ext/**/*~", "ext/**/*#*", "ext/**/*.obj", "**/*#*", "**/*#*.*",
13
- "ext/**/*.def", "ext/**/*.pdb", "**/*_flymake*.*", "**/*_flymake")
14
-
15
- def apply_spec_defaults(s)
16
- s.name = PROJECT_NAME
17
- s.summary = "FIX ME"
18
- s.version = BindingOfCaller::VERSION
19
- s.date = Time.now.strftime '%Y-%m-%d'
20
- s.author = "John Mair (banisterfiend)"
21
- s.email = 'jrmair@gmail.com'
22
- s.description = s.summary
23
- s.require_path = 'lib'
24
- s.add_development_dependency("bacon",">=1.1.0")
25
- s.homepage = "http://banisterfiend.wordpress.com"
26
- s.has_rdoc = 'yard'
27
- s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb",
28
- "test/*.rb", "HISTORY", "README.md", "Rakefile"]
29
- end
30
-
31
- desc "run tests"
32
- task :test do
33
- sh "bacon -k #{direc}/test/test.rb"
34
- end
35
-
36
- [:mingw32, :mswin32].each do |v|
37
- namespace v do
38
- spec = Gem::Specification.new do |s|
39
- apply_spec_defaults(s)
40
- s.platform = "i386-#{v}"
41
- s.files += FileList["lib/**/*.#{dlext}"].to_a
42
- end
43
-
44
- Rake::GemPackageTask.new(spec) do |pkg|
45
- pkg.need_zip = false
46
- pkg.need_tar = false
47
- end
48
- end
49
- end
50
-
51
- namespace :ruby do
52
- spec = Gem::Specification.new do |s|
53
- apply_spec_defaults(s)
54
- s.platform = Gem::Platform::RUBY
55
- s.extensions = ["ext/#{PROJECT_NAME}/extconf.rb"]
56
- end
57
-
58
- Rake::GemPackageTask.new(spec) do |pkg|
59
- pkg.need_zip = false
60
- pkg.need_tar = false
61
- end
62
- end
63
-
64
- directories = ["#{direc}/lib/1.8", "#{direc}/lib/1.9"]
65
- directories.each { |d| directory d }
66
-
67
- desc "build the 1.8 and 1.9 binaries from source and copy to lib/"
68
- task :compile => directories do
69
- build_for = proc do |pik_ver, ver|
70
- sh %{ \
71
- c:\\devkit\\devkitvars.bat && \
72
- pik #{pik_ver} && \
73
- ruby extconf.rb && \
74
- make clean && \
75
- make && \
76
- cp *.so #{direc}/lib/#{ver} \
77
- }
78
- end
79
-
80
- chdir("#{direc}/ext/#{PROJECT_NAME}") do
81
- build_for.call("187", "1.8")
82
- build_for.call("192", "1.9")
83
- end
84
- end
85
-
86
- desc "build all platform gems at once"
87
- task :gems => [:clean, :rmgems, "mingw32:gem", "mswin32:gem", "ruby:gem"]
88
-
89
- desc "remove all platform gems"
90
- task :rmgems => ["ruby:clobber_package"]
91
-
92
- desc "build and push latest gems"
93
- task :pushgems => :gems do
94
- chdir("#{direc}/pkg") do
95
- Dir["*.gem"].each do |gemfile|
96
- sh "gem push #{gemfile}"
97
- end
98
- end
99
- end
1
+ dlext = RbConfig::CONFIG['DLEXT']
2
+ direc = File.dirname(__FILE__)
3
+
4
+ $:.unshift 'lib'
5
+
6
+ require 'rake/clean'
7
+ require 'rubygems/package_task'
8
+
9
+ require "binding_of_caller/version"
10
+
11
+ CLOBBER.include("**/*.#{dlext}", "**/*~", "**/*#*", "**/*.log", "**/*.o")
12
+ CLEAN.include("ext/**/*.#{dlext}", "ext/**/*.log", "ext/**/*.o",
13
+ "ext/**/*~", "ext/**/*#*", "ext/**/*.obj", "**/*#*", "**/*#*.*",
14
+ "ext/**/*.def", "ext/**/*.pdb", "**/*_flymake*.*", "**/*_flymake", "**/*.rbc")
15
+
16
+ def mri_2?
17
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" &&
18
+ RUBY_VERSION =~ /^2/
19
+ end
20
+
21
+ def apply_spec_defaults(s)
22
+ s.name = "binding_of_caller"
23
+ s.summary = "Retrieve the binding of a method's caller. Can also retrieve bindings even further up the stack."
24
+ s.version = BindingOfCaller::VERSION
25
+ s.date = Time.now.strftime '%Y-%m-%d'
26
+ s.author = "John Mair (banisterfiend)"
27
+ s.email = 'jrmair@gmail.com'
28
+ s.description = s.summary
29
+ s.require_path = 'lib'
30
+ s.add_dependency 'debug_inspector', '>= 0.0.1'
31
+ s.add_development_dependency 'bacon'
32
+ s.add_development_dependency 'rake'
33
+ s.homepage = "http://github.com/banister/binding_of_caller"
34
+ s.has_rdoc = 'yard'
35
+ s.files = `git ls-files`.split("\n")
36
+ s.test_files = `git ls-files -- test/*`.split("\n")
37
+ end
38
+
39
+ desc "Show version"
40
+ task :version do
41
+ puts "BindingOfCaller version: #{BindingOfCaller::VERSION}"
42
+ end
43
+
44
+ desc "run tests"
45
+ task :default => [:test]
46
+
47
+ desc "Run tests"
48
+ task :test do
49
+ unless defined?(Rubinius)
50
+ Rake::Task['compile'].execute
51
+ end
52
+
53
+ $stdout.puts("\033[33m")
54
+ sh "bacon -Itest -rubygems -a -q"
55
+ $stdout.puts("\033[0m")
56
+
57
+ unless defined?(Rubinius)
58
+ Rake::Task['cleanup'].execute
59
+ end
60
+ end
61
+
62
+ task :pry do
63
+ puts "loading binding_of_caller into pry"
64
+ sh "pry -r ./lib/binding_of_caller"
65
+ end
66
+
67
+ desc "generate gemspec"
68
+ task :gemspec => "ruby:gemspec"
69
+
70
+ namespace :ruby do
71
+ spec = Gem::Specification.new do |s|
72
+ apply_spec_defaults(s)
73
+ s.platform = Gem::Platform::RUBY
74
+ s.extensions = ["ext/binding_of_caller/extconf.rb"]
75
+ end
76
+
77
+ Gem::PackageTask.new(spec) do |pkg|
78
+ pkg.need_zip = false
79
+ pkg.need_tar = false
80
+ end
81
+
82
+ desc "Generate gemspec file"
83
+ task :gemspec do
84
+ File.open("#{spec.name}.gemspec", "w") do |f|
85
+ f << spec.to_ruby
86
+ end
87
+ end
88
+ end
89
+
90
+ desc "build the binaries"
91
+ task :compile => :cleanup do
92
+ if !mri_2?
93
+ chdir "./ext/binding_of_caller/" do
94
+ sh "ruby extconf.rb"
95
+ sh "make"
96
+ sh "cp *.#{dlext} ../../lib/"
97
+ end
98
+ end
99
+ end
100
+
101
+ desc 'cleanup the extensions'
102
+ task :cleanup do
103
+ if !mri_2?
104
+ sh 'rm -rf lib/binding_of_caller.so'
105
+ chdir "./ext/binding_of_caller/" do
106
+ sh 'make clean'
107
+ end
108
+ end
109
+ end
110
+
111
+ desc "reinstall gem"
112
+ task :reinstall => :gems do
113
+ sh "gem uninstall binding_of_caller" rescue nil
114
+ sh "gem install #{direc}/pkg/binding_of_caller-#{BindingOfCaller::VERSION}.gem"
115
+ end
116
+
117
+ task :install => :reinstall
118
+
119
+ desc "build all platform gems at once"
120
+ task :gems => [:clean, :rmgems, "ruby:gem"]
121
+
122
+ task :gem => [:gems]
123
+
124
+ desc "remove all platform gems"
125
+ task :rmgems => ["ruby:clobber_package"]
126
+
127
+ desc "build and push latest gems"
128
+ task :pushgems => :gems do
129
+ chdir("./pkg") do
130
+ Dir["*.gem"].each do |gemfile|
131
+ sh "gem push #{gemfile}"
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "binding_of_caller"
5
+ s.version = "0.6.9"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["John Mair (banisterfiend)"]
9
+ s.date = "2013-02-14"
10
+ s.description = "Retrieve the binding of a method's caller. Can also retrieve bindings even further up the stack."
11
+ s.email = "jrmair@gmail.com"
12
+ s.extensions = ["ext/binding_of_caller/extconf.rb"]
13
+ s.files = [".gemtest", ".gitignore", ".travis.yml", ".yardopts", "Gemfile", "HISTORY", "LICENSE", "README.md", "Rakefile", "binding_of_caller.gemspec", "examples/example.rb", "ext/binding_of_caller/binding_of_caller.c", "ext/binding_of_caller/extconf.rb", "ext/binding_of_caller/ruby_headers/192/debug.h", "ext/binding_of_caller/ruby_headers/192/dln.h", "ext/binding_of_caller/ruby_headers/192/eval_intern.h", "ext/binding_of_caller/ruby_headers/192/gc.h", "ext/binding_of_caller/ruby_headers/192/id.h", "ext/binding_of_caller/ruby_headers/192/iseq.h", "ext/binding_of_caller/ruby_headers/192/method.h", "ext/binding_of_caller/ruby_headers/192/node.h", "ext/binding_of_caller/ruby_headers/192/regenc.h", "ext/binding_of_caller/ruby_headers/192/regint.h", "ext/binding_of_caller/ruby_headers/192/regparse.h", "ext/binding_of_caller/ruby_headers/192/thread_pthread.h", "ext/binding_of_caller/ruby_headers/192/thread_win32.h", "ext/binding_of_caller/ruby_headers/192/timev.h", "ext/binding_of_caller/ruby_headers/192/transcode_data.h", "ext/binding_of_caller/ruby_headers/192/version.h", "ext/binding_of_caller/ruby_headers/192/vm_core.h", "ext/binding_of_caller/ruby_headers/192/vm_exec.h", "ext/binding_of_caller/ruby_headers/192/vm_insnhelper.h", "ext/binding_of_caller/ruby_headers/192/vm_opts.h", "ext/binding_of_caller/ruby_headers/193/addr2line.h", "ext/binding_of_caller/ruby_headers/193/atomic.h", "ext/binding_of_caller/ruby_headers/193/constant.h", "ext/binding_of_caller/ruby_headers/193/debug.h", "ext/binding_of_caller/ruby_headers/193/dln.h", "ext/binding_of_caller/ruby_headers/193/encdb.h", "ext/binding_of_caller/ruby_headers/193/eval_intern.h", "ext/binding_of_caller/ruby_headers/193/gc.h", "ext/binding_of_caller/ruby_headers/193/id.h", "ext/binding_of_caller/ruby_headers/193/internal.h", "ext/binding_of_caller/ruby_headers/193/iseq.h", "ext/binding_of_caller/ruby_headers/193/method.h", "ext/binding_of_caller/ruby_headers/193/node.h", "ext/binding_of_caller/ruby_headers/193/parse.h", "ext/binding_of_caller/ruby_headers/193/regenc.h", "ext/binding_of_caller/ruby_headers/193/regint.h", "ext/binding_of_caller/ruby_headers/193/regparse.h", "ext/binding_of_caller/ruby_headers/193/revision.h", "ext/binding_of_caller/ruby_headers/193/thread_pthread.h", "ext/binding_of_caller/ruby_headers/193/thread_win32.h", "ext/binding_of_caller/ruby_headers/193/timev.h", "ext/binding_of_caller/ruby_headers/193/transcode_data.h", "ext/binding_of_caller/ruby_headers/193/transdb.h", "ext/binding_of_caller/ruby_headers/193/version.h", "ext/binding_of_caller/ruby_headers/193/vm_core.h", "ext/binding_of_caller/ruby_headers/193/vm_exec.h", "ext/binding_of_caller/ruby_headers/193/vm_insnhelper.h", "ext/binding_of_caller/ruby_headers/193/vm_opts.h", "lib/binding_of_caller.rb", "lib/binding_of_caller/mri2.rb", "lib/binding_of_caller/rubinius.rb", "lib/binding_of_caller/version.rb", "test/test_binding_of_caller.rb"]
14
+ s.homepage = "http://github.com/banister/binding_of_caller"
15
+ s.require_paths = ["lib"]
16
+ s.rubygems_version = "2.0.0.rc.2"
17
+ s.summary = "Retrieve the binding of a method's caller. Can also retrieve bindings even further up the stack."
18
+ s.test_files = ["test/test_binding_of_caller.rb"]
19
+
20
+ if s.respond_to? :specification_version then
21
+ s.specification_version = 4
22
+
23
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
24
+ s.add_runtime_dependency(%q<debug_inspector>, [">= 0.0.1"])
25
+ s.add_development_dependency(%q<bacon>, [">= 0"])
26
+ s.add_development_dependency(%q<rake>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<debug_inspector>, [">= 0.0.1"])
29
+ s.add_dependency(%q<bacon>, [">= 0"])
30
+ s.add_dependency(%q<rake>, [">= 0"])
31
+ end
32
+ else
33
+ s.add_dependency(%q<debug_inspector>, [">= 0.0.1"])
34
+ s.add_dependency(%q<bacon>, [">= 0"])
35
+ s.add_dependency(%q<rake>, [">= 0"])
36
+ end
37
+ end
@@ -0,0 +1,41 @@
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,22 +1,32 @@
1
1
  /* (c) 2011 John Mair (banisterfiend), MIT license */
2
2
 
3
3
  #include <ruby.h>
4
- //#include "compat.h"
5
-
6
- //#ifdef RUBY_19
7
- # include <ruby/io.h>
8
- # include <ruby/re.h>
9
- # include "vm_core.h"
10
- # include "gc.h"
11
- /* #else */
12
- /* # include "re.h" */
13
- /* # include "env.h" */
14
- /* # include "node.h" */
15
- /* # include "rubysig.h" */
16
- /* # include "rubyio.h" */
17
- /* #endif */
18
-
19
- extern rb_thread_t *ruby_current_thread;
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()))
20
30
 
21
31
  static size_t
22
32
  binding_memsize(const void *ptr)
@@ -44,7 +54,11 @@ binding_mark(void *ptr)
44
54
  if (ptr) {
45
55
  bind = ptr;
46
56
  RUBY_MARK_UNLESS_NULL(bind->env);
57
+
58
+ #ifdef RUBY_192
47
59
  RUBY_MARK_UNLESS_NULL(bind->filename);
60
+ #endif
61
+
48
62
  }
49
63
  RUBY_MARK_LEAVE("binding");
50
64
  }
@@ -65,60 +79,147 @@ binding_alloc(VALUE klass)
65
79
  return obj;
66
80
  }
67
81
 
68
- typedef enum { false, true } bool;
69
-
70
- static bool valid_frame_p(rb_control_frame_t * cfp) {
71
- return cfp->iseq && !NIL_P(cfp->self);
82
+ static bool ifunc_p(rb_control_frame_t * cfp) {
83
+ return (cfp->flag & VM_FRAME_MAGIC_MASK) == VM_FRAME_MAGIC_IFUNC;
72
84
  }
73
85
 
74
- static rb_control_frame_t * find_valid_frame(rb_control_frame_t * cfp) {
75
- int error_count = 0;
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
+ }
76
89
 
77
- while (error_count <= 4) {
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) {
78
92
  cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
79
93
 
80
- if (valid_frame_p(cfp))
94
+ if (cfp >= limit_cfp)
95
+ return NULL;
96
+
97
+ if (valid_frame_p(cfp, limit_cfp))
81
98
  return cfp;
82
- else
83
- error_count += 1;
84
99
  }
85
100
 
86
- rb_raise(rb_eRuntimeError, "No valid stack frame found.");
101
+ // beyond end of stack
102
+ return NULL;
103
+ }
87
104
 
88
- // never reached
89
- return 0;
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
+ }
90
121
  }
91
122
 
92
123
  static VALUE binding_of_caller(VALUE self, VALUE rb_level)
93
124
  {
94
- rb_thread_t *th = GET_THREAD();
125
+ rb_thread_t *th;
126
+ GetThreadPtr(rb_thread_current(), th);
127
+
95
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);
96
130
  int level = FIX2INT(rb_level);
97
131
 
98
- for (int i = 0; i < level; i++)
132
+ // attempt to locate the nth parent control frame
133
+ for (int i = 0; i < level; i++) {
99
134
  cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
100
135
 
101
- if (!valid_frame_p(cfp))
102
- cfp = find_valid_frame(cfp);
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
+ }
103
143
 
104
144
  VALUE bindval = binding_alloc(rb_cBinding);
105
145
  rb_binding_t *bind;
106
146
 
107
- if (cfp == 0) {
147
+ if (cfp == 0)
108
148
  rb_raise(rb_eRuntimeError, "Can't create Binding Object on top of Fiber.");
109
- }
110
149
 
111
150
  GetBindingPtr(bindval, bind);
151
+
112
152
  bind->env = rb_vm_make_env_object(th, cfp);
113
153
  bind->filename = cfp->iseq->filename;
114
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
+
115
159
  return bindval;
116
160
  }
117
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
+
118
213
  void
119
214
  Init_binding_of_caller()
120
215
  {
121
- rb_define_method(rb_cObject, "binding_of_caller", binding_of_caller, 1);
122
-
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);
123
224
  }
124
225
 
@@ -1,14 +1,33 @@
1
- require 'mkmf'
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"
2
23
 
3
- $CFLAGS += " -O0"
4
- $CFLAGS += " -std=c99"
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
5
30
 
6
- case RUBY_VERSION
7
- when /1.9.2/
8
- $CFLAGS += " -I./ruby_headers/192/"
9
- when /1.9.3/
10
- puts "hit 193"
11
- $CFLAGS += " -I./ruby_headers/193/"
31
+ create_makefile('binding_of_caller')
12
32
  end
13
33
 
14
- create_makefile('binding_of_caller')
@@ -0,0 +1,69 @@
1
+ require 'debug_inspector'
2
+
3
+ module BindingOfCaller
4
+ module BindingExtensions
5
+ # Retrieve the binding of the nth caller of the current frame.
6
+ # @return [Binding]
7
+ def of_caller(n)
8
+ c = callers.drop(1)
9
+ if n > (c.size - 1)
10
+ raise "No such frame, gone beyond end of stack!"
11
+ else
12
+ c[n]
13
+ end
14
+ end
15
+
16
+ # Return bindings for all caller frames.
17
+ # @return [Array<Binding>]
18
+ def callers
19
+ ary = []
20
+
21
+ RubyVM::DebugInspector.open do |i|
22
+ n = 0
23
+ loop do
24
+ begin
25
+ b = i.frame_binding(n)
26
+
27
+ if b
28
+ iseq = i.frame_iseq(n)
29
+ b.instance_variable_set(:@iseq, iseq)
30
+ ary << b
31
+ end
32
+ rescue ArgumentError
33
+ break
34
+ end
35
+ n += 1
36
+ end
37
+ end
38
+
39
+ ary.drop(1)
40
+ end
41
+
42
+ # Number of parent frames available at the point of call.
43
+ # @return [Fixnum]
44
+ def frame_count
45
+ callers.size - 1
46
+ end
47
+
48
+ # The type of the frame.
49
+ # @return [Symbol]
50
+ def frame_type
51
+ return nil if !@iseq
52
+
53
+ # apparently the 9th element of the iseq array holds the frame type
54
+ # ...not sure how reliable this is.
55
+ @frame_type ||= @iseq.to_a[9]
56
+ end
57
+
58
+ # The description of the frame.
59
+ # @return [String]
60
+ def frame_description
61
+ return nil if !@iseq
62
+ @frame_description ||= @iseq.label
63
+ end
64
+ end
65
+ end
66
+
67
+ class ::Binding
68
+ include BindingOfCaller::BindingExtensions
69
+ end
@@ -0,0 +1,77 @@
1
+ module BindingOfCaller
2
+ module BindingExtensions
3
+
4
+ # Retrieve the binding of the nth caller of the current frame.
5
+ # @return [Binding]
6
+ def of_caller(n)
7
+ bt = Rubinius::VM.backtrace(1 + n, true).first
8
+
9
+ b = Binding.setup(
10
+ bt.variables,
11
+ bt.variables.method,
12
+ bt.static_scope,
13
+ bt.variables.self,
14
+ bt
15
+ )
16
+
17
+ b.instance_variable_set(:@frame_description, bt.describe)
18
+
19
+ b
20
+ rescue
21
+ raise RuntimeError, "Invalid frame, gone beyond end of stack!"
22
+ end
23
+
24
+ # The description of the frame.
25
+ # @return [String]
26
+ def frame_description
27
+ @frame_description
28
+ end
29
+
30
+ # Return bindings for all caller frames.
31
+ # @return [Array<Binding>]
32
+ def callers
33
+ ary = []
34
+ n = 0
35
+ loop do
36
+ begin
37
+ ary << Binding.of_caller(n)
38
+ rescue
39
+ break
40
+ end
41
+ n += 1
42
+ end
43
+ ary.drop_while do |v|
44
+ !(v.frame_type == :method && v.eval("__method__") == :callers)
45
+ end.drop(1)
46
+ end
47
+
48
+ # Number of parent frames available at the point of call.
49
+ # @return [Fixnum]
50
+ def frame_count
51
+ callers.size - 1
52
+ end
53
+
54
+ # The type of the frame.
55
+ # @return [Symbol]
56
+ def frame_type
57
+ case self.variables.method.metadata.to_a.first.to_s
58
+ when /block/
59
+ :block
60
+ when /eval/
61
+ :eval
62
+ else
63
+ if frame_description =~ /__(?:class|module)_init__/
64
+ :class
65
+ else
66
+ :method
67
+ end
68
+ end
69
+ end
70
+
71
+ end
72
+ end
73
+
74
+ class ::Binding
75
+ include BindingOfCaller::BindingExtensions
76
+ extend BindingOfCaller::BindingExtensions
77
+ end
@@ -1,3 +1,3 @@
1
- module BindingOfCaller
2
- VERSION = "0.2.0"
3
- end
1
+ module BindingOfCaller
2
+ VERSION = "0.7.1"
3
+ end
@@ -1,22 +1,14 @@
1
- # binding_of_caller.rb
2
- # (C) John Mair (banisterfiend); MIT license
1
+ dlext = RbConfig::CONFIG['DLEXT']
3
2
 
4
- direc = File.dirname(__FILE__)
5
-
6
- require "#{direc}/binding_of_caller/version"
7
-
8
- begin
9
- if RUBY_VERSION =~ /1.9/
10
- require "#{direc}/1.9/binding_of_caller"
11
- else
12
- require "#{direc}/1.8/binding_of_caller"
13
- end
14
- rescue LoadError => e
15
- require "rbconfig"
16
- dlext = Config::CONFIG['DLEXT']
17
- require "#{direc}/binding_of_caller.#{dlext}"
3
+ def mri_2?
4
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" &&
5
+ RUBY_VERSION =~ /^2/
18
6
  end
19
7
 
20
- module BindingOfCaller
21
- end
22
-
8
+ if mri_2?
9
+ require 'binding_of_caller/mri2'
10
+ elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
11
+ require "binding_of_caller.#{dlext}"
12
+ elsif defined?(Rubinius)
13
+ require 'binding_of_caller/rubinius'
14
+ end
@@ -0,0 +1,149 @@
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
+ class Module
8
+ public :remove_const
9
+ end
10
+
11
+ puts "Testing binding_of_caller version #{BindingOfCaller::VERSION}..."
12
+ puts "Ruby version: #{RUBY_VERSION}"
13
+
14
+ describe BindingOfCaller do
15
+ describe "of_caller" do
16
+ it "should fetch immediate caller's binding when 0 is passed" do
17
+ o = Object.new
18
+ def o.a
19
+ var = 1
20
+ binding.of_caller(0).eval('var')
21
+ end
22
+
23
+ o. a.should == 1
24
+ end
25
+
26
+ it "should fetch parent of caller's binding when 1 is passed" do
27
+ o = Object.new
28
+ def o.a
29
+ var = 1
30
+ b
31
+ end
32
+
33
+ def o.b
34
+ binding.of_caller(1).eval('var')
35
+ end
36
+
37
+ o.a.should == 1
38
+ end
39
+
40
+ it "should modify locals in parent of caller's binding" do
41
+ o = Object.new
42
+ def o.a
43
+ var = 1
44
+ b
45
+ var
46
+ end
47
+
48
+ def o.b
49
+ binding.of_caller(1).eval('var = 20')
50
+ end
51
+
52
+ o.a.should == 20
53
+ end
54
+
55
+ it "should raise an exception when retrieving an out of band binding" do
56
+ o = Object.new
57
+ def o.a
58
+ binding.of_caller(100)
59
+ end
60
+
61
+ lambda { o.a }.should.raise RuntimeError
62
+ end
63
+ end
64
+
65
+ describe "callers" do
66
+ before do
67
+ @o = Object.new
68
+ end
69
+
70
+ it 'should return the first non-internal binding when using callers.first' do
71
+ def @o.meth
72
+ x = :a_local
73
+ [binding.callers.first, binding.of_caller(0)]
74
+ end
75
+
76
+ b1, b2 = @o.meth
77
+ b1.eval("x").should == :a_local
78
+ b2.eval("x").should == :a_local
79
+ end
80
+ end
81
+
82
+ describe "frame_count" do
83
+ it 'frame_count should equal callers.count' do
84
+ binding.frame_count.should == binding.callers.count
85
+ end
86
+ end
87
+
88
+ describe "frame_descripton" do
89
+ it 'can be called on ordinary binding without raising' do
90
+ lambda { binding.frame_description }.should.not.raise
91
+ end
92
+
93
+ it 'describes a block frame' do
94
+ binding.of_caller(0).frame_description.should =~ /block/
95
+ end
96
+
97
+ it 'describes a method frame' do
98
+ o = Object.new
99
+ def o.horsey_malone
100
+ binding.of_caller(0).frame_description.should =~ /horsey_malone/
101
+ end
102
+ o.horsey_malone
103
+ end
104
+
105
+ it 'describes a class frame' do
106
+ class HorseyMalone
107
+ binding.of_caller(0).frame_description.should =~ /class/
108
+ end
109
+ Object.remove_const(:HorseyMalone)
110
+ end
111
+ end
112
+
113
+ describe "frame_type" do
114
+ it 'can be called on ordinary binding without raising' do
115
+ lambda { binding.frame_type }.should.not.raise
116
+ end
117
+
118
+ it 'should return the correct frame types' do
119
+ o = Object.new
120
+
121
+ # method frame
122
+ def o.a
123
+ b
124
+ end
125
+
126
+ # method frame
127
+ def o.b
128
+ # block frame
129
+ proc do
130
+ binding.callers
131
+ end.call
132
+ end
133
+ caller_bindings = o.a
134
+ caller_bindings[0].frame_type.should == :block
135
+ caller_bindings[1].frame_type.should == :method
136
+ caller_bindings[2].frame_type.should == :method
137
+ end
138
+
139
+ it 'identifies a class frame' do
140
+ class HorseyMalone
141
+ binding.of_caller(0).frame_type.should == :class
142
+ end
143
+
144
+ Object.remove_const(:HorseyMalone)
145
+ end
146
+
147
+ end
148
+ end
149
+
metadata CHANGED
@@ -1,39 +1,78 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: binding_of_caller
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.1
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - John Mair (banisterfiend)
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2011-10-17 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2013-02-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: debug_inspector
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.1
27
+ - !ruby/object:Gem::Dependency
16
28
  name: bacon
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
17
35
  prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 1.1.0
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
24
48
  type: :development
25
- version_requirements: *id001
26
- description: FIX ME
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Retrieve the binding of a method's caller. Can also retrieve bindings
56
+ even further up the stack.
27
57
  email: jrmair@gmail.com
28
58
  executables: []
29
-
30
- extensions:
59
+ extensions:
31
60
  - ext/binding_of_caller/extconf.rb
32
61
  extra_rdoc_files: []
33
-
34
- files:
62
+ files:
63
+ - .gemtest
64
+ - .gitignore
65
+ - .travis.yml
66
+ - .yardopts
67
+ - Gemfile
68
+ - HISTORY
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - binding_of_caller.gemspec
73
+ - examples/example.rb
74
+ - ext/binding_of_caller/binding_of_caller.c
35
75
  - ext/binding_of_caller/extconf.rb
36
- - ext/binding_of_caller/compat.h
37
76
  - ext/binding_of_caller/ruby_headers/192/debug.h
38
77
  - ext/binding_of_caller/ruby_headers/192/dln.h
39
78
  - ext/binding_of_caller/ruby_headers/192/eval_intern.h
@@ -82,39 +121,34 @@ files:
82
121
  - ext/binding_of_caller/ruby_headers/193/vm_exec.h
83
122
  - ext/binding_of_caller/ruby_headers/193/vm_insnhelper.h
84
123
  - ext/binding_of_caller/ruby_headers/193/vm_opts.h
85
- - ext/binding_of_caller/binding_of_caller.c
86
- - lib/binding_of_caller/version.rb
87
124
  - lib/binding_of_caller.rb
88
- - test/test.rb
89
- - HISTORY
90
- - README.md
91
- - Rakefile
92
- homepage: http://banisterfiend.wordpress.com
125
+ - lib/binding_of_caller/mri2.rb
126
+ - lib/binding_of_caller/rubinius.rb
127
+ - lib/binding_of_caller/version.rb
128
+ - test/test_binding_of_caller.rb
129
+ homepage: http://github.com/banister/binding_of_caller
93
130
  licenses: []
94
-
131
+ metadata: {}
95
132
  post_install_message:
96
133
  rdoc_options: []
97
-
98
- require_paths:
134
+ require_paths:
99
135
  - lib
100
- required_ruby_version: !ruby/object:Gem::Requirement
101
- none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- version: "0"
106
- required_rubygems_version: !ruby/object:Gem::Requirement
107
- none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- version: "0"
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
112
146
  requirements: []
113
-
114
147
  rubyforge_project:
115
- rubygems_version: 1.8.11
148
+ rubygems_version: 2.0.0.rc.2
116
149
  signing_key:
117
- specification_version: 3
118
- summary: FIX ME
119
- test_files: []
120
-
150
+ specification_version: 4
151
+ summary: Retrieve the binding of a method's caller. Can also retrieve bindings even
152
+ further up the stack.
153
+ test_files:
154
+ - test/test_binding_of_caller.rb
@@ -1,57 +0,0 @@
1
- /* contains basic macros to facilitate ruby 1.8 and ruby 1.9 compatibility */
2
-
3
- #ifndef GUARD_COMPAT_H
4
- #define GUARD_COMPAT_H
5
-
6
- #include <ruby.h>
7
-
8
- /* test for 1.9 */
9
- #if !defined(RUBY_19) && defined(ROBJECT_EMBED_LEN_MAX)
10
- # define RUBY_19
11
- #endif
12
-
13
- /* macros for backwards compatibility with 1.8 */
14
- #ifndef RUBY_19
15
- # define RCLASS_M_TBL(c) (RCLASS(c)->m_tbl)
16
- # define RCLASS_SUPER(c) (RCLASS(c)->super)
17
- # define RCLASS_IV_TBL(c) (RCLASS(c)->iv_tbl)
18
- # define OBJ_UNTRUSTED OBJ_TAINTED
19
- # include "st.h"
20
- #endif
21
-
22
- #ifdef RUBY_19
23
- inline static VALUE
24
- class_alloc(VALUE flags, VALUE klass)
25
- {
26
- rb_classext_t *ext = ALLOC(rb_classext_t);
27
- NEWOBJ(obj, struct RClass);
28
- OBJSETUP(obj, klass, flags);
29
- obj->ptr = ext;
30
- RCLASS_IV_TBL(obj) = 0;
31
- RCLASS_M_TBL(obj) = 0;
32
- RCLASS_SUPER(obj) = 0;
33
- RCLASS_IV_INDEX_TBL(obj) = 0;
34
- return (VALUE)obj;
35
- }
36
- #endif
37
-
38
- inline static VALUE
39
- create_class(VALUE flags, VALUE klass)
40
- {
41
- #ifdef RUBY_19
42
- VALUE new_klass = class_alloc(flags, klass);
43
- #else
44
- NEWOBJ(new_klass, struct RClass);
45
- OBJSETUP(new_klass, klass, flags);
46
- #endif
47
-
48
- return (VALUE)new_klass;
49
- }
50
-
51
- # define FALSE 0
52
- # define TRUE 1
53
-
54
- /* a useful macro. cannot use ordinary CLASS_OF as it does not return an lvalue */
55
- #define KLASS_OF(c) (RBASIC(c)->klass)
56
-
57
- #endif
data/test/test.rb DELETED
@@ -1,12 +0,0 @@
1
- direc = File.dirname(__FILE__)
2
-
3
- require 'rubygems'
4
- require "#{direc}/../lib/binding_of_caller"
5
- require 'bacon'
6
-
7
- puts "Testing binding_of_caller version #{BindingOfCaller::VERSION}..."
8
- puts "Ruby version: #{RUBY_VERSION}"
9
-
10
- describe BindingOfCaller do
11
- end
12
-