rallhook 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ 0.7.1 Fixed issue 9 ( http://github.com/tario/rallhook/issues#issue/9 ), "broken" object is processed by the GC due the impossibility of avoid
2
+ the deletion of an object of class Redirect returned by handle_method. The hotfix disabled the GC at each redirection and enable
3
+ it again each time that a WRAPPER redirection concludes. Also the GC are re-enabled when the hook block is terminated.
4
+
5
+ MULTI-THREAD SUPPORT DISABLED
6
+ This hotfix changes a flag, the global state of GC enabled. Due this flag is not by thread, concurrency executions of hook blocks
7
+ in many thread simulaniously has unexpected and maybe undesirable behaviours
8
+
9
+ The thread support will be added again to the next patch version 0.7.2
10
+
1
11
  0.7.0 Concurrency support, any thread can hook without affect the hook state of the other threads
2
12
 
3
13
  Restrictions about overwrite instance methods disabled
data/README CHANGED
@@ -13,12 +13,18 @@ This package contains rallhook, a ruby C extension to intercept ruby methods cal
13
13
  * distorm ( found at https://code.google.com/p/distorm/ )
14
14
 
15
15
 
16
- === Gem installation
16
+ === Installation
17
+
18
+ * run in your system
19
+
20
+ sudo gem install rallhook
21
+
22
+ OR
17
23
 
18
24
  * Download the last version of the gem from http://github.com/tario/ruby-cpp/downloads
19
25
  * Install the gem with the following;
20
26
 
21
- gem install rallhook-X.X.X.gem
27
+ sudo gem install rallhook-X.X.X.gem
22
28
 
23
29
  == Usage
24
30
 
@@ -52,21 +58,21 @@ test.rb:
52
58
 
53
59
  standard output:
54
60
 
55
- method call each:4001 over 123:Array
56
- method call print:7697 over main:Object
57
- method call write:7649 over #<IO:0x7fb15e54fad0>:IO
58
- method call to_s:3137 over 1:Fixnum
59
- 1method call write:7649 over #<IO:0x7fb15e54fad0>:IO
61
+ method call each:4001 over 123:Array
62
+ method call print:7697 over main:Object
63
+ method call write:7649 over #<IO:0x7fb15e54fad0>:IO
64
+ method call to_s:3137 over 1:Fixnum
65
+ 1method call write:7649 over #<IO:0x7fb15e54fad0>:IO
60
66
 
61
- method call print:7697 over main:Object
62
- method call write:7649 over #<IO:0x7fb15e54fad0>:IO
63
- method call to_s:3137 over 2:Fixnum
64
- 2method call write:7649 over #<IO:0x7fb15e54fad0>:IO
67
+ method call print:7697 over main:Object
68
+ method call write:7649 over #<IO:0x7fb15e54fad0>:IO
69
+ method call to_s:3137 over 2:Fixnum
70
+ 2method call write:7649 over #<IO:0x7fb15e54fad0>:IO
65
71
 
66
- method call print:7697 over main:Object
67
- method call write:7649 over #<IO:0x7fb15e54fad0>:IO
68
- method call to_s:3137 over 3:Fixnum
69
- 3method call write:7649 over #<IO:0x7fb15e54fad0>:IO
72
+ method call print:7697 over main:Object
73
+ method call write:7649 over #<IO:0x7fb15e54fad0>:IO
74
+ method call to_s:3137 over 3:Fixnum
75
+ 3method call write:7649 over #<IO:0x7fb15e54fad0>:IO
70
76
 
71
77
  === Redirecting calls
72
78
 
@@ -92,7 +98,7 @@ standard output:
92
98
 
93
99
  nil # do nothing
94
100
  end
95
-
101
+
96
102
  def bar
97
103
  print "bar in MethodHandler\n"
98
104
  end
@@ -131,7 +137,7 @@ standard output:
131
137
 
132
138
  class MethodHandler < HookHandler
133
139
  include RallHook::Helper
134
-
140
+
135
141
  class FooMethodWrapper < MethodWrapper
136
142
  def call(*x)
137
143
  # call with reyield if block_given
@@ -139,7 +145,7 @@ standard output:
139
145
  original_call(*x) do |*a|
140
146
  yield(*a)
141
147
  end
142
- # add "�bar?"
148
+ # add "�bar?"
143
149
  yield("bar?")
144
150
  else
145
151
  original_call(*x)
@@ -205,3 +211,6 @@ main.rb
205
211
  print y.method(Y,:foo).body.file,"\n" # source2.rb
206
212
 
207
213
 
214
+ == Copying
215
+
216
+ Copyright (c) 2010 Dario Seminara, released under the GPL License (see LICENSE)
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'rake/gempackagetask'
6
6
 
7
7
  spec = Gem::Specification.new do |s|
8
8
  s.name = 'rallhook'
9
- s.version = '0.7.0'
9
+ s.version = '0.7.1'
10
10
  s.author = 'Dario Seminara'
11
11
  s.email = 'robertodarioseminara@gmail.com'
12
12
  s.platform = Gem::Platform::RUBY
@@ -117,6 +117,12 @@ VALUE get_hook_proc() {
117
117
  Disable the hook. Is not usually necesary because of the RAII feature of Hook#hook
118
118
  */
119
119
  VALUE unhook(VALUE self) {
120
+ disable_redirect(tinfo_from_thread( rb_thread_current() ) );
121
+ rb_gc_enable();
122
+ return Qnil;
123
+ }
124
+
125
+ VALUE restore_unhook(VALUE self) {
120
126
  disable_redirect(tinfo_from_thread( rb_thread_current() ) );
121
127
  return Qnil;
122
128
  }
@@ -191,6 +197,9 @@ void rallhook_redirect_handler ( VALUE* klass, VALUE* recv, ID* mid ) {
191
197
 
192
198
  // method named "binding" cannot be redirected
193
199
  if (rb_obj_is_kind_of(result,rb_mMethodRedirect) == Qtrue ) {
200
+
201
+ rb_gc_disable();
202
+
194
203
  *klass = rb_ivar_get(result,id_klass_var );
195
204
  *recv = rb_ivar_get(result,id_recv_var );
196
205
  *mid = rb_to_id( rb_ivar_get(result,id_method_var) );
@@ -257,7 +266,7 @@ If no call to Hook#hook has made, rehook does nothing
257
266
  VALUE rehook(VALUE unused) {
258
267
  enable_redirect(tinfo_from_thread( rb_thread_current() ));
259
268
  if (rb_block_given_p() ) {
260
- return rb_ensure(rb_yield, Qnil, unhook, Qnil);
269
+ return rb_ensure(rb_yield, Qnil, restore_unhook, Qnil);
261
270
  }
262
271
  return Qnil;
263
272
  }
data/lib/rallhook.rb CHANGED
@@ -40,7 +40,7 @@ module RallHook
40
40
  #
41
41
  class Redirect
42
42
  include MethodRedirect
43
-
43
+
44
44
  attr_reader :recv
45
45
 
46
46
  def initialize(klass, recv, m, unhook = nil)
@@ -225,7 +225,8 @@ module RallHook
225
225
  call(*args)
226
226
  end
227
227
  ensure
228
- rehook
228
+ GC.enable
229
+ ::RallHook::Hook.rehook
229
230
  end
230
231
 
231
232
  #
@@ -325,6 +326,11 @@ class Object
325
326
  # Anyway, it is desirable to use MethodWrapper instead to "wrap" method calls
326
327
  #
327
328
  # see RallHook::Helper::MethodWrapper
329
+ #
330
+ # NOTE: Rallhook internally disable the GC in a redirection, you must reactivate it after
331
+ #
332
+ # NOTE 2: If use the MethodWrapper functionallity, it reactivates the GC disabled by rallhook. You should not
333
+ # worry about it
328
334
  #
329
335
  def redirect_with_unhook(method_name, klass = nil)
330
336
  if klass
@@ -358,6 +364,7 @@ class Object
358
364
  #
359
365
  # # hook using MethodHandler, etc... (see README and examples)
360
366
  #
367
+ # NOTE: Rallhook internally disable the GC in a redirection, you must reactivate it after
361
368
  #
362
369
  def redirect(method_name, klass = nil)
363
370
  if klass
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rallhook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ hash: 1
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 7
9
+ - 1
10
+ version: 0.7.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Dario Seminara
@@ -9,19 +15,25 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-06-20 00:00:00 -03:00
18
+ date: 2010-06-21 00:00:00 -03:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: ruby-cymbol
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 27
30
+ segments:
31
+ - 0
32
+ - 1
33
+ - 0
23
34
  version: 0.1.0
24
- version:
35
+ type: :runtime
36
+ version_requirements: *id001
25
37
  description:
26
38
  email: robertodarioseminara@gmail.com
27
39
  executables: []
@@ -91,21 +103,27 @@ rdoc_options:
91
103
  require_paths:
92
104
  - lib
93
105
  required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
94
107
  requirements:
95
108
  - - ">="
96
109
  - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
97
113
  version: "0"
98
- version:
99
114
  required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
100
116
  requirements:
101
117
  - - ">="
102
118
  - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
103
122
  version: "0"
104
- version:
105
123
  requirements: []
106
124
 
107
125
  rubyforge_project:
108
- rubygems_version: 1.3.5
126
+ rubygems_version: 1.3.7
109
127
  signing_key:
110
128
  specification_version: 3
111
129
  summary: Allow hooking of all method invocations transparently to control and / or monitor the behavior of a ruby program