malloc 1.0.0 → 1.1.1
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.
- data/COPYING +1 -1
- data/Rakefile +12 -11
- data/ext/error.hh +1 -2
- data/ext/malloc.cc +2 -2
- data/lib/malloc_ext.rb +79 -43
- data/test/tc_malloc.rb +17 -0
- data/test/ts_malloc.rb +16 -0
- metadata +29 -9
- data/ext/error.cc +0 -20
data/COPYING
CHANGED
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'rake/packagetask'
|
|
6
6
|
require 'rbconfig'
|
7
7
|
|
8
8
|
PKG_NAME = 'malloc'
|
9
|
-
PKG_VERSION = '1.
|
9
|
+
PKG_VERSION = '1.1.1'
|
10
10
|
CXX = ENV[ 'CXX' ] || 'g++'
|
11
11
|
STRIP = ENV[ 'STRIP' ] || 'strip'
|
12
12
|
RB_FILES = FileList[ 'lib/**/*.rb' ]
|
@@ -54,8 +54,8 @@ desc 'Install Ruby extension'
|
|
54
54
|
task :install => :all do
|
55
55
|
verbose true do
|
56
56
|
for f in RB_FILES do
|
57
|
-
FileUtils.mkdir_p "#{$SITELIBDIR}/#{File.dirname
|
58
|
-
FileUtils.cp_r f, "#{$SITELIBDIR}/#{f
|
57
|
+
FileUtils.mkdir_p "#{$SITELIBDIR}/#{File.dirname f.gsub( /^lib\//, '' )}"
|
58
|
+
FileUtils.cp_r f, "#{$SITELIBDIR}/#{f.gsub( /^lib\//, '' )}"
|
59
59
|
end
|
60
60
|
FileUtils.mkdir_p $SITEARCHDIR
|
61
61
|
FileUtils.cp SO_FILE, "#{$SITEARCHDIR}/#{File.basename SO_FILE}"
|
@@ -66,7 +66,7 @@ desc 'Uninstall Ruby extension'
|
|
66
66
|
task :uninstall do
|
67
67
|
verbose true do
|
68
68
|
for f in RB_FILES do
|
69
|
-
FileUtils.rm_f "#{$SITELIBDIR}/#{f
|
69
|
+
FileUtils.rm_f "#{$SITELIBDIR}/#{f.gsub /^lib\//, ''}"
|
70
70
|
end
|
71
71
|
FileUtils.rm_f "#{$SITEARCHDIR}/#{File.basename SO_FILE}"
|
72
72
|
end
|
@@ -112,6 +112,7 @@ begin
|
|
112
112
|
s.has_rdoc = 'yard'
|
113
113
|
s.extra_rdoc_files = []
|
114
114
|
s.rdoc_options = %w{--no-private}
|
115
|
+
s.add_development_dependency %q{rake}
|
115
116
|
end
|
116
117
|
GEM_SOURCE = "#{PKG_NAME}-#{PKG_VERSION}.gem"
|
117
118
|
$BINSPEC = Gem::Specification.new do |s|
|
@@ -128,7 +129,6 @@ begin
|
|
128
129
|
s.test_files = TC_FILES
|
129
130
|
s.require_paths = [ 'lib', 'ext' ]
|
130
131
|
s.rubyforge_project = %q{hornetseye}
|
131
|
-
s.add_development_dependency %q{rake}
|
132
132
|
s.has_rdoc = 'yard'
|
133
133
|
s.extra_rdoc_files = []
|
134
134
|
s.rdoc_options = %w{--no-private}
|
@@ -137,15 +137,17 @@ begin
|
|
137
137
|
desc "Build the gem file #{GEM_SOURCE}"
|
138
138
|
task :gem => [ "pkg/#{GEM_SOURCE}" ]
|
139
139
|
file "pkg/#{GEM_SOURCE}" => [ 'pkg' ] + $SPEC.files do
|
140
|
-
|
141
|
-
|
142
|
-
|
140
|
+
when_writing 'Creating GEM' do
|
141
|
+
Gem::Builder.new( $SPEC ).build
|
142
|
+
verbose true do
|
143
|
+
FileUtils.mv GEM_SOURCE, "pkg/#{GEM_SOURCE}"
|
144
|
+
end
|
143
145
|
end
|
144
146
|
end
|
145
147
|
desc "Build the gem file #{GEM_BINARY}"
|
146
148
|
task :gem_binary => [ "pkg/#{GEM_BINARY}" ]
|
147
149
|
file "pkg/#{GEM_BINARY}" => [ 'pkg' ] + $BINSPEC.files do
|
148
|
-
when_writing 'Creating GEM' do
|
150
|
+
when_writing 'Creating binary GEM' do
|
149
151
|
Gem::Builder.new( $BINSPEC ).build
|
150
152
|
verbose true do
|
151
153
|
FileUtils.mv GEM_BINARY, "pkg/#{GEM_BINARY}"
|
@@ -160,8 +162,7 @@ rule '.o' => '.cc' do |t|
|
|
160
162
|
sh "#{CXX} #{$CXXFLAGS} -c -o #{t.name} #{t.source}"
|
161
163
|
end
|
162
164
|
|
163
|
-
file 'ext/error.o' => [ 'ext/error.cc', 'ext/error.hh' ]
|
164
165
|
file 'ext/malloc.o' => [ 'ext/malloc.cc', 'ext/malloc.hh', 'ext/error.hh' ]
|
165
166
|
|
166
167
|
CLEAN.include 'ext/*.o'
|
167
|
-
CLOBBER.include SO_FILE, 'doc'
|
168
|
+
CLOBBER.include SO_FILE, 'doc', '.yardoc'
|
data/ext/error.hh
CHANGED
@@ -35,11 +35,10 @@ public:
|
|
35
35
|
virtual const char* what(void) const throw() {
|
36
36
|
temp = m_message.str();
|
37
37
|
return temp.c_str();
|
38
|
-
return NULL;
|
39
38
|
}
|
40
39
|
protected:
|
41
40
|
std::ostringstream m_message;
|
42
|
-
|
41
|
+
mutable std::string temp;
|
43
42
|
};
|
44
43
|
|
45
44
|
#define ERRORMACRO( condition, class, params, message ) \
|
data/ext/malloc.cc
CHANGED
@@ -53,7 +53,7 @@ VALUE Malloc::mallocNew( VALUE rbClass, VALUE rbSize )
|
|
53
53
|
<< " bytes of memory" );
|
54
54
|
retVal = Data_Wrap_Struct( rbClass, 0, xfree, (void *)self );
|
55
55
|
} catch( std::exception &e ) {
|
56
|
-
rb_raise( rb_eRuntimeError, e.what() );
|
56
|
+
rb_raise( rb_eRuntimeError, "%s", e.what() );
|
57
57
|
};
|
58
58
|
return retVal;
|
59
59
|
}
|
@@ -68,7 +68,7 @@ VALUE Malloc::mallocPlus( VALUE rbSelf, VALUE rbOffset )
|
|
68
68
|
<< offset << ')' );
|
69
69
|
retVal = Data_Wrap_Struct( cRubyClass, 0, 0, (void *)( self + offset ) );
|
70
70
|
} catch( std::exception &e ) {
|
71
|
-
rb_raise( rb_eRuntimeError, e.what() );
|
71
|
+
rb_raise( rb_eRuntimeError, "%s", e.what() );
|
72
72
|
};
|
73
73
|
return retVal;
|
74
74
|
}
|
data/lib/malloc_ext.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
# malloc - Raw memory allocation for Ruby
|
2
|
+
# Copyright (C) 2010 Jan Wedekind
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
1
17
|
# String#bytesize is defined if it does not exist already
|
2
18
|
class String
|
3
19
|
|
@@ -29,13 +45,15 @@ module Hornetseye
|
|
29
45
|
# Allocate the specified number of bytes of raw memory.
|
30
46
|
#
|
31
47
|
# @example Allocate raw memory
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
48
|
+
# require 'malloc'
|
49
|
+
# include Hornetseye
|
50
|
+
# m = Malloc.new 32
|
51
|
+
# # Malloc(32)
|
36
52
|
#
|
37
53
|
# @param [Integer] size Number of bytes to allocate.
|
38
54
|
# @return [Malloc] A new Malloc object.
|
55
|
+
#
|
56
|
+
# @see Malloc
|
39
57
|
def new( size )
|
40
58
|
retval = orig_new size
|
41
59
|
retval.instance_eval { @size = size }
|
@@ -49,13 +67,13 @@ module Hornetseye
|
|
49
67
|
# Number of bytes allocated
|
50
68
|
#
|
51
69
|
# @example Querying size of allocated memory
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
70
|
+
# require 'malloc'
|
71
|
+
# include Hornetseye
|
72
|
+
# m = Malloc.new 32
|
73
|
+
# m.size
|
74
|
+
# # 32
|
75
|
+
# ( m + 8 ).size
|
76
|
+
# # 24
|
59
77
|
#
|
60
78
|
# @return [Integer] Size of allocated memory.
|
61
79
|
attr_reader :size
|
@@ -63,9 +81,9 @@ module Hornetseye
|
|
63
81
|
# Display information about this object
|
64
82
|
#
|
65
83
|
# @example Displaying information about a Malloc object
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
84
|
+
# require 'malloc'
|
85
|
+
# Hornetseye::Malloc.new( 8 ).inspect
|
86
|
+
# "Malloc(8)"
|
69
87
|
#
|
70
88
|
# @return [String] A string with information about this object.
|
71
89
|
def inspect
|
@@ -75,12 +93,12 @@ module Hornetseye
|
|
75
93
|
# Read data from memory
|
76
94
|
#
|
77
95
|
# @example Convert data of Malloc object to string
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
96
|
+
# require 'malloc'
|
97
|
+
# include Hornetseye
|
98
|
+
# m = Malloc.new 5
|
99
|
+
# m.write 'abcde'
|
100
|
+
# m.to_s
|
101
|
+
# "abcde"
|
84
102
|
#
|
85
103
|
# @return [String] A string containing the data.
|
86
104
|
#
|
@@ -92,15 +110,15 @@ module Hornetseye
|
|
92
110
|
# Operator for doing pointer arithmetic
|
93
111
|
#
|
94
112
|
# @example Pointer arithmetic
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
113
|
+
# require 'malloc'
|
114
|
+
# include Hornetseye
|
115
|
+
# m = Malloc.new 4
|
116
|
+
# # Malloc(4)
|
117
|
+
# m.write 'abcd'
|
118
|
+
# n = m + 2
|
119
|
+
# # Malloc(2)
|
120
|
+
# n.read 2
|
121
|
+
# # "cd"
|
104
122
|
#
|
105
123
|
# @param [Integer] offset Non-negative offset for pointer.
|
106
124
|
# @return [Malloc] A new Malloc object.
|
@@ -119,13 +137,13 @@ module Hornetseye
|
|
119
137
|
# Read data from memory
|
120
138
|
#
|
121
139
|
# @example Reading and writing data
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
140
|
+
# require 'malloc'
|
141
|
+
# include Hornetseye
|
142
|
+
# m = Malloc.new 4
|
143
|
+
# # Malloc(4)
|
144
|
+
# m.write 'abcd'
|
145
|
+
# m.read 2
|
146
|
+
# # "ab"
|
129
147
|
#
|
130
148
|
# @param [Integer] length Number of bytes to read.
|
131
149
|
# @return [String] A string containing the data.
|
@@ -143,13 +161,13 @@ module Hornetseye
|
|
143
161
|
# Write data to memory
|
144
162
|
#
|
145
163
|
# @example Reading and writing data
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
#
|
164
|
+
# require 'malloc'
|
165
|
+
# include Hornetseye
|
166
|
+
# m = Malloc.new 4
|
167
|
+
# # Malloc(4)
|
168
|
+
# m.write 'abcd'
|
169
|
+
# m.read 2
|
170
|
+
# # "ab"
|
153
171
|
#
|
154
172
|
# @param [String] string A string with the data.
|
155
173
|
# @return [String] Returns the parameter +string+.
|
@@ -167,4 +185,22 @@ module Hornetseye
|
|
167
185
|
|
168
186
|
end
|
169
187
|
|
188
|
+
# Shortcut for instantiating Malloc object
|
189
|
+
#
|
190
|
+
# @example Create malloc object
|
191
|
+
# require 'malloc'
|
192
|
+
# include Hornetseye
|
193
|
+
# m = Malloc 4
|
194
|
+
# # Malloc(4)
|
195
|
+
#
|
196
|
+
# @param [Integer] size Number of bytes to allocate.
|
197
|
+
# @return [Malloc] A new Malloc object.
|
198
|
+
#
|
199
|
+
# @see Malloc.new
|
200
|
+
def Malloc( size )
|
201
|
+
Malloc.new size
|
202
|
+
end
|
203
|
+
|
204
|
+
module_function :Malloc
|
205
|
+
|
170
206
|
end
|
data/test/tc_malloc.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
# malloc - Raw memory allocation for Ruby
|
2
|
+
# Copyright (C) 2010 Jan Wedekind
|
3
|
+
#
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
1
17
|
require 'test/unit'
|
2
18
|
Kernel::require 'malloc'
|
3
19
|
|
@@ -5,6 +21,7 @@ class TC_Malloc < Test::Unit::TestCase
|
|
5
21
|
|
6
22
|
def test_new
|
7
23
|
assert_nothing_raised { Hornetseye::Malloc.new 32 }
|
24
|
+
assert_nothing_raised { Hornetseye::Malloc 32 }
|
8
25
|
assert_raise( ArgumentError ) { Hornetseye::Malloc.new }
|
9
26
|
end
|
10
27
|
|
data/test/ts_malloc.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# malloc - Raw memory allocation for Ruby
|
3
|
+
# Copyright (C) 2010 Jan Wedekind
|
4
|
+
#
|
5
|
+
# This program is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License as published by
|
7
|
+
# the Free Software Foundation, either version 3 of the License, or
|
8
|
+
# (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
+
|
2
18
|
require 'tc_malloc'
|
3
19
|
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: malloc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 1.1.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jan Wedekind
|
@@ -9,10 +14,22 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-09-25 00:00:00 +01:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rake
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
16
33
|
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
34
|
email: jan@wedesoft.de
|
18
35
|
executables: []
|
@@ -27,11 +44,10 @@ files:
|
|
27
44
|
- COPYING
|
28
45
|
- .document
|
29
46
|
- lib/malloc_ext.rb
|
30
|
-
- ext/error.cc
|
31
47
|
- ext/malloc.cc
|
32
48
|
- ext/init.cc
|
33
|
-
- ext/error.hh
|
34
49
|
- ext/malloc.hh
|
50
|
+
- ext/error.hh
|
35
51
|
- test/ts_malloc.rb
|
36
52
|
- test/tc_malloc.rb
|
37
53
|
has_rdoc: yard
|
@@ -45,21 +61,25 @@ require_paths:
|
|
45
61
|
- lib
|
46
62
|
- ext
|
47
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
48
65
|
requirements:
|
49
66
|
- - ">="
|
50
67
|
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 0
|
51
70
|
version: "0"
|
52
|
-
version:
|
53
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
54
73
|
requirements:
|
55
74
|
- - ">="
|
56
75
|
- !ruby/object:Gem::Version
|
76
|
+
segments:
|
77
|
+
- 0
|
57
78
|
version: "0"
|
58
|
-
version:
|
59
79
|
requirements: []
|
60
80
|
|
61
81
|
rubyforge_project: hornetseye
|
62
|
-
rubygems_version: 1.3.
|
82
|
+
rubygems_version: 1.3.7
|
63
83
|
signing_key:
|
64
84
|
specification_version: 3
|
65
85
|
summary: Object for raw memory allocation and pointer operations
|
data/ext/error.cc
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
/* HornetsEye - Computer Vision with Ruby
|
2
|
-
Copyright (C) 2006, 2007, 2008, 2009 Jan Wedekind
|
3
|
-
|
4
|
-
This program is free software: you can redistribute it and/or modify
|
5
|
-
it under the terms of the GNU General Public License as published by
|
6
|
-
the Free Software Foundation, either version 3 of the License, or
|
7
|
-
(at your option) any later version.
|
8
|
-
|
9
|
-
This program is distributed in the hope that it will be useful,
|
10
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
-
GNU General Public License for more details.
|
13
|
-
|
14
|
-
You should have received a copy of the GNU General Public License
|
15
|
-
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
16
|
-
#include "error.hh"
|
17
|
-
|
18
|
-
using namespace std;
|
19
|
-
|
20
|
-
string Error::temp;
|