malloc 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Makefile +7 -3
- data/README +0 -1
- data/binary.gemspec +4 -4
- data/lib/malloc_ext.rb +31 -0
- data/source.gemspec +4 -4
- data/test/tc_malloc.rb +3 -3
- metadata +7 -9
data/Makefile
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
.SUFFIXES: .gem .o .cc .hh .rb .tar .gz .bz2
|
3
3
|
|
4
4
|
RUBY_VERSION = 1.8
|
5
|
-
MALLOC_VERSION = 0.2.
|
5
|
+
MALLOC_VERSION = 0.2.1
|
6
6
|
|
7
7
|
CP = cp
|
8
|
-
RM = rm -
|
8
|
+
RM = rm -Rf
|
9
9
|
MKDIR = mkdir -p
|
10
10
|
GEM = gem$(RUBY_VERSION)
|
11
11
|
RUBY = ruby$(RUBY_VERSION)
|
12
|
+
YARDOC = yardoc
|
12
13
|
TAR = tar
|
13
14
|
GIT = git
|
14
15
|
SITELIBDIR = $(shell $(RUBY) -r mkmf -e "puts \"\#{Config::CONFIG['sitelibdir']}\"")
|
@@ -46,6 +47,9 @@ install-gem:: malloc-$(MALLOC_VERSION).gem
|
|
46
47
|
uninstall-gem::
|
47
48
|
$(GEM) uninstall malloc || echo Nothing to uninstall
|
48
49
|
|
50
|
+
yardoc:: README $(LIB)
|
51
|
+
$(YARDOC)
|
52
|
+
|
49
53
|
check:: ext/malloc.so $(LIB) $(TEST)
|
50
54
|
$(RUBY) -rrubygems -Iext -Ilib -Itest test/ts_malloc.rb
|
51
55
|
|
@@ -81,5 +85,5 @@ malloc-$(MALLOC_VERSION).tar.bz2: $(SOURCES)
|
|
81
85
|
$(TAR) cjf $@ $(SOURCES)
|
82
86
|
|
83
87
|
clean::
|
84
|
-
|
88
|
+
$(RM) *~ ext/*~ ext/*.o ext/*.so ext/Makefile lib/*~ lib/*.so test/*~ *.gem doc
|
85
89
|
|
data/README
CHANGED
@@ -1,2 +1 @@
|
|
1
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.
|
2
|
-
|
data/binary.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'date'
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = %q{malloc}
|
4
|
-
s.version = '0.2.
|
4
|
+
s.version = '0.2.1'
|
5
5
|
s.platform = Gem::Platform::CURRENT
|
6
6
|
s.date = Date.today.to_s
|
7
7
|
s.summary = %q{Object for raw memory allocation and pointer operations}
|
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = Dir.glob( 'test/tc_*.rb' )
|
17
17
|
s.require_paths = [ 'lib', 'ext' ]
|
18
18
|
s.rubyforge_project = %q{hornetseye}
|
19
|
-
s.has_rdoc =
|
20
|
-
s.extra_rdoc_files = [ 'README' ]
|
21
|
-
s.rdoc_options = %w{--exclude=/Makefile|.*\.(cc|hh|rb)/ --main README}
|
19
|
+
s.has_rdoc = 'yard'
|
20
|
+
# s.extra_rdoc_files = [ 'README' ]
|
21
|
+
# s.rdoc_options = %w{--exclude=/Makefile|.*\.(cc|hh|rb)/ --main README}
|
22
22
|
end
|
data/lib/malloc_ext.rb
CHANGED
@@ -1,23 +1,36 @@
|
|
1
|
+
# Namespace of the Hornetseye project.
|
1
2
|
module Hornetseye
|
2
3
|
|
4
|
+
# Class for allocating raw memory and for doing pointer operations.
|
3
5
|
class Malloc
|
4
6
|
|
5
7
|
class << self
|
6
8
|
|
7
9
|
alias_method :orig_new, :new
|
8
10
|
|
11
|
+
# Create new Malloc object.
|
12
|
+
#
|
13
|
+
# @param [size] Number of bytes to allocate.
|
14
|
+
# @return [Malloc] A new Malloc object.
|
9
15
|
def new( size )
|
10
16
|
retval = orig_new size
|
11
17
|
retval.instance_eval { @size = size }
|
12
18
|
retval
|
13
19
|
end
|
14
20
|
|
21
|
+
private :orig_new
|
22
|
+
|
15
23
|
end
|
16
24
|
|
25
|
+
# Number of bytes allocated.
|
17
26
|
attr_reader :size
|
18
27
|
|
19
28
|
alias_method :orig_plus, :+
|
20
29
|
|
30
|
+
# Operator for doing pointer arithmetic.
|
31
|
+
#
|
32
|
+
# @param [offset] Non-negative offset for pointer.
|
33
|
+
# @return [Malloc] A new Malloc object.
|
21
34
|
def +( offset )
|
22
35
|
if offset > @size
|
23
36
|
raise "Offset must not be more than #{@size} (but was #{offset})"
|
@@ -28,16 +41,28 @@ module Hornetseye
|
|
28
41
|
retval
|
29
42
|
end
|
30
43
|
|
44
|
+
private :orig_plus
|
45
|
+
|
31
46
|
alias_method :orig_read, :read
|
32
47
|
|
48
|
+
# Read data from memory.
|
49
|
+
#
|
50
|
+
# @param [length] Number of bytes to read.
|
51
|
+
# @return [String] A string containing the data.
|
33
52
|
def read( length )
|
34
53
|
raise "Only #{@size} bytes of memory left to read " +
|
35
54
|
"(illegal attempt to read #{length} bytes)" if length > @size
|
36
55
|
orig_read length
|
37
56
|
end
|
38
57
|
|
58
|
+
private :orig_read
|
59
|
+
|
39
60
|
alias_method :orig_write, :write
|
40
61
|
|
62
|
+
# Write data to memory.
|
63
|
+
#
|
64
|
+
# @param [string] A string with the data.
|
65
|
+
# @return [String] Returns the parameter `string`.
|
41
66
|
def write( string )
|
42
67
|
if string.bytesize > @size
|
43
68
|
raise "Must not write more than #{@size} bytes of memory " +
|
@@ -46,14 +71,20 @@ module Hornetseye
|
|
46
71
|
orig_write string
|
47
72
|
end
|
48
73
|
|
74
|
+
private :orig_write
|
75
|
+
|
49
76
|
end
|
50
77
|
|
51
78
|
end
|
52
79
|
|
80
|
+
# The string class of the standard library.
|
53
81
|
class String
|
54
82
|
|
55
83
|
unless method_defined? :bytesize
|
56
84
|
|
85
|
+
# This method won't be overriden if it is defined already.
|
86
|
+
#
|
87
|
+
# Provided for compatibility with Ruby 1.8.6. Same as #size.
|
57
88
|
def bytesize
|
58
89
|
size
|
59
90
|
end
|
data/source.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'date'
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = %q{malloc}
|
4
|
-
s.version = '0.2.
|
4
|
+
s.version = '0.2.1'
|
5
5
|
s.platform = Gem::Platform::RUBY
|
6
6
|
s.date = Date.today.to_s
|
7
7
|
s.summary = %q{Object for raw memory allocation and pointer operations}
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.require_paths = [ 'lib', 'ext' ]
|
23
23
|
s.rubyforge_project = %q{hornetseye}
|
24
24
|
s.extensions = %w{ext/extconf.rb}
|
25
|
-
s.has_rdoc =
|
26
|
-
s.extra_rdoc_files = [ 'README' ]
|
27
|
-
s.rdoc_options = %w{--exclude=/Makefile|.*\.(cc|hh|rb)/ --main README}
|
25
|
+
s.has_rdoc = 'yard'
|
26
|
+
# s.extra_rdoc_files = [ 'README' ]
|
27
|
+
# s.rdoc_options = %w{--exclude=/Makefile|.*\.(cc|hh|rb)/ --main README}
|
28
28
|
end
|
data/test/tc_malloc.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
require 'malloc'
|
2
|
+
Kernel::require 'malloc'
|
3
3
|
|
4
4
|
class TC_Malloc < Test::Unit::TestCase
|
5
5
|
|
@@ -10,9 +10,9 @@ class TC_Malloc < Test::Unit::TestCase
|
|
10
10
|
|
11
11
|
def test_read_write
|
12
12
|
m = Hornetseye::Malloc.new 6
|
13
|
-
m.write 'abcdef'
|
13
|
+
assert_equal 'abcdef', m.write( 'abcdef' )
|
14
14
|
assert_equal 'abcdef', m.read( 6 )
|
15
|
-
m.write 'ghi'
|
15
|
+
assert_equal 'ghi', m.write( 'ghi' )
|
16
16
|
assert_equal 'ghidef', m.read( 6 )
|
17
17
|
assert_raise( RuntimeError ) { m.read 7 }
|
18
18
|
assert_raise( RuntimeError ) { m.write 'abcdefg' }
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Wedekind
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-10 00:00:00 +00:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -19,8 +19,8 @@ executables: []
|
|
19
19
|
|
20
20
|
extensions:
|
21
21
|
- ext/extconf.rb
|
22
|
-
extra_rdoc_files:
|
23
|
-
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
24
|
files:
|
25
25
|
- source.gemspec
|
26
26
|
- binary.gemspec
|
@@ -36,15 +36,13 @@ files:
|
|
36
36
|
- ext/extconf.rb
|
37
37
|
- test/ts_malloc.rb
|
38
38
|
- test/tc_malloc.rb
|
39
|
-
has_rdoc:
|
39
|
+
has_rdoc: yard
|
40
40
|
homepage: http://wedesoft.github.com/malloc/
|
41
41
|
licenses: []
|
42
42
|
|
43
43
|
post_install_message:
|
44
|
-
rdoc_options:
|
45
|
-
|
46
|
-
- --main
|
47
|
-
- README
|
44
|
+
rdoc_options: []
|
45
|
+
|
48
46
|
require_paths:
|
49
47
|
- lib
|
50
48
|
- ext
|