malloc 0.1.6 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING CHANGED
@@ -1,5 +1,5 @@
1
- This is the license for the Ruby extension "Malloc".
2
- Copyright (C) 2009 Jan Wedekind, Sheffield, United Kingdom.
1
+ This is the license for the computer vision library Hornetseye.
2
+ Copyright (C) 2006, 2007, 2008, 2009 Jan Wedekind, Sheffield, United Kingdom.
3
3
 
4
4
 
5
5
  GNU GENERAL PUBLIC LICENSE
data/Makefile CHANGED
@@ -2,41 +2,71 @@
2
2
  .SUFFIXES: .gem .o .cc .hh .rb .tar .gz .bz2
3
3
 
4
4
  RUBY_VERSION = 1.8
5
- MALLOC_VERSION = 0.1.6
5
+ MALLOC_VERSION = 0.2.0
6
6
 
7
+ CP = cp
8
+ RM = rm -f
9
+ MKDIR = mkdir -p
7
10
  GEM = gem$(RUBY_VERSION)
8
11
  RUBY = ruby$(RUBY_VERSION)
9
12
  TAR = tar
13
+ GIT = git
14
+ SITELIBDIR = $(shell $(RUBY) -r mkmf -e "puts \"\#{Config::CONFIG['sitelibdir']}\"")
15
+ SITEARCHDIR = $(shell $(RUBY) -r mkmf -e "puts \"\#{Config::CONFIG['sitearchdir']}\"")
10
16
 
11
- MAIN = Makefile malloc.gemspec binary.gemspec README COPYING
17
+ MAIN = Makefile source.gemspec binary.gemspec README COPYING
12
18
  EXT = ext/extconf.rb $(wildcard ext/*.cc) $(wildcard ext/*.hh)
13
19
  LIB = $(wildcard lib/*.rb)
14
- TESTS = $(wildcard test/*.rb)
20
+ TEST = $(wildcard test/*.rb)
15
21
  DOC = $(wildcard doc/*.rb)
16
- SOURCES = $(MAIN) $(EXT) $(LIB) $(TESTS) $(DOC)
22
+ SOURCES = $(MAIN) $(EXT) $(LIB) $(TEST) $(DOC)
17
23
 
18
- all:: malloc-$(MALLOC_VERSION).gem
24
+ all:: target
19
25
 
20
- check:: ext/malloc.so $(LIB) $(TESTS)
21
- $(RUBY) -Iext -Ilib $(TESTS)
26
+ target:: ext/malloc.so
22
27
 
23
- binary:: binary.gemspec ext/malloc.so $(LIB)
28
+ gem:: malloc-$(MALLOC_VERSION).gem
29
+
30
+ binary-gem:: binary.gemspec ext/malloc.so $(LIB)
24
31
  $(GEM) build binary.gemspec
25
32
 
26
- install:: malloc-$(MALLOC_VERSION).gem
27
- $(GEM) install $<
33
+ install:: ext/malloc.so $(LIB)
34
+ $(MKDIR) $(SITELIBDIR)
35
+ $(MKDIR) $(SITEARCHDIR)
36
+ $(CP) $(LIB) $(SITELIBDIR)
37
+ $(CP) ext/malloc.so $(SITEARCHDIR)
28
38
 
29
39
  uninstall::
40
+ $(RM) $(addprefix $(SITELIBDIR)/,$(notdir $(LIB)))
41
+ $(RM) $(addprefix $(SITEARCHDIR)/,malloc.so)
42
+
43
+ install-gem:: malloc-$(MALLOC_VERSION).gem
44
+ $(GEM) install --local $<
45
+
46
+ uninstall-gem::
30
47
  $(GEM) uninstall malloc || echo Nothing to uninstall
31
48
 
32
- dist:: malloc.tar.gz
49
+ check:: ext/malloc.so $(LIB) $(TEST)
50
+ $(RUBY) -rrubygems -Iext -Ilib -Itest test/ts_malloc.rb
51
+
52
+ push-gem:: malloc-$(MALLOC_VERSION).gem
53
+ echo Pushing $< in 3 seconds!
54
+ sleep 3
55
+ $(GEM) push $<
33
56
 
34
- dist-gzip:: malloc.tar.gz
57
+ push-git::
58
+ echo Pushing to origin in 3 seconds!
59
+ sleep 3
60
+ $(GIT) push origin master
35
61
 
36
- dist-bzip2:: malloc.tar.bz2
62
+ dist:: dist-gzip
37
63
 
38
- malloc-$(MALLOC_VERSION).gem: malloc.gemspec README $(EXT) $(LIB) $(TESTS) $(DOC)
39
- $(GEM) build malloc.gemspec
64
+ dist-gzip:: malloc-$(MALLOC_VERSION).tar.gz
65
+
66
+ dist-bzip2:: malloc-$(MALLOC_VERSION).tar.bz2
67
+
68
+ malloc-$(MALLOC_VERSION).gem: $(SOURCES)
69
+ $(GEM) build source.gemspec
40
70
 
41
71
  ext/Makefile: ext/extconf.rb
42
72
  cd ext && $(RUBY) extconf.rb && cd ..
@@ -44,11 +74,12 @@ ext/Makefile: ext/extconf.rb
44
74
  ext/malloc.so: ext/Makefile $(EXT)
45
75
  cd ext && $(MAKE) && cd ..
46
76
 
47
- malloc.tar.gz: $(SOURCES)
77
+ malloc-$(MALLOC_VERSION).tar.gz: $(SOURCES)
48
78
  $(TAR) czf $@ $(SOURCES)
49
79
 
50
- malloc.tar.bz2: $(SOURCES)
80
+ malloc-$(MALLOC_VERSION).tar.bz2: $(SOURCES)
51
81
  $(TAR) cjf $@ $(SOURCES)
52
82
 
53
83
  clean::
54
84
  rm -f *~ ext/*~ ext/*.o ext/*.so ext/Makefile lib/*~ lib/*.so test/*~ doc/*~ *.gem
85
+
data/README CHANGED
@@ -1,11 +1,2 @@
1
- This software is very experimental at the moment.
2
- The most pressing problem is to achieve a good combination of support across operating systems, support across Ruby versions, and ease of installation for everyone.
3
-
4
- http://www.wedesoft.demon.co.uk/hornetseye-api/files/Installation-txt.html
5
- http://rake-compiler.rubyforge.org/
6
- http://pkg-ruby-extras.alioth.debian.org/upstream-devs.html
7
- http://nsis.sourceforge.net/
8
- http://rubyforge.org/tracker/index.php?func=detail&aid=24036&group_id=126&atid=578
9
- http://rubyforge.org/pipermail/rubygems-developers/2009-April/004522.html
10
- http://rubyforge.org/tracker/index.php?func=detail&aid=27503&group_id=126&atid=575
1
+ This Ruby extension defines the class Hornetseye::Malloc. Hornetseye::Malloc#new allows you to allocate memory, using Hornetseye::Malloc#+ one can do pointer manipulation, and Hornetseye::Malloc#read and Hornetseye::Malloc#write provide reading Ruby strings from memory and writing Ruby strings to memory.
11
2
 
data/binary.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ require 'date'
2
+ Gem::Specification.new do |s|
3
+ s.name = %q{malloc}
4
+ s.version = '0.2.0'
5
+ s.platform = Gem::Platform::CURRENT
6
+ s.date = Date.today.to_s
7
+ s.summary = %q{Object for raw memory allocation and pointer operations}
8
+ s.description = %q{This Ruby extension defines the class Hornetseye::Malloc. Hornetseye::Malloc#new allows you to allocate memory, using Hornetseye::Malloc#+ one can do pointer manipulation, and Hornetseye::Malloc#read and Hornetseye::Malloc#write provide reading Ruby strings from memory and writing Ruby strings to memory.}
9
+ s.author = %q{Jan Wedekind}
10
+ s.email = %q{jan@wedesoft.de}
11
+ s.homepage = %q{http://wedesoft.github.com/malloc/}
12
+ s.files = [ 'README', 'COPYING' ] +
13
+ Dir.glob( 'lib/*.rb' ) +
14
+ [ 'ext/malloc.so' ] +
15
+ Dir.glob( 'test/*.rb' )
16
+ s.test_files = Dir.glob( 'test/tc_*.rb' )
17
+ s.require_paths = [ 'lib', 'ext' ]
18
+ s.rubyforge_project = %q{hornetseye}
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = [ 'README' ]
21
+ s.rdoc_options = %w{--exclude=/Makefile|.*\.(cc|hh|rb)/ --main README}
22
+ end
data/ext/init.cc CHANGED
@@ -29,7 +29,8 @@ extern "C" {
29
29
 
30
30
  void Init_malloc(void)
31
31
  {
32
- Malloc::init();
32
+ VALUE rbHornetseye = rb_define_module( "Hornetseye" );
33
+ Malloc::init( rbHornetseye );
33
34
  rb_require( "malloc_ext.rb" );
34
35
  }
35
36
 
data/ext/malloc.cc CHANGED
@@ -29,9 +29,9 @@ using namespace std;
29
29
 
30
30
  VALUE Malloc::cRubyClass = Qnil;
31
31
 
32
- VALUE Malloc::init(void)
32
+ VALUE Malloc::init( VALUE rbModule )
33
33
  {
34
- cRubyClass = rb_define_class( "Malloc", rb_cObject );
34
+ cRubyClass = rb_define_class_under( rbModule, "Malloc", rb_cObject );
35
35
  rb_define_singleton_method( cRubyClass, "new",
36
36
  RUBY_METHOD_FUNC( mallocNew ), 1 );
37
37
  rb_define_method( cRubyClass, "+",
data/ext/malloc.hh CHANGED
@@ -22,7 +22,7 @@ class Malloc
22
22
  {
23
23
  public:
24
24
  static VALUE cRubyClass;
25
- static VALUE init(void);
25
+ static VALUE init( VALUE rbModule );
26
26
  static VALUE mallocNew( VALUE rbClass, VALUE rbSize );
27
27
  static VALUE mallocPlus( VALUE rbSelf, VALUE rbOffset );
28
28
  static VALUE mallocRead( VALUE rbSelf, VALUE rbLength );
data/lib/malloc_ext.rb CHANGED
@@ -1,59 +1,63 @@
1
- class String
1
+ module Hornetseye
2
2
 
3
- unless method_defined? :bytesize
3
+ class Malloc
4
4
 
5
- def bytesize
6
- size
7
- end
5
+ class << self
8
6
 
9
- end
10
-
11
- end
7
+ alias_method :orig_new, :new
12
8
 
13
- class Malloc
9
+ def new( size )
10
+ retval = orig_new size
11
+ retval.instance_eval { @size = size }
12
+ retval
13
+ end
14
14
 
15
- class << self
15
+ end
16
16
 
17
- alias_method :orig_new, :new
17
+ attr_reader :size
18
18
 
19
- def new( size )
20
- retval = orig_new size
21
- retval.instance_eval { @size = size }
19
+ alias_method :orig_plus, :+
20
+
21
+ def +( offset )
22
+ if offset > @size
23
+ raise "Offset must not be more than #{@size} (but was #{offset})"
24
+ end
25
+ mark, size = self, @size - offset
26
+ retval = orig_plus offset
27
+ retval.instance_eval { @mark, @size = mark, size }
22
28
  retval
23
29
  end
24
30
 
25
- end
31
+ alias_method :orig_read, :read
26
32
 
27
- attr_reader :size
33
+ def read( length )
34
+ raise "Only #{@size} bytes of memory left to read " +
35
+ "(illegal attempt to read #{length} bytes)" if length > @size
36
+ orig_read length
37
+ end
28
38
 
29
- alias_method :orig_plus, :+
39
+ alias_method :orig_write, :write
30
40
 
31
- def +( offset )
32
- if offset > @size
33
- raise "Offset must not be more than #{@size} (but was #{offset})"
41
+ def write( string )
42
+ if string.bytesize > @size
43
+ raise "Must not write more than #{@size} bytes of memory " +
44
+ "(illegal attempt to write #{string.bytesize} bytes)"
45
+ end
46
+ orig_write string
34
47
  end
35
- mark, size = self, @size - offset
36
- retval = orig_plus offset
37
- retval.instance_eval { @mark, @size = mark, size }
38
- retval
48
+
39
49
  end
40
50
 
41
- alias_method :orig_read, :read
51
+ end
42
52
 
43
- def read( length )
44
- raise "Only #{@size} bytes of memory left to read " +
45
- "(illegal attempt to read #{length} bytes)" if length > @size
46
- orig_read length
47
- end
53
+ class String
48
54
 
49
- alias_method :orig_write, :write
55
+ unless method_defined? :bytesize
50
56
 
51
- def write( string )
52
- if string.bytesize > @size
53
- raise "Must not write more than #{@size} bytes of memory " +
54
- "(illegal attempt to write #{string.bytesize} bytes)"
57
+ def bytesize
58
+ size
55
59
  end
56
- orig_write string
57
- end
58
60
 
61
+ end
62
+
59
63
  end
data/source.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ require 'date'
2
+ Gem::Specification.new do |s|
3
+ s.name = %q{malloc}
4
+ s.version = '0.2.0'
5
+ s.platform = Gem::Platform::RUBY
6
+ s.date = Date.today.to_s
7
+ s.summary = %q{Object for raw memory allocation and pointer operations}
8
+ s.description = %q{This Ruby extension defines the class Hornetseye::Malloc. Hornetseye::Malloc#new allows you to allocate memory, using Hornetseye::Malloc#+ one can do pointer manipulation, and Hornetseye::Malloc#read and Hornetseye::Malloc#write provide reading Ruby strings from memory and writing Ruby strings to memory.}
9
+ s.author = %q{Jan Wedekind}
10
+ s.email = %q{jan@wedesoft.de}
11
+ s.homepage = %q{http://wedesoft.github.com/malloc/}
12
+ s.files = [ 'source.gemspec', 'binary.gemspec', 'Makefile', 'README',
13
+ 'COPYING' ] +
14
+ Dir.glob( 'lib/*.rb' ) +
15
+ Dir.glob( 'ext/*.cc' ) +
16
+ Dir.glob( 'ext/*.hh' ) +
17
+ [ 'ext/extconf.rb' ] +
18
+ Dir.glob( 'test/*.rb' )
19
+ s.test_files = Dir.glob( 'test/tc_*.rb' )
20
+ # s.default_executable = %q{...}
21
+ # s.executables = Dir.glob( 'bin/*' ).collect { |f| File.basename f }
22
+ s.require_paths = [ 'lib', 'ext' ]
23
+ s.rubyforge_project = %q{hornetseye}
24
+ s.extensions = %w{ext/extconf.rb}
25
+ s.has_rdoc = true
26
+ s.extra_rdoc_files = [ 'README' ]
27
+ s.rdoc_options = %w{--exclude=/Makefile|.*\.(cc|hh|rb)/ --main README}
28
+ end
data/test/tc_malloc.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+ require 'malloc'
3
+
4
+ class TC_Malloc < Test::Unit::TestCase
5
+
6
+ def test_new
7
+ assert_nothing_raised { Hornetseye::Malloc.new 32 }
8
+ assert_raise( ArgumentError ) { Hornetseye::Malloc.new }
9
+ end
10
+
11
+ def test_read_write
12
+ m = Hornetseye::Malloc.new 6
13
+ m.write 'abcdef'
14
+ assert_equal 'abcdef', m.read( 6 )
15
+ m.write 'ghi'
16
+ assert_equal 'ghidef', m.read( 6 )
17
+ assert_raise( RuntimeError ) { m.read 7 }
18
+ assert_raise( RuntimeError ) { m.write 'abcdefg' }
19
+ end
20
+
21
+ def test_plus
22
+ assert_raise( RuntimeError ) { Hornetseye::Malloc.new( 2 ) + ( -1 ) }
23
+ assert_nothing_raised { Hornetseye::Malloc.new( 2 ) + 2 }
24
+ assert_raise( RuntimeError ) { Hornetseye::Malloc.new( 2 ) + 3 }
25
+ m = Hornetseye::Malloc.new 6
26
+ m.write 'abcdef'
27
+ assert_equal 'cde', ( m + 2 ).read( 3 )
28
+ assert_raise( RuntimeError ) { ( m + 2 ).read 5 }
29
+ end
30
+
31
+ end
data/test/ts_malloc.rb CHANGED
@@ -1,31 +1,3 @@
1
- require 'test/unit'
2
- require 'malloc'
1
+ #!/usr/bin/env ruby
2
+ require 'tc_malloc'
3
3
 
4
- class TC_Malloc < Test::Unit::TestCase
5
-
6
- def test_new
7
- assert_nothing_raised { Malloc.new 32 }
8
- assert_raise( ArgumentError ) { Malloc.new }
9
- end
10
-
11
- def test_read_write
12
- m = Malloc.new 6
13
- m.write 'abcdef'
14
- assert_equal 'abcdef', m.read( 6 )
15
- m.write 'ghi'
16
- assert_equal 'ghidef', m.read( 6 )
17
- assert_raise( RuntimeError ) { m.read 7 }
18
- assert_raise( RuntimeError ) { m.write 'abcdefg' }
19
- end
20
-
21
- def test_plus
22
- assert_raise( RuntimeError ) { Malloc.new( 2 ) + ( -1 ) }
23
- assert_nothing_raised { Malloc.new( 2 ) + 2 }
24
- assert_raise( RuntimeError ) { Malloc.new( 2 ) + 3 }
25
- m = Malloc.new 6
26
- m.write 'abcdef'
27
- assert_equal 'cde', ( m + 2 ).read( 3 )
28
- assert_raise( RuntimeError ) { ( m + 2 ).read 5 }
29
- end
30
-
31
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: malloc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Wedekind
@@ -9,20 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-04 00:00:00 +00:00
12
+ date: 2009-12-09 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: This gem defines the class Malloc. Malloc#new allows you to allocate memory, using Malloc#+ one can do pointer manipulation, and Malloc#read and Malloc#write provide reading Ruby strings from memory and writing Ruby strings to memory.
16
+ description: This Ruby extension defines the class Hornetseye::Malloc. Hornetseye::Malloc#new allows you to allocate memory, using Hornetseye::Malloc#+ one can do pointer manipulation, and Hornetseye::Malloc#read and Hornetseye::Malloc#write provide reading Ruby strings from memory and writing Ruby strings to memory.
17
17
  email: jan@wedesoft.de
18
18
  executables: []
19
19
 
20
20
  extensions:
21
21
  - ext/extconf.rb
22
- extra_rdoc_files: []
23
-
22
+ extra_rdoc_files:
23
+ - README
24
24
  files:
25
- - malloc.gemspec
25
+ - source.gemspec
26
+ - binary.gemspec
26
27
  - Makefile
27
28
  - README
28
29
  - COPYING
@@ -34,13 +35,16 @@ files:
34
35
  - ext/malloc.hh
35
36
  - ext/extconf.rb
36
37
  - test/ts_malloc.rb
38
+ - test/tc_malloc.rb
37
39
  has_rdoc: true
38
40
  homepage: http://wedesoft.github.com/malloc/
39
41
  licenses: []
40
42
 
41
43
  post_install_message:
42
- rdoc_options: []
43
-
44
+ rdoc_options:
45
+ - --exclude=/Makefile|.*\.(cc|hh|rb)/
46
+ - --main
47
+ - README
44
48
  require_paths:
45
49
  - lib
46
50
  - ext
@@ -64,4 +68,4 @@ signing_key:
64
68
  specification_version: 3
65
69
  summary: Object for raw memory allocation and pointer operations
66
70
  test_files:
67
- - test/ts_malloc.rb
71
+ - test/tc_malloc.rb
data/malloc.gemspec DELETED
@@ -1,27 +0,0 @@
1
- require 'date'
2
- Gem::Specification.new do |s|
3
- s.name = %q{malloc}
4
- s.version = '0.1.6'
5
- s.platform = Gem::Platform::RUBY
6
- s.date = Date.today.to_s
7
- s.summary = %q{Object for raw memory allocation and pointer operations}
8
- s.description = %q{This gem defines the class Malloc. Malloc#new allows you to allocate memory, using Malloc#+ one can do pointer manipulation, and Malloc#read and Malloc#write provide reading Ruby strings from memory and writing Ruby strings to memory.}
9
- s.author = %q{Jan Wedekind}
10
- s.email = %q{jan@wedesoft.de}
11
- s.homepage = %q{http://wedesoft.github.com/malloc/}
12
- s.files = [ 'malloc.gemspec', 'Makefile', 'README', 'COPYING' ] +
13
- Dir.glob( 'lib/*.rb' ) +
14
- Dir.glob( 'ext/*.cc' ) +
15
- Dir.glob( 'ext/*.hh' ) +
16
- [ 'ext/extconf.rb',
17
- 'test/ts_malloc.rb' ]
18
- s.test_files = [ 'test/ts_malloc.rb' ]
19
- # s.default_executable = %q{...}
20
- # s.executables = Dir.glob( 'bin/*' ).collect { |f| File.basename f }
21
- s.require_paths = [ 'lib', 'ext' ]
22
- s.rubyforge_project = %q{hornetseye}
23
- s.extensions = %w{ext/extconf.rb}
24
- s.has_rdoc = false
25
- # s.extra_rdoc_files = [ 'README' ]
26
- # s.rdoc_options = %w{--main README}
27
- end