binding_of_caller 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +0 -0
- data/README.md +56 -0
- data/Rakefile +99 -0
- data/ext/binding_of_caller/binding_of_caller.c +124 -0
- data/ext/binding_of_caller/compat.h +57 -0
- data/ext/binding_of_caller/extconf.rb +14 -0
- data/ext/binding_of_caller/ruby_headers/192/debug.h +36 -0
- data/ext/binding_of_caller/ruby_headers/192/dln.h +41 -0
- data/ext/binding_of_caller/ruby_headers/192/eval_intern.h +232 -0
- data/ext/binding_of_caller/ruby_headers/192/gc.h +77 -0
- data/ext/binding_of_caller/ruby_headers/192/id.h +173 -0
- data/ext/binding_of_caller/ruby_headers/192/iseq.h +104 -0
- data/ext/binding_of_caller/ruby_headers/192/method.h +103 -0
- data/ext/binding_of_caller/ruby_headers/192/node.h +483 -0
- data/ext/binding_of_caller/ruby_headers/192/regenc.h +211 -0
- data/ext/binding_of_caller/ruby_headers/192/regint.h +841 -0
- data/ext/binding_of_caller/ruby_headers/192/regparse.h +354 -0
- data/ext/binding_of_caller/ruby_headers/192/thread_pthread.h +27 -0
- data/ext/binding_of_caller/ruby_headers/192/thread_win32.h +33 -0
- data/ext/binding_of_caller/ruby_headers/192/timev.h +21 -0
- data/ext/binding_of_caller/ruby_headers/192/transcode_data.h +109 -0
- data/ext/binding_of_caller/ruby_headers/192/version.h +63 -0
- data/ext/binding_of_caller/ruby_headers/192/vm_core.h +703 -0
- data/ext/binding_of_caller/ruby_headers/192/vm_exec.h +184 -0
- data/ext/binding_of_caller/ruby_headers/192/vm_insnhelper.h +208 -0
- data/ext/binding_of_caller/ruby_headers/192/vm_opts.h +51 -0
- data/ext/binding_of_caller/ruby_headers/193/addr2line.h +21 -0
- data/ext/binding_of_caller/ruby_headers/193/atomic.h +56 -0
- data/ext/binding_of_caller/ruby_headers/193/constant.h +34 -0
- data/ext/binding_of_caller/ruby_headers/193/debug.h +41 -0
- data/ext/binding_of_caller/ruby_headers/193/dln.h +50 -0
- data/ext/binding_of_caller/ruby_headers/193/encdb.h +167 -0
- data/ext/binding_of_caller/ruby_headers/193/eval_intern.h +234 -0
- data/ext/binding_of_caller/ruby_headers/193/gc.h +98 -0
- data/ext/binding_of_caller/ruby_headers/193/id.h +175 -0
- data/ext/binding_of_caller/ruby_headers/193/internal.h +227 -0
- data/ext/binding_of_caller/ruby_headers/193/iseq.h +125 -0
- data/ext/binding_of_caller/ruby_headers/193/method.h +105 -0
- data/ext/binding_of_caller/ruby_headers/193/node.h +503 -0
- data/ext/binding_of_caller/ruby_headers/193/parse.h +186 -0
- data/ext/binding_of_caller/ruby_headers/193/regenc.h +219 -0
- data/ext/binding_of_caller/ruby_headers/193/regint.h +851 -0
- data/ext/binding_of_caller/ruby_headers/193/regparse.h +362 -0
- data/ext/binding_of_caller/ruby_headers/193/revision.h +1 -0
- data/ext/binding_of_caller/ruby_headers/193/thread_pthread.h +51 -0
- data/ext/binding_of_caller/ruby_headers/193/thread_win32.h +40 -0
- data/ext/binding_of_caller/ruby_headers/193/timev.h +21 -0
- data/ext/binding_of_caller/ruby_headers/193/transcode_data.h +117 -0
- data/ext/binding_of_caller/ruby_headers/193/transdb.h +189 -0
- data/ext/binding_of_caller/ruby_headers/193/version.h +52 -0
- data/ext/binding_of_caller/ruby_headers/193/vm_core.h +755 -0
- data/ext/binding_of_caller/ruby_headers/193/vm_exec.h +184 -0
- data/ext/binding_of_caller/ruby_headers/193/vm_insnhelper.h +220 -0
- data/ext/binding_of_caller/ruby_headers/193/vm_opts.h +51 -0
- data/lib/binding_of_caller.rb +22 -0
- data/lib/binding_of_caller/version.rb +3 -0
- data/test/test.rb +12 -0
- metadata +120 -0
data/HISTORY
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
binding_of_caller
|
2
|
+
===========
|
3
|
+
|
4
|
+
(C) John Mair (banisterfiend) 2011
|
5
|
+
|
6
|
+
FIXME: _tagline_
|
7
|
+
|
8
|
+
FIXME: _description goes here_
|
9
|
+
|
10
|
+
* 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
|
+
* See the [source code](http://github.com/banister/binding_of_caller)
|
13
|
+
|
14
|
+
Example: Example description
|
15
|
+
--------
|
16
|
+
|
17
|
+
Example preamble
|
18
|
+
|
19
|
+
puts "example code"
|
20
|
+
|
21
|
+
Features and limitations
|
22
|
+
-------------------------
|
23
|
+
|
24
|
+
Feature List Preamble
|
25
|
+
|
26
|
+
Contact
|
27
|
+
-------
|
28
|
+
|
29
|
+
Problems or questions contact me at [github](http://github.com/banister)
|
30
|
+
|
31
|
+
|
32
|
+
License
|
33
|
+
-------
|
34
|
+
|
35
|
+
(The MIT License)
|
36
|
+
|
37
|
+
Copyright (c) 2011 (John Mair)
|
38
|
+
|
39
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
40
|
+
a copy of this software and associated documentation files (the
|
41
|
+
'Software'), to deal in the Software without restriction, including
|
42
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
43
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
44
|
+
permit persons to whom the Software is furnished to do so, subject to
|
45
|
+
the following conditions:
|
46
|
+
|
47
|
+
The above copyright notice and this permission notice shall be
|
48
|
+
included in all copies or substantial portions of the Software.
|
49
|
+
|
50
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
51
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
52
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
53
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
54
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
55
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
56
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,99 @@
|
|
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
|
@@ -0,0 +1,124 @@
|
|
1
|
+
/* (c) 2011 John Mair (banisterfiend), MIT license */
|
2
|
+
|
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;
|
20
|
+
|
21
|
+
static size_t
|
22
|
+
binding_memsize(const void *ptr)
|
23
|
+
{
|
24
|
+
return ptr ? sizeof(rb_binding_t) : 0;
|
25
|
+
}
|
26
|
+
|
27
|
+
static void
|
28
|
+
binding_free(void *ptr)
|
29
|
+
{
|
30
|
+
rb_binding_t *bind;
|
31
|
+
RUBY_FREE_ENTER("binding");
|
32
|
+
if (ptr) {
|
33
|
+
bind = ptr;
|
34
|
+
ruby_xfree(ptr);
|
35
|
+
}
|
36
|
+
RUBY_FREE_LEAVE("binding");
|
37
|
+
}
|
38
|
+
|
39
|
+
static void
|
40
|
+
binding_mark(void *ptr)
|
41
|
+
{
|
42
|
+
rb_binding_t *bind;
|
43
|
+
RUBY_MARK_ENTER("binding");
|
44
|
+
if (ptr) {
|
45
|
+
bind = ptr;
|
46
|
+
RUBY_MARK_UNLESS_NULL(bind->env);
|
47
|
+
RUBY_MARK_UNLESS_NULL(bind->filename);
|
48
|
+
}
|
49
|
+
RUBY_MARK_LEAVE("binding");
|
50
|
+
}
|
51
|
+
|
52
|
+
static const rb_data_type_t binding_data_type = {
|
53
|
+
"binding",
|
54
|
+
binding_mark,
|
55
|
+
binding_free,
|
56
|
+
binding_memsize,
|
57
|
+
};
|
58
|
+
|
59
|
+
static VALUE
|
60
|
+
binding_alloc(VALUE klass)
|
61
|
+
{
|
62
|
+
VALUE obj;
|
63
|
+
rb_binding_t *bind;
|
64
|
+
obj = TypedData_Make_Struct(klass, rb_binding_t, &binding_data_type, bind);
|
65
|
+
return obj;
|
66
|
+
}
|
67
|
+
|
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);
|
72
|
+
}
|
73
|
+
|
74
|
+
static rb_control_frame_t * find_valid_frame(rb_control_frame_t * cfp) {
|
75
|
+
int error_count = 0;
|
76
|
+
|
77
|
+
while (error_count <= 4) {
|
78
|
+
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
|
79
|
+
|
80
|
+
if (valid_frame_p(cfp))
|
81
|
+
return cfp;
|
82
|
+
else
|
83
|
+
error_count += 1;
|
84
|
+
}
|
85
|
+
|
86
|
+
rb_raise(rb_eRuntimeError, "No valid stack frame found.");
|
87
|
+
|
88
|
+
// never reached
|
89
|
+
return 0;
|
90
|
+
}
|
91
|
+
|
92
|
+
static VALUE binding_of_caller(VALUE self, VALUE rb_level)
|
93
|
+
{
|
94
|
+
rb_thread_t *th = GET_THREAD();
|
95
|
+
rb_control_frame_t *cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
|
96
|
+
int level = FIX2INT(rb_level);
|
97
|
+
|
98
|
+
for (int i = 0; i < level; i++)
|
99
|
+
cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
|
100
|
+
|
101
|
+
if (!valid_frame_p(cfp))
|
102
|
+
cfp = find_valid_frame(cfp);
|
103
|
+
|
104
|
+
VALUE bindval = binding_alloc(rb_cBinding);
|
105
|
+
rb_binding_t *bind;
|
106
|
+
|
107
|
+
if (cfp == 0) {
|
108
|
+
rb_raise(rb_eRuntimeError, "Can't create Binding Object on top of Fiber.");
|
109
|
+
}
|
110
|
+
|
111
|
+
GetBindingPtr(bindval, bind);
|
112
|
+
bind->env = rb_vm_make_env_object(th, cfp);
|
113
|
+
bind->filename = cfp->iseq->filename;
|
114
|
+
bind->line_no = rb_vm_get_sourceline(cfp);
|
115
|
+
return bindval;
|
116
|
+
}
|
117
|
+
|
118
|
+
void
|
119
|
+
Init_binding_of_caller()
|
120
|
+
{
|
121
|
+
rb_define_method(rb_cObject, "binding_of_caller", binding_of_caller, 1);
|
122
|
+
|
123
|
+
}
|
124
|
+
|
@@ -0,0 +1,57 @@
|
|
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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
$CFLAGS += " -O0"
|
4
|
+
$CFLAGS += " -std=c99"
|
5
|
+
|
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/"
|
12
|
+
end
|
13
|
+
|
14
|
+
create_makefile('binding_of_caller')
|
@@ -0,0 +1,36 @@
|
|
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 */
|
@@ -0,0 +1,41 @@
|
|
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
|
@@ -0,0 +1,232 @@
|
|
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 */
|