utilrb 1.2 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +1 -0
- data/ext/utilrb_ext.cc +11 -0
- data/lib/utilrb/common.rb +1 -1
- data/patches/gc_live_objects.patch +71 -0
- data/test/test_pkgconfig.rb +1 -1
- data/test/test_weakref.rb +55 -0
- metadata +5 -3
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
data/ext/utilrb_ext.cc
CHANGED
@@ -8,6 +8,8 @@
|
|
8
8
|
#include "ruby_internals-1.8.h"
|
9
9
|
#endif
|
10
10
|
|
11
|
+
static VALUE mUtilrb;
|
12
|
+
|
11
13
|
using namespace std;
|
12
14
|
|
13
15
|
static VALUE enumerable_each_uniq_i(VALUE i, VALUE* memo)
|
@@ -116,11 +118,17 @@ static VALUE proc_line(VALUE self)
|
|
116
118
|
|
117
119
|
#endif
|
118
120
|
|
121
|
+
static VALUE kernel_is_immediate(VALUE klass, VALUE object)
|
122
|
+
{ return IMMEDIATE_P(object) ? Qtrue : Qfalse; }
|
123
|
+
|
119
124
|
extern "C" void Init_value_set();
|
120
125
|
extern "C" void Init_swap();
|
126
|
+
extern "C" void Init_weakref(VALUE mUtilrb);
|
121
127
|
|
122
128
|
extern "C" void Init_utilrb_ext()
|
123
129
|
{
|
130
|
+
mUtilrb = rb_define_module("Utilrb");
|
131
|
+
|
124
132
|
rb_define_method(rb_mEnumerable, "each_uniq", RUBY_METHOD_FUNC(enumerable_each_uniq), 0);
|
125
133
|
rb_define_method(rb_mKernel, "is_singleton?", RUBY_METHOD_FUNC(kernel_is_singleton_p), 0);
|
126
134
|
#ifndef RUBY_IS_19
|
@@ -130,7 +138,10 @@ extern "C" void Init_utilrb_ext()
|
|
130
138
|
rb_define_method(rb_cIO, "clearerr", RUBY_METHOD_FUNC(io_clearerr), 0);
|
131
139
|
#endif
|
132
140
|
|
141
|
+
rb_define_singleton_method(rb_mKernel, "immediate?", RUBY_METHOD_FUNC(kernel_is_immediate), 1);
|
142
|
+
|
133
143
|
Init_value_set();
|
134
144
|
Init_swap();
|
145
|
+
Init_weakref(mUtilrb);
|
135
146
|
}
|
136
147
|
|
data/lib/utilrb/common.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- gc.c 2006-08-25 10:12:46.000000000 +0200
|
2
|
+
+++ gc.c.new 2007-01-13 12:39:38.383681000 +0100
|
3
|
+
@@ -88,6 +88,8 @@ static void run_final();
|
4
|
+
static VALUE nomem_error;
|
5
|
+
static void garbage_collect();
|
6
|
+
|
7
|
+
+static unsigned long live_objects = 0;
|
8
|
+
+
|
9
|
+
void
|
10
|
+
rb_memerror()
|
11
|
+
{
|
12
|
+
@@ -401,6 +398,7 @@ rb_newobj()
|
13
|
+
RANY(obj)->file = ruby_sourcefile;
|
14
|
+
RANY(obj)->line = ruby_sourceline;
|
15
|
+
#endif
|
16
|
+
+ live_objects++;
|
17
|
+
return obj;
|
18
|
+
}
|
19
|
+
|
20
|
+
@@ -1053,8 +1051,8 @@ gc_sweep()
|
21
|
+
RVALUE *p, *pend, *final_list;
|
22
|
+
int freed = 0;
|
23
|
+
int i;
|
24
|
+
- unsigned long live = 0;
|
25
|
+
unsigned long free_min = 0;
|
26
|
+
+ live_objects = 0;
|
27
|
+
|
28
|
+
for (i = 0; i < heaps_used; i++) {
|
29
|
+
free_min += heaps[i].limit;
|
30
|
+
@@ -1113,7 +1111,7 @@ gc_sweep()
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
RBASIC(p)->flags &= ~FL_MARK;
|
34
|
+
- live++;
|
35
|
+
+ live_objects++;
|
36
|
+
}
|
37
|
+
p++;
|
38
|
+
}
|
39
|
+
@@ -1131,7 +1129,7 @@ gc_sweep()
|
40
|
+
}
|
41
|
+
}
|
42
|
+
if (malloc_increase > malloc_limit) {
|
43
|
+
- malloc_limit += (malloc_increase - malloc_limit) * (double)live / (live + freed);
|
44
|
+
+ malloc_limit += (malloc_increase - malloc_limit) * (double)live_objects / (live_objects + freed);
|
45
|
+
if (malloc_limit < GC_MALLOC_LIMIT) malloc_limit = GC_MALLOC_LIMIT;
|
46
|
+
}
|
47
|
+
malloc_increase = 0;
|
48
|
+
@@ -2003,6 +2001,15 @@ rb_obj_id(VALUE obj)
|
49
|
+
return (VALUE)((long)obj|FIXNUM_FLAG);
|
50
|
+
}
|
51
|
+
|
52
|
+
+/* call-seq:
|
53
|
+
+ * GC.live_objects => number
|
54
|
+
+ *
|
55
|
+
+ * Returns the count of objects currently allocated
|
56
|
+
+ */
|
57
|
+
+static
|
58
|
+
+VALUE rb_gc_live_objects(VALUE self)
|
59
|
+
+{ return INT2FIX(live_objects); }
|
60
|
+
+
|
61
|
+
/*
|
62
|
+
* The <code>GC</code> module provides an interface to Ruby's mark and
|
63
|
+
* sweep garbage collection mechanism. Some of the underlying methods
|
64
|
+
@@ -2027,6 +2034,7 @@ Init_GC()
|
65
|
+
rb_define_module_function(rb_mObSpace, "remove_finalizer", rm_final, 1);
|
66
|
+
rb_define_module_function(rb_mObSpace, "finalizers", finals, 0);
|
67
|
+
rb_define_module_function(rb_mObSpace, "call_finalizer", call_final, 1);
|
68
|
+
+ rb_define_module_function(rb_mObSpace, "live_objects", rb_gc_live_objects, 0);
|
69
|
+
|
70
|
+
rb_define_module_function(rb_mObSpace, "define_finalizer", define_final, -1);
|
71
|
+
rb_define_module_function(rb_mObSpace, "undefine_finalizer", undefine_final, 1);
|
data/test/test_pkgconfig.rb
CHANGED
@@ -8,7 +8,7 @@ class TC_PkgConfig < Test::Unit::TestCase
|
|
8
8
|
ENV['PKG_CONFIG_PATH'] = File.join(File.expand_path(File.dirname(__FILE__)), 'data')
|
9
9
|
end
|
10
10
|
def teardown
|
11
|
-
ENV
|
11
|
+
ENV.delete('PKG_CONFIG_PATH')
|
12
12
|
end
|
13
13
|
|
14
14
|
PkgConfig = Utilrb::PkgConfig
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test/unit/testcase'
|
2
|
+
require 'utilrb/weakref'
|
3
|
+
|
4
|
+
Utilrb.require_ext('TC_WeakRef') do
|
5
|
+
class TC_WeakRef < Test::Unit::TestCase
|
6
|
+
WeakRef = Utilrb::WeakRef
|
7
|
+
def test_normal
|
8
|
+
obj = Object.new
|
9
|
+
ref = Utilrb::WeakRef.new(obj)
|
10
|
+
|
11
|
+
assert_equal(obj, ref.get)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_initialize_validation
|
15
|
+
assert_raises(ArgumentError) { Utilrb::WeakRef.new(nil) }
|
16
|
+
assert_raises(ArgumentError) { Utilrb::WeakRef.new(5) }
|
17
|
+
|
18
|
+
ref = WeakRef.new(Object.new)
|
19
|
+
assert_raises(ArgumentError) { Utilrb::WeakRef.new(ref) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_deep_ref(lvl)
|
23
|
+
if lvl == 0
|
24
|
+
obj = Object.new
|
25
|
+
refs = (1..100).map { WeakRef.new(obj) }
|
26
|
+
return refs, obj.object_id
|
27
|
+
else
|
28
|
+
create_deep_ref(lvl - 1)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_deep_obj(lvl)
|
33
|
+
if lvl == 0
|
34
|
+
ref = WeakRef.new(obj = Object.new)
|
35
|
+
return obj, ref.object_id
|
36
|
+
else
|
37
|
+
create_deep_obj(lvl - 1)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_finalization
|
42
|
+
refs, obj_id = create_deep_ref(100)
|
43
|
+
GC.start
|
44
|
+
for ref in refs
|
45
|
+
assert_raises(WeakRef::RefError) { ref.get }
|
46
|
+
end
|
47
|
+
assert_equal(nil, WeakRef.refcount(obj_id))
|
48
|
+
|
49
|
+
obj, ref_id = create_deep_obj(100)
|
50
|
+
GC.start
|
51
|
+
assert_raises(RangeError) { ObjectSpace._id2ref(ref_id) }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utilrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "1.
|
4
|
+
version: "1.3"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvain Joyeux
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-06-14 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -37,7 +37,7 @@ dependencies:
|
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.5.
|
40
|
+
version: 1.5.3
|
41
41
|
version:
|
42
42
|
description: == What is Utilrb ? Utilrb is yet another Ruby toolkit, in the spirit of facets. It includes all the standard class extensions I use in my own projects like Genom.rb. == Installation The only dependency Utilrb has is flexmock if you want to run tests. It is available as a gem, so you can run gem install flexmock == Utilrb's C extension Utilrb includes a C extension in ext/. It is optional, but some of the functionalities will be disabled if it is not present. Trying to require a file in which there is a C-only feature will yield a warning on STDOUT.
|
43
43
|
email:
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/utilrb/unbound_method.rb
|
120
120
|
- lib/utilrb/unbound_method/call.rb
|
121
121
|
- lib/utilrb/value_set.rb
|
122
|
+
- patches/gc_live_objects.patch
|
122
123
|
- test/data/test_pkgconfig.pc
|
123
124
|
- test/test_array.rb
|
124
125
|
- test/test_config.rb
|
@@ -180,6 +181,7 @@ test_files:
|
|
180
181
|
- test/test_gc.rb
|
181
182
|
- test/test_array.rb
|
182
183
|
- test/test_enumerable.rb
|
184
|
+
- test/test_weakref.rb
|
183
185
|
- test/test_hash.rb
|
184
186
|
- test/test_objectstats.rb
|
185
187
|
- test/test_pkgconfig.rb
|