ruby18_source_location 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/extconf.rb +7 -0
- data/ext/ruby18_source_location.c +147 -0
- metadata +65 -0
data/ext/extconf.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
// Include the Ruby headers and goodies
|
2
|
+
#include "ruby.h"
|
3
|
+
|
4
|
+
typedef struct RNode {
|
5
|
+
unsigned long flags;
|
6
|
+
char *nd_file;
|
7
|
+
union {
|
8
|
+
struct RNode *node;
|
9
|
+
ID id;
|
10
|
+
VALUE value;
|
11
|
+
VALUE (*cfunc)(ANYARGS);
|
12
|
+
ID *tbl;
|
13
|
+
} u1;
|
14
|
+
union {
|
15
|
+
struct RNode *node;
|
16
|
+
ID id;
|
17
|
+
long argc;
|
18
|
+
VALUE value;
|
19
|
+
} u2;
|
20
|
+
union {
|
21
|
+
struct RNode *node;
|
22
|
+
ID id;
|
23
|
+
long state;
|
24
|
+
struct global_entry *entry;
|
25
|
+
long cnt;
|
26
|
+
VALUE value;
|
27
|
+
} u3;
|
28
|
+
} NODE;
|
29
|
+
|
30
|
+
struct FRAME {
|
31
|
+
VALUE self;
|
32
|
+
int argc;
|
33
|
+
ID last_func;
|
34
|
+
ID orig_func;
|
35
|
+
VALUE last_class;
|
36
|
+
struct FRAME *prev;
|
37
|
+
struct FRAME *tmp;
|
38
|
+
struct RNode *node;
|
39
|
+
int iter;
|
40
|
+
int flags;
|
41
|
+
unsigned long uniq;
|
42
|
+
} *ruby_frame;
|
43
|
+
|
44
|
+
struct METHOD {
|
45
|
+
VALUE klass, rklass;
|
46
|
+
VALUE recv;
|
47
|
+
ID id, oid;
|
48
|
+
int safe_level;
|
49
|
+
NODE *body;
|
50
|
+
};
|
51
|
+
|
52
|
+
struct BLOCK {
|
53
|
+
NODE *var;
|
54
|
+
NODE *body;
|
55
|
+
VALUE self;
|
56
|
+
struct FRAME frame;
|
57
|
+
struct SCOPE *scope;
|
58
|
+
VALUE klass;
|
59
|
+
NODE *cref;
|
60
|
+
int iter;
|
61
|
+
int vmode;
|
62
|
+
int flags;
|
63
|
+
int uniq;
|
64
|
+
struct RVarmap *dyna_vars;
|
65
|
+
VALUE orig_thread;
|
66
|
+
VALUE wrapper;
|
67
|
+
VALUE block_obj;
|
68
|
+
struct BLOCK *outer;
|
69
|
+
struct BLOCK *prev;
|
70
|
+
};
|
71
|
+
#define RNODE(obj) (R_CAST(RNode)(obj))
|
72
|
+
#define NODE_LSHIFT (FL_USHIFT+8)
|
73
|
+
#define NODE_LMASK (((long)1<<(sizeof(NODE*)*CHAR_BIT-NODE_LSHIFT))-1)
|
74
|
+
#define nd_line(n) ((unsigned int)(((RNODE(n))->flags>>NODE_LSHIFT)&NODE_LMASK))
|
75
|
+
|
76
|
+
|
77
|
+
static VALUE
|
78
|
+
source_pair(const char *filename, int lineno)
|
79
|
+
{
|
80
|
+
VALUE array = rb_ary_new();
|
81
|
+
rb_ary_push(array, rb_str_new2(filename));
|
82
|
+
rb_ary_push(array, INT2FIX(lineno));
|
83
|
+
|
84
|
+
return array;
|
85
|
+
}
|
86
|
+
|
87
|
+
static VALUE
|
88
|
+
node_source_location(NODE *node)
|
89
|
+
{
|
90
|
+
const char *filename = node->nd_file;
|
91
|
+
int lineno = nd_line(node);
|
92
|
+
|
93
|
+
if (filename && lineno)
|
94
|
+
return source_pair(filename, lineno);
|
95
|
+
|
96
|
+
return Qnil;
|
97
|
+
}
|
98
|
+
|
99
|
+
/*
|
100
|
+
* call-seq:
|
101
|
+
* meth.source_location => [String, Fixnum]
|
102
|
+
*
|
103
|
+
* returns a pair of the Filename and line number on which the method is defined
|
104
|
+
*
|
105
|
+
* returns nil if method has no associated ruby source code
|
106
|
+
*/
|
107
|
+
static VALUE
|
108
|
+
method_source_location(VALUE method)
|
109
|
+
{
|
110
|
+
struct METHOD *data;
|
111
|
+
NODE *node;
|
112
|
+
|
113
|
+
Data_Get_Struct(method, struct METHOD, data);
|
114
|
+
if (node = data->body) {
|
115
|
+
return node_source_location(node);
|
116
|
+
}
|
117
|
+
return Qnil;
|
118
|
+
}
|
119
|
+
|
120
|
+
/*
|
121
|
+
* call-seq:
|
122
|
+
* meth.source_location => [String, Fixnum]
|
123
|
+
*
|
124
|
+
* returns a pair of the Filename and line number on which the method is defined
|
125
|
+
*
|
126
|
+
* returns nil if method has no associated ruby source code
|
127
|
+
*/
|
128
|
+
static VALUE
|
129
|
+
proc_source_location(VALUE block)
|
130
|
+
{
|
131
|
+
struct BLOCK *data;
|
132
|
+
NODE *node;
|
133
|
+
|
134
|
+
Data_Get_Struct(block, struct BLOCK, data);
|
135
|
+
if ((node = data->frame.node) || (node = data->body)) {
|
136
|
+
return node_source_location(node);
|
137
|
+
}
|
138
|
+
return Qnil;
|
139
|
+
}
|
140
|
+
|
141
|
+
void
|
142
|
+
Init_ruby18_source_location()
|
143
|
+
{
|
144
|
+
rb_define_method(rb_cUnboundMethod, "source_location", method_source_location, 0);
|
145
|
+
rb_define_method(rb_cMethod, "source_location", method_source_location, 0);
|
146
|
+
rb_define_method(rb_cProc, "source_location", proc_source_location, 0);
|
147
|
+
}
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby18_source_location
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Conrad Irwin
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-10-22 00:00:00 Z
|
18
|
+
dependencies: []
|
19
|
+
|
20
|
+
description: Allows you to make use of lots of ruby 1.9.2 specific goodness
|
21
|
+
email: conrad.irwin@gmail.com
|
22
|
+
executables: []
|
23
|
+
|
24
|
+
extensions:
|
25
|
+
- ext/extconf.rb
|
26
|
+
extra_rdoc_files: []
|
27
|
+
|
28
|
+
files:
|
29
|
+
- ext/ruby18_source_location.c
|
30
|
+
- ext/extconf.rb
|
31
|
+
homepage: http://github.com/ConradIrwin/ruby18_source_location
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- ext
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.6
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Add .source_location to methods in Ruby 1.8.7
|
64
|
+
test_files: []
|
65
|
+
|