utilrb 1.6.6 → 2.0

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.
Files changed (51) hide show
  1. data/Manifest.txt +10 -9
  2. data/README.rd +23 -0
  3. data/Rakefile +40 -37
  4. data/ext/utilrb/extconf.rb +36 -0
  5. data/ext/{proc.cc → utilrb/proc.c} +7 -6
  6. data/ext/utilrb/ruby_allocator.hh +76 -0
  7. data/ext/{ruby_internals-1.8.h → utilrb/ruby_internals-1.8.h} +0 -0
  8. data/ext/{ruby_internals-1.9.h → utilrb/ruby_internals-1.9.h} +0 -0
  9. data/ext/{swap.cc → utilrb/swap.cc} +0 -0
  10. data/ext/utilrb/utilrb.cc +79 -0
  11. data/ext/{value_set.cc → utilrb/value_set.cc} +5 -5
  12. data/ext/{weakref.cc → utilrb/weakref.cc} +0 -0
  13. data/lib/utilrb/common.rb +7 -2
  14. data/lib/utilrb/doc/rake.rb +46 -15
  15. data/lib/utilrb/kernel/load_dsl_file.rb +2 -2
  16. data/lib/utilrb/kernel/options.rb +6 -0
  17. data/lib/utilrb/logger/forward.rb +7 -0
  18. data/lib/utilrb/logger/hierarchy.rb +100 -42
  19. data/lib/utilrb/logger/indent.rb +38 -3
  20. data/lib/utilrb/logger/log_pp.rb +1 -1
  21. data/lib/utilrb/logger/root.rb +27 -12
  22. data/lib/utilrb/module/inherited_enumerable.rb +2 -196
  23. data/lib/utilrb/objectstats.rb +4 -1
  24. data/lib/utilrb/pkgconfig.rb +42 -6
  25. data/lib/utilrb/rake_common.rb +12 -0
  26. data/lib/utilrb/ruby_object_graph.rb +195 -46
  27. data/lib/utilrb/yard.rb +89 -89
  28. data/test/test_array.rb +1 -1
  29. data/test/test_dir.rb +1 -1
  30. data/test/test_enumerable.rb +7 -1
  31. data/test/test_event_loop.rb +407 -0
  32. data/test/test_exception.rb +1 -1
  33. data/test/test_gc.rb +1 -1
  34. data/test/test_hash.rb +57 -1
  35. data/test/test_kernel.rb +52 -21
  36. data/test/test_logger.rb +150 -1
  37. data/test/test_misc.rb +1 -1
  38. data/test/test_models.rb +212 -0
  39. data/test/test_module.rb +41 -71
  40. data/test/test_object.rb +1 -1
  41. data/test/test_objectstats.rb +1 -1
  42. data/test/test_pkgconfig.rb +7 -5
  43. data/test/test_proc.rb +1 -1
  44. data/test/test_set.rb +1 -1
  45. data/test/test_thread_pool.rb +409 -0
  46. data/test/test_time.rb +6 -6
  47. data/test/test_unbound_method.rb +1 -1
  48. metadata +157 -131
  49. data/README.txt +0 -45
  50. data/ext/extconf.rb +0 -29
  51. data/ext/utilrb_ext.cc +0 -144
data/Manifest.txt CHANGED
@@ -2,18 +2,19 @@
2
2
  History.txt
3
3
  License.txt
4
4
  Manifest.txt
5
- README.txt
5
+ README.rd
6
6
  Rakefile
7
7
  bm/allocation.rb
8
8
  bm/speed.rb
9
- ext/extconf.rb
10
- ext/proc.cc
11
- ext/ruby_internals-1.8.h
12
- ext/ruby_internals-1.9.h
13
- ext/swap.cc
14
- ext/utilrb_ext.cc
15
- ext/value_set.cc
16
- ext/weakref.cc
9
+ ext/utilrb/extconf.rb
10
+ ext/utilrb/proc.c
11
+ ext/utilrb/ruby_internals-1.8.h
12
+ ext/utilrb/ruby_internals-1.9.h
13
+ ext/utilrb/ruby_allocator.hh
14
+ ext/utilrb/swap.cc
15
+ ext/utilrb/utilrb.cc
16
+ ext/utilrb/value_set.cc
17
+ ext/utilrb/weakref.cc
17
18
  lib/utilrb.rb
18
19
  lib/utilrb/array.rb
19
20
  lib/utilrb/array/to_s.rb
data/README.rd ADDED
@@ -0,0 +1,23 @@
1
+ = Utilrb
2
+
3
+ homepage :: http://rock-robotics.org
4
+ mailing list :: http://www.dfki.de/mailman/cgi-bin/listinfo/rock-dev
5
+ bug tracker :: trac.rock-robotics.org
6
+ rubygem page :: http://rubygems.org/gems/utilrb
7
+ git repository :: http://gitorious.org/orocos-toolchain/utilrb.git
8
+ API documentation :: http://rubydoc.info/gems/utilrb/1.6.6/frames
9
+
10
+ == DESCRIPTION
11
+
12
+ Utilrb is yet another Ruby toolkit, in the spirit of facets. It includes all
13
+ the standard class extensions I use in other projects.
14
+
15
+ == LICENSE
16
+
17
+ Copyright (c) 2006-2013
18
+ Sylvain Joyeux <sylvain.joyeux@m4x.org>
19
+ DFKI <robotics@dfki.de>
20
+ LAAS/CNRS <openrobots@laas.fr>
21
+
22
+ This work is licensed under the BSD license. See License.txt for details
23
+
data/Rakefile CHANGED
@@ -1,56 +1,59 @@
1
+ $LOAD_PATH.unshift File.expand_path('lib', File.dirname(__FILE__))
1
2
  require 'rake'
2
- require './lib/utilrb/common'
3
- require './lib/utilrb/rake_common'
4
- require './lib/utilrb/doc/rake'
5
3
 
6
- Utilrb::Rake.hoe do
4
+ begin
5
+ require 'hoe'
6
+
7
+ Hoe::plugin :yard
8
+
7
9
  hoe_spec = Hoe.spec 'utilrb' do
8
10
  developer "Sylvain Joyeux", "sylvain.joyeux@m4x.org"
11
+ self.readme_file = 'README.rd'
12
+
9
13
  extra_deps <<
10
14
  ['facets', '>= 2.4.0'] <<
11
- ['rake', '>= 0']
15
+ ['rake', '>= 0.9'] <<
16
+ ["rake-compiler", "~> 0.8.0"] <<
17
+ ["hoe-yard", ">= 0.1.2"]
12
18
 
13
19
  extra_dev_deps <<
14
- ['flexmock', '>= 0.8.6']
15
-
16
- self.summary = 'Yet another Ruby toolkit'
17
- self.description = paragraphs_of('README.txt', 3..5).join("\n\n")
18
- end
19
- hoe_spec.spec.extensions << 'ext/extconf.rb'
20
- Rake.clear_tasks(/^default$/)
21
- Rake.clear_tasks(/doc/)
22
- end
20
+ ['flexmock', '>= 0.8.6'] <<
21
+ ['debugger-ruby_core_source', '>= 0']
23
22
 
24
- task :default => :setup
23
+ licenses << 'BSD'
25
24
 
26
- Utilrb.doc
25
+ spec_extras[:extensions] = FileList["ext/**/extconf.rb"]
26
+ end
27
27
 
28
- desc "builds Utilrb's C extension"
29
- task :setup do
30
- Dir.chdir("ext") do
31
- if !system("#{FileUtils::RUBY} extconf.rb") || !system("make")
32
- raise "cannot build the C extension"
33
- end
28
+ require 'rubygems/package_task'
29
+ Gem::PackageTask.new(hoe_spec.spec) do |pkg|
30
+ pkg.need_zip = true
31
+ pkg.need_tar = true
34
32
  end
35
- FileUtils.ln_sf "../ext/utilrb_ext.so", "lib/utilrb_ext.so"
36
- end
37
33
 
38
- task :clean do
39
- puts "Cleaning extension in ext/"
40
- FileUtils.rm_f "lib/utilrb_ext.so"
41
- if File.file?(File.join('ext', 'Makefile'))
42
- Dir.chdir("ext") do
43
- system("make clean")
44
- end
34
+ require 'rake/extensiontask'
35
+ utilrb_task = Rake::ExtensionTask.new('utilrb', hoe_spec.spec) do |ext|
36
+ ext.name = 'utilrb'
37
+ ext.ext_dir = 'ext/utilrb'
38
+ ext.lib_dir = 'lib/utilrb'
39
+ ext.config_options << "-DRUBINIUS"
40
+ ext.source_pattern ="*.{c,cc,cpp}"
45
41
  end
46
- FileUtils.rm_f "ext/Makefile"
47
- FileUtils.rm_f "lib/utilrb_ext.so"
42
+
43
+ Rake.clear_tasks(/^default$/)
44
+ task :default => :compile
45
+
46
+ task :docs => :yard
47
+ task :redocs => :yard
48
+
49
+
50
+ rescue LoadError => e
51
+ puts "'utilrb' cannot be build -- loading gem failed: #{e}"
48
52
  end
49
53
 
50
54
  task :full_test do
51
- ENV['UTILRB_EXT_MODE'] = 'no'
52
- system("testrb test/")
55
+ ENV.delete_if { |name,val| name == "UTILRB_EXT_MODE" }
56
+ system('testrb -I. test')
53
57
  ENV['UTILRB_EXT_MODE'] = 'yes'
54
- system("testrb test/")
58
+ system('testrb -I. test')
55
59
  end
56
-
@@ -0,0 +1,36 @@
1
+ require 'mkmf'
2
+
3
+ CONFIG['LDSHARED'].gsub! '$(CC)', "$(CXX)"
4
+ if try_link("int main() { }", "-module")
5
+ $LDFLAGS += " -module"
6
+ end
7
+
8
+ if RUBY_VERSION >= "1.9"
9
+ $CFLAGS += " -DRUBY_IS_19"
10
+ begin
11
+ require 'debugger/ruby_core_source'
12
+ $CFLAGS += " -DHAS_RUBY_SOURCE"
13
+ hdrs = lambda { try_compile("#include <vm_core.h>") }
14
+ Debugger::RubyCoreSource.create_makefile_with_core(hdrs, "utilrb/utilrb")
15
+ rescue LoadError
16
+ puts "not building with core source"
17
+ create_makefile("utilrb/utilrb")
18
+ end
19
+ else
20
+ puts "not building with core source"
21
+ create_makefile("utilrb/utilrb")
22
+ end
23
+
24
+ ## WORKAROUND a problem with mkmf.rb
25
+ # It seems that the newest version do define an 'install' target. However, that
26
+ # install target tries to install in the system directories
27
+ #
28
+ # The issue is that RubyGems *does* call make install. Ergo, gem install utilrb
29
+ # is broken right now
30
+ #lines = File.readlines("Makefile")
31
+ #lines.delete_if { |l| l =~ /^install:/ }
32
+ #lines << "install:"
33
+ #File.open("Makefile", 'w') do |io|
34
+ # io.write lines.join("\n")
35
+ #end
36
+
@@ -1,7 +1,5 @@
1
1
  #ifdef HAS_RUBY_SOURCE
2
- extern "C" {
3
- #include "/usr/include/ruby-1.9.1/ruby-1.9.3-p0/vm_core.h"
4
- }
2
+ #include <vm_core.h>
5
3
 
6
4
  static VALUE env_references(VALUE rbenv)
7
5
  {
@@ -11,7 +9,8 @@ static VALUE env_references(VALUE rbenv)
11
9
  GetEnvPtr(rbenv, env);
12
10
  if (env->env)
13
11
  {
14
- for (int i = 0; i < env->env_size; ++i)
12
+ int i;
13
+ for (i = 0; i < env->env_size; ++i)
15
14
  rb_ary_push(result, rb_obj_id(env->env[i]));
16
15
  }
17
16
  return result;
@@ -26,11 +25,13 @@ static VALUE proc_references(VALUE rbproc)
26
25
  return env_references(proc->envval);
27
26
  return rb_ary_new();
28
27
  }
28
+ #elif RUBY_IS_19
29
+ #warning "Ruby core sources cannot be found, Proc#references will not be available. Install the debugger-ruby_core_source gem to enable"
29
30
  #else
30
- #warning "RUBY_SOURCE_DIR is not set, Proc#references will not be available"
31
+ #warning "compiling on Ruby 1.8, Proc#references will not be available"
31
32
  #endif
32
33
 
33
- extern "C" void Init_proc()
34
+ void Init_proc()
34
35
  {
35
36
  #ifdef HAS_RUBY_SOURCE
36
37
  rb_define_method(rb_cProc, "references", RUBY_METHOD_FUNC(proc_references), 0);
@@ -0,0 +1,76 @@
1
+ #ifndef RUBY_ALLOCATOR_HH
2
+ #define RUBY_ALLOCATOR_HH
3
+
4
+ #include <ruby.h>
5
+
6
+ template <class T> class ruby_allocator
7
+ {
8
+ public:
9
+ typedef T value_type;
10
+ typedef value_type* pointer;
11
+ typedef const value_type* const_pointer;
12
+ typedef value_type& reference;
13
+ typedef const value_type& const_reference;
14
+ typedef std::size_t size_type;
15
+ typedef std::ptrdiff_t difference_type;
16
+
17
+ template <class U>
18
+ struct rebind { typedef ruby_allocator<U> other; };
19
+
20
+ ruby_allocator() {}
21
+ ruby_allocator(const ruby_allocator&) {}
22
+ template <class U>
23
+ ruby_allocator(const ruby_allocator<U>&) {}
24
+ ~ruby_allocator() {}
25
+
26
+ pointer address(reference x) const { return &x; }
27
+ const_pointer address(const_reference x) const {
28
+ return x;
29
+ }
30
+
31
+ pointer allocate(size_type n, const_pointer = 0) {
32
+ void* p = ruby_xmalloc(n * sizeof(T));
33
+ if (!p)
34
+ throw std::bad_alloc();
35
+ return static_cast<pointer>(p);
36
+ }
37
+
38
+ void deallocate(pointer p, size_type) { ruby_xfree(p); }
39
+
40
+ size_type max_size() const {
41
+ return static_cast<size_type>(-1) / sizeof(T);
42
+ }
43
+
44
+ void construct(pointer p, const value_type& x) {
45
+ new(p) value_type(x);
46
+ }
47
+ void destroy(pointer p) { p->~value_type(); }
48
+
49
+ private:
50
+ void operator=(const ruby_allocator&);
51
+ };
52
+
53
+ template<> class ruby_allocator<void>
54
+ {
55
+ typedef void value_type;
56
+ typedef void* pointer;
57
+ typedef const void* const_pointer;
58
+
59
+ template <class U>
60
+ struct rebind { typedef ruby_allocator<U> other; };
61
+ };
62
+
63
+
64
+ template <class T>
65
+ inline bool operator==(const ruby_allocator<T>&,
66
+ const ruby_allocator<T>&) {
67
+ return true;
68
+ }
69
+
70
+ template <class T>
71
+ inline bool operator!=(const ruby_allocator<T>&,
72
+ const ruby_allocator<T>&) {
73
+ return false;
74
+ }
75
+
76
+ #endif
File without changes
@@ -0,0 +1,79 @@
1
+ #include <ruby.h>
2
+ #include <set>
3
+
4
+ static VALUE mUtilrb;
5
+
6
+ using namespace std;
7
+
8
+ #ifndef RUBINIUS
9
+ static VALUE enumerable_each_uniq_i(VALUE i, VALUE* memo)
10
+ {
11
+ set<VALUE>& seen = *reinterpret_cast< set<VALUE>* >(memo);
12
+ if (seen.find(i) == seen.end())
13
+ {
14
+ seen.insert(i);
15
+ return rb_yield(i);
16
+ }
17
+ else
18
+ return Qnil;
19
+
20
+ }
21
+
22
+ /* :nodoc: */
23
+ static VALUE enumerable_each_uniq(VALUE self)
24
+ {
25
+ set<VALUE> seen;
26
+ rb_iterate(rb_each, self,
27
+ RUBY_METHOD_FUNC(enumerable_each_uniq_i), (VALUE)&seen);
28
+ return self;
29
+ }
30
+
31
+ /* call-seq:
32
+ * Kernel.is_singleton?(object)
33
+ *
34
+ * Returns true if +self+ is a singleton class
35
+ */
36
+ static VALUE kernel_is_singleton_p(VALUE self)
37
+ {
38
+ if (BUILTIN_TYPE(self) == T_CLASS && FL_TEST(self, FL_SINGLETON))
39
+ return Qtrue;
40
+ else
41
+ return Qfalse;
42
+ }
43
+
44
+ static VALUE kernel_is_immediate(VALUE klass, VALUE object)
45
+ { return IMMEDIATE_P(object) ? Qtrue : Qfalse; }
46
+ #endif
47
+
48
+ static VALUE kernel_crash(VALUE klass)
49
+ {
50
+ *((int*)0) = 10;
51
+ // Return something to shut gcc up
52
+ return Qfalse;
53
+ }
54
+
55
+ extern "C" void Init_value_set();
56
+ extern "C" void Init_swap();
57
+ extern "C" void Init_weakref(VALUE mUtilrb);
58
+ extern "C" void Init_proc();
59
+
60
+ extern "C" void Init_utilrb()
61
+ {
62
+ mUtilrb = rb_define_module("Utilrb");
63
+
64
+ #ifndef RUBINIUS
65
+ rb_define_method(rb_mEnumerable, "each_uniq", RUBY_METHOD_FUNC(enumerable_each_uniq), 0);
66
+ rb_define_method(rb_mKernel, "is_singleton?", RUBY_METHOD_FUNC(kernel_is_singleton_p), 0);
67
+
68
+ rb_define_singleton_method(rb_mKernel, "crash!", RUBY_METHOD_FUNC(kernel_crash), 0);
69
+ rb_define_singleton_method(rb_mKernel, "immediate?", RUBY_METHOD_FUNC(kernel_is_immediate), 1);
70
+
71
+ Init_swap();
72
+ Init_weakref(mUtilrb);
73
+ #endif
74
+
75
+ Init_proc();
76
+
77
+ Init_value_set();
78
+ }
79
+
@@ -1,13 +1,14 @@
1
1
  #include <ruby.h>
2
2
  #include <set>
3
3
  #include <algorithm>
4
+ #include "ruby_allocator.hh"
4
5
 
5
6
  using namespace std;
6
7
 
7
8
  static VALUE cValueSet;
8
9
  static ID id_new;
9
10
 
10
- typedef std::set<VALUE> ValueSet;
11
+ typedef std::set<VALUE, std::less<VALUE>, ruby_allocator<VALUE> > ValueSet;
11
12
  static ValueSet& get_wrapped_set(VALUE self)
12
13
  {
13
14
  ValueSet* object = 0;
@@ -252,7 +253,8 @@ static VALUE value_set_difference_bang(VALUE vself, VALUE vother)
252
253
  ValueSet result;
253
254
  std::set_difference(self.begin(), self.end(), other.begin(), other.end(),
254
255
  std::inserter(result, result.end()));
255
- self.swap(result);
256
+ if (result.size() != self.size())
257
+ self.swap(result);
256
258
  return vself;
257
259
  }
258
260
 
@@ -335,9 +337,7 @@ static VALUE value_set_clear(VALUE self)
335
337
  */
336
338
  static VALUE value_set_initialize_copy(VALUE vself, VALUE vother)
337
339
  {
338
- ValueSet const& other = get_wrapped_set(vother);
339
- set<VALUE> new_set(other.begin(), other.end());
340
- get_wrapped_set(vself).swap(new_set);
340
+ get_wrapped_set(vself) = get_wrapped_set(vother);
341
341
  return vself;
342
342
  }
343
343
 
File without changes
data/lib/utilrb/common.rb CHANGED
@@ -1,17 +1,22 @@
1
+
2
+ # Utilrb is yet another Ruby toolkit, in the spirit of facets. It includes all
3
+ # the standard class extensions used by www.rock-robotics.org projects.
1
4
  module Utilrb
2
5
  unless defined? Utilrb::VERSION
3
- VERSION = "1.6.6"
6
+ VERSION = "2.0"
4
7
  RUBY_IS_19 = (RUBY_VERSION >= "1.9.2")
5
8
  RUBY_IS_191 = (RUBY_VERSION >= "1.9") && (RUBY_VERSION < "1.9.2")
6
9
  end
7
10
 
11
+ LIB_DIR = File.expand_path(File.dirname(__FILE__))
12
+
8
13
  unless defined? UTILRB_EXT_MODE
9
14
  if ENV['UTILRB_EXT_MODE'] == 'no'
10
15
  UTILRB_EXT_MODE = nil
11
16
  STDERR.puts "Utilrb: not loading the C extension"
12
17
  else
13
18
  begin
14
- require 'utilrb_ext'
19
+ require 'utilrb/utilrb'
15
20
  UTILRB_EXT_MODE = true
16
21
  STDERR.puts "Utilrb: loaded C extension" if ENV['UTILRB_EXT_MODE']
17
22
  rescue LoadError => e