utilrb 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,14 @@
1
+ === Version 1.2
2
+
3
+ * compatibility with ruby 1.9. Some feature are specific 1.8:
4
+ IO#clearerr, Proc#line, Proc#file and Proc#same_body?.
5
+ * misc fixes to Time#to_hms and Time.from_hms
6
+ * migrate to facets >= 2.4.0
7
+ * fix Object#address on 64bit architectures
8
+ * new functionality:
9
+ - socket-related tools (see Socket)
10
+ - Dir#empty?
11
+
1
12
  === Version 1.1
2
13
 
3
14
  * changes and fixes:
data/License.txt CHANGED
@@ -1,5 +1,5 @@
1
- Copyright (c) 2006-2007 LAAS/CNRS <openrobots@laas.fr>
2
- 2006-2007 Sylvain Joyeux <sylvain.joyeux@laas.fr>
1
+ Copyright (c) 2006-2008 LAAS/CNRS <openrobots@laas.fr>
2
+ 2006-2008 Sylvain Joyeux <sylvain.joyeux@laas.fr>
3
3
  All rights reserved.
4
4
 
5
5
  Redistribution and use in source and binary forms, with or without
data/Manifest.txt CHANGED
@@ -1,4 +1,4 @@
1
- Changes.txt
1
+ History.txt
2
2
  License.txt
3
3
  Manifest.txt
4
4
  README.txt
@@ -6,8 +6,9 @@ Rakefile
6
6
  bm/allocation.rb
7
7
  bm/speed.rb
8
8
  ext/extconf.rb
9
- ext/faster.cc
10
- ext/ruby_internals.h
9
+ ext/utilrb_ext.cc
10
+ ext/ruby_internals-1.8.h
11
+ ext/ruby_internals-1.9.h
11
12
  ext/swap.cc
12
13
  ext/value_set.cc
13
14
  lib/utilrb.rb
@@ -15,6 +16,8 @@ lib/utilrb/array.rb
15
16
  lib/utilrb/array/to_s.rb
16
17
  lib/utilrb/column_formatter.rb
17
18
  lib/utilrb/common.rb
19
+ lib/utilrb/dir.rb
20
+ lib/utilrb/dir/empty.rb
18
21
  lib/utilrb/enumerable.rb
19
22
  lib/utilrb/enumerable/null.rb
20
23
  lib/utilrb/enumerable/random_element.rb
@@ -44,6 +47,7 @@ lib/utilrb/module/attr_enumerable.rb
44
47
  lib/utilrb/module/attr_predicate.rb
45
48
  lib/utilrb/module/cached_enum.rb
46
49
  lib/utilrb/module/define_method.rb
50
+ lib/utilrb/module/define_or_reuse.rb
47
51
  lib/utilrb/module/include.rb
48
52
  lib/utilrb/module/inherited_enumerable.rb
49
53
  lib/utilrb/object.rb
@@ -54,6 +58,8 @@ lib/utilrb/objectstats.rb
54
58
  lib/utilrb/pkgconfig.rb
55
59
  lib/utilrb/set.rb
56
60
  lib/utilrb/set/to_s.rb
61
+ lib/utilrb/socket/tcp_server.rb
62
+ lib/utilrb/socket/tcp_socket.rb
57
63
  lib/utilrb/time.rb
58
64
  lib/utilrb/time/to_hms.rb
59
65
  lib/utilrb/unbound_method.rb
@@ -62,6 +68,7 @@ lib/utilrb/value_set.rb
62
68
  test/data/test_pkgconfig.pc
63
69
  test/test_array.rb
64
70
  test/test_config.rb
71
+ test/test_dir.rb
65
72
  test/test_enumerable.rb
66
73
  test/test_exception.rb
67
74
  test/test_gc.rb
data/README.txt CHANGED
@@ -1,9 +1,9 @@
1
1
  Utilrb
2
2
  http://utilrb.rubyforge.org
3
- http://www.laas.fr/~sjoyeux/darcs/utilrb (dev repository)
4
- http://www.laas.fr/~sjoyeux/research.php
3
+ http://www.rubyforge.org/projects/utilrb
4
+ http://github.com/doudou/util-rb (git repository)
5
5
 
6
- Copyright (c) 2006
6
+ Copyright (c) 2006-2008
7
7
  Sylvain Joyeux <sylvain.joyeux@m4x.org>
8
8
  LAAS/CNRS <openrobots@laas.fr>
9
9
 
@@ -13,6 +13,12 @@ This work is licensed under the BSD license. See License.txt for details
13
13
  Utilrb is yet another Ruby toolkit, in the spirit of facets. It includes all
14
14
  the standard class extensions I use in my own projects like Genom.rb.
15
15
 
16
+ == Installation
17
+ The only dependency Utilrb has is flexmock if you want to run tests. It is
18
+ available as a gem, so you can run
19
+
20
+ gem install flexmock
21
+
16
22
  == Utilrb's C extension
17
23
  Utilrb includes a C extension in ext/. It is optional, but some of the
18
24
  functionalities will be disabled if it is not present. Trying to require
@@ -31,14 +37,5 @@ loading. Set it to +no+ to disable the extension, to +yes+ to force it
31
37
  (an error is generated if the extension is not available). If the variable
32
38
  is not set, the extension is loaded if available.
33
39
 
34
- == TODO
35
- * put the +block+ argument in front in Module#define_method_with_block. This
36
- would allow to do
37
-
38
- define_method_with_block(:bla) do |block, *args|
39
- end
40
-
41
- [DONE 20061101125259-1e605-fef189550540b8e096f0bbe6c219d892bf3e13fc.gz]
42
-
43
40
  == CHANGES
44
- :include: Changes.txt
41
+ :include: History.txt
data/Rakefile CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rake'
2
2
  require 'rake/rdoctask'
3
+
3
4
  # FIX: Hoe always calls rdoc with -d, and diagram generation fails here
4
5
  class Rake::RDocTask
5
6
  alias __option_list__ option_list
@@ -10,20 +11,24 @@ class Rake::RDocTask
10
11
  end
11
12
  end
12
13
 
13
- require 'hoe'
14
14
  require './lib/utilrb/common'
15
15
 
16
- Hoe.new('utilrb', Utilrb::VERSION) do |p|
17
- p.author = "Sylvain Joyeux"
18
- p.email = "sylvain.joyeux@m4x.org"
16
+ begin
17
+ require 'hoe'
18
+ config = Hoe.new('utilrb', Utilrb::VERSION) do |p|
19
+ p.developer("Sylvain Joyeux", "sylvain.joyeux@m4x.org")
19
20
 
20
- p.summary = 'Yet another Ruby toolkit'
21
- p.description = p.paragraphs_of('README.txt', 3..6).join("\n\n")
22
- p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
23
- p.changes = p.paragraphs_of('Changes.txt', 0..1).join("\n\n")
21
+ p.summary = 'Yet another Ruby toolkit'
22
+ p.description = p.paragraphs_of('README.txt', 3..6).join("\n\n")
23
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
24
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
24
25
 
25
- p.extra_deps << 'facets'
26
- p.rdoc_pattern = /(ext\/.*cc$|lib)|txt/
26
+ p.extra_deps << ['facets', '>= 2.4.0'] << 'rake'
27
+ p.rdoc_pattern = /(ext\/.*cc$|lib)|txt/
28
+ end
29
+ config.spec.extensions << 'ext/extconf.rb'
30
+ rescue LoadError
31
+ puts "cannot load the Hoe gem, distribution is disabled"
27
32
  end
28
33
 
29
34
  desc "builds Utilrb's C extension"
@@ -33,13 +38,25 @@ task :setup do
33
38
  raise "cannot build the C extension"
34
39
  end
35
40
  end
36
- FileUtils.ln_sf "../../ext/faster.so", "lib/utilrb/faster.so"
41
+ FileUtils.ln_sf "../ext/utilrb_ext.so", "lib/utilrb_ext.so"
42
+ end
43
+
44
+ task :clean do
45
+ puts "Cleaning extension in ext/"
46
+ FileUtils.rm_f "lib/utilrb_ext.so"
47
+ if File.file?(File.join('ext', 'Makefile'))
48
+ Dir.chdir("ext") do
49
+ system("make clean")
50
+ end
51
+ end
52
+ FileUtils.rm_f "ext/Makefile"
53
+ FileUtils.rm_f "lib/utilrb_ext.so"
37
54
  end
38
55
 
39
56
  task :full_test do
40
- ENV['UTILRB_FASTER_MODE'] = 'no'
57
+ ENV['UTILRB_EXT_MODE'] = 'no'
41
58
  system("testrb test/")
42
- ENV['UTILRB_FASTER_MODE'] = 'yes'
59
+ ENV['UTILRB_EXT_MODE'] = 'yes'
43
60
  system("testrb test/")
44
61
  end
45
62
 
data/ext/extconf.rb CHANGED
@@ -1,5 +1,10 @@
1
1
  require 'mkmf'
2
+
2
3
  CONFIG['CC'] = "g++"
4
+ if RUBY_VERSION >= "1.9"
5
+ $CFLAGS += "-DRUBY_IS_19"
6
+ end
7
+
3
8
  $LDFLAGS += "-module"
4
- create_makefile("faster")
9
+ create_makefile("utilrb_ext")
5
10
 
File without changes
@@ -0,0 +1,48 @@
1
+ #ifndef __RUBY_INTERNALS_HH__
2
+ #define __RUBY_INTERNALS_HH__
3
+
4
+ /* WARNING: this file contains copies of internal Ruby structures. They are not supposed to be copied (I think ;-)), but I had to nonetheless.
5
+ * The following methods depend on these:
6
+ *
7
+ * Kernel.swap!
8
+ * Proc#same_body?
9
+ * Proc#file
10
+ * Proc#line
11
+ */
12
+
13
+ #include <ruby.h>
14
+ #include <ruby/intern.h>
15
+ #include <ruby/node.h>
16
+ #include <ruby/re.h>
17
+
18
+ typedef struct RVALUE {
19
+ union {
20
+ struct {
21
+ VALUE flags; /* always 0 for freed obj */
22
+ struct RVALUE *next;
23
+ } free;
24
+ struct RBasic basic;
25
+ struct RObject object;
26
+ struct RClass klass;
27
+ struct RFloat flonum;
28
+ struct RString string;
29
+ struct RArray array;
30
+ struct RRegexp regexp;
31
+ struct RHash hash;
32
+ struct RData data;
33
+ struct RStruct rstruct;
34
+ struct RBignum bignum;
35
+ struct RFile file;
36
+ struct RNode node;
37
+ struct RMatch match;
38
+ } as;
39
+ #ifdef GC_DEBUG
40
+ char *file;
41
+ int line;
42
+ #endif
43
+ } RVALUE;
44
+
45
+ static const size_t SLOT_SIZE = sizeof(RVALUE);
46
+
47
+ #endif
48
+
data/ext/swap.cc CHANGED
@@ -1,4 +1,8 @@
1
- #include "ruby_internals.h"
1
+ #ifdef RUBY_IS_19
2
+ #include "ruby_internals-1.9.h"
3
+ #else
4
+ #include "ruby_internals-1.8.h"
5
+ #endif
2
6
 
3
7
  /*
4
8
  * Kernel.swap!(obj1, obj2, *args)
@@ -1,6 +1,12 @@
1
1
  #include <ruby.h>
2
2
  #include <set>
3
- #include "ruby_internals.h"
3
+
4
+ #ifdef RUBY_IS_19
5
+ #include "ruby_internals-1.9.h"
6
+ #else
7
+ #include <rubyio.h>
8
+ #include "ruby_internals-1.8.h"
9
+ #endif
4
10
 
5
11
  using namespace std;
6
12
 
@@ -26,6 +32,21 @@ static VALUE enumerable_each_uniq(VALUE self)
26
32
  return self;
27
33
  }
28
34
 
35
+ #ifndef RUBY_IS_19
36
+ /* call-seq:
37
+ * io.clearerr => nil
38
+ *
39
+ * Clear all error flags on the IO
40
+ */
41
+ static VALUE io_clearerr(VALUE self)
42
+ {
43
+ OpenFile* file;
44
+ file = RFILE(self)->fptr;
45
+ clearerr(file->f);
46
+ return Qnil;
47
+ }
48
+ #endif
49
+
29
50
  /* call-seq:
30
51
  * Kernel.is_singleton?(object)
31
52
  *
@@ -39,6 +60,7 @@ static VALUE kernel_is_singleton_p(VALUE self)
39
60
  return Qfalse;
40
61
  }
41
62
 
63
+ #ifndef RUBY_IS_19
42
64
 
43
65
  /* call-seq:
44
66
  * proc.same_body?(other) => true or false
@@ -92,16 +114,21 @@ static VALUE proc_line(VALUE self)
92
114
  return Qnil;
93
115
  }
94
116
 
117
+ #endif
118
+
95
119
  extern "C" void Init_value_set();
96
120
  extern "C" void Init_swap();
97
121
 
98
- extern "C" void Init_faster()
122
+ extern "C" void Init_utilrb_ext()
99
123
  {
100
124
  rb_define_method(rb_mEnumerable, "each_uniq", RUBY_METHOD_FUNC(enumerable_each_uniq), 0);
101
125
  rb_define_method(rb_mKernel, "is_singleton?", RUBY_METHOD_FUNC(kernel_is_singleton_p), 0);
126
+ #ifndef RUBY_IS_19
102
127
  rb_define_method(rb_cProc, "same_body?", RUBY_METHOD_FUNC(proc_same_body_p), 1);
103
128
  rb_define_method(rb_cProc, "file", RUBY_METHOD_FUNC(proc_file), 0);
104
129
  rb_define_method(rb_cProc, "line", RUBY_METHOD_FUNC(proc_line), 0);
130
+ rb_define_method(rb_cIO, "clearerr", RUBY_METHOD_FUNC(io_clearerr), 0);
131
+ #endif
105
132
 
106
133
  Init_value_set();
107
134
  Init_swap();
@@ -54,7 +54,7 @@ class ColumnFormatter
54
54
 
55
55
  while !names.empty? && (line_w < screen_width)
56
56
  col_n = names.shift
57
- col_w = width[col_n]
57
+ col_w = width[col_n] || 0
58
58
  line_n << col_n
59
59
  line_w += col_w
60
60
  format << "% #{col_w}s"
data/lib/utilrb/common.rb CHANGED
@@ -1,46 +1,49 @@
1
1
  module Utilrb
2
- VERSION = "1.1" unless defined? Utilrb::VERSION
2
+ unless defined? Utilrb::VERSION
3
+ VERSION = "1.2"
4
+ RUBY_IS_19 = (RUBY_VERSION >= "1.9")
5
+ end
3
6
 
4
- unless defined? UTILRB_FASTER_MODE
5
- if ENV['UTILRB_FASTER_MODE'] == 'no'
6
- UTILRB_FASTER_MODE = nil
7
+ unless defined? UTILRB_EXT_MODE
8
+ if ENV['UTILRB_EXT_MODE'] == 'no'
9
+ UTILRB_EXT_MODE = nil
7
10
  STDERR.puts "Utilrb: not loading the C extension"
8
11
  else
9
12
  begin
10
- require 'utilrb/faster'
11
- UTILRB_FASTER_MODE = true
12
- STDERR.puts "Utilrb: loaded C extension" if ENV['UTILRB_FASTER_MODE']
13
+ require 'utilrb_ext'
14
+ UTILRB_EXT_MODE = true
15
+ STDERR.puts "Utilrb: loaded C extension" if ENV['UTILRB_EXT_MODE']
13
16
  rescue LoadError => e
14
17
  raise unless e.message =~ /no such file to load/
15
- if ENV['UTILRB_FASTER_MODE'] == 'yes'
18
+ if ENV['UTILRB_EXT_MODE'] == 'yes'
16
19
  raise LoadError, "unable to load Util.rb C extension: #{e.message}"
17
20
  else
18
- UTILRB_FASTER_MODE = nil
21
+ UTILRB_EXT_MODE = nil
19
22
  end
20
23
  end
21
24
  end
22
25
  end
23
26
 
24
- # Yields if the faster extension is not present
27
+ # Yields if the extension is not present
25
28
  # This is used by Utilrb libraries to provide a
26
29
  # Ruby version if the C extension is not loaded
27
- def self.unless_faster # :yield:
28
- unless UTILRB_FASTER_MODE
30
+ def self.unless_ext # :yield:
31
+ unless UTILRB_EXT_MODE
29
32
  return yield if block_given?
30
33
  end
31
34
  end
32
35
 
33
- # Yields if the faster extension is present. This is used for Ruby code
36
+ # Yields if the extension is present. This is used for Ruby code
34
37
  # which depends on methods in the C extension
35
- def self.if_faster(&block)
36
- require_faster(nil, &block)
38
+ def self.if_ext(&block)
39
+ require_ext(nil, &block)
37
40
  end
38
41
 
39
- # Yields if the faster extension is present, and
42
+ # Yields if the extension is present, and
40
43
  # issue a warning otherwise. This is used for Ruby
41
44
  # code which depends on methods in the C extension
42
- def self.require_faster(name)
43
- if UTILRB_FASTER_MODE
45
+ def self.require_ext(name)
46
+ if UTILRB_EXT_MODE
44
47
  yield if block_given?
45
48
  elsif name
46
49
  STDERR.puts "Utilrb: not loading #{name} since the C extension is not available"
data/lib/utilrb/dir.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'utilrb/kernel/require'
2
+ require_dir(__FILE__)
@@ -0,0 +1,3 @@
1
+ class Dir
2
+ def empty?; entries.size == 2 end
3
+ end
@@ -48,7 +48,7 @@ class Object
48
48
  end
49
49
  end
50
50
 
51
- Utilrb.unless_faster do
51
+ Utilrb.unless_ext do
52
52
  module Enumerable
53
53
  # call-seq:
54
54
  # each_uniq { |obj| ... }
@@ -17,7 +17,7 @@ module Kernel
17
17
  # filter_options(nil, known_options) -> default_options, {}
18
18
  #
19
19
  def filter_options(options, option_spec)
20
- options = (options || Hash.new).to_sym_keys
20
+ options = (options.to_hash || Hash.new).to_sym_keys
21
21
  # cannot use #to_sym_keys as option_spec can be an array
22
22
  option_spec = option_spec.inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
23
23
 
@@ -44,7 +44,8 @@ module Kernel
44
44
  # as an empty option hash, all keys are converted into symbols.
45
45
  #
46
46
  def validate_options(options, known_options)
47
- opt, unknown = Kernel.filter_options(options, known_options)
47
+ options ||= Hash.new
48
+ opt, unknown = Kernel.filter_options(options.to_hash, known_options)
48
49
  unless unknown.empty?
49
50
  not_valid = unknown.keys.map { |m| "'#{m}'" }.join(" ")
50
51
  raise ArgumentError, "unknown options #{not_valid}", caller(1)