Permalink
Browse files

Adding Yardoc documentation.

  • Loading branch information...
1 parent 16c83cc commit 094c1203303706febe950032b25222b923dcfc01 @wedesoft committed Dec 10, 2009
Showing with 28 additions and 5 deletions.
  1. +1 −1 Makefile
  2. +1 −1 binary.gemspec
  3. +23 −0 lib/malloc_ext.rb
  4. +1 −1 source.gemspec
  5. +2 −2 test/tc_malloc.rb
View
@@ -2,7 +2,7 @@
.SUFFIXES: .gem .o .cc .hh .rb .tar .gz .bz2
RUBY_VERSION = 1.8
-MALLOC_VERSION = 0.2.0
+MALLOC_VERSION = 0.2.1
CP = cp
RM = rm -Rf
View
@@ -1,7 +1,7 @@
require 'date'
Gem::Specification.new do |s|
s.name = %q{malloc}
- s.version = '0.2.0'
+ s.version = '0.2.1'
s.platform = Gem::Platform::CURRENT
s.date = Date.today.to_s
s.summary = %q{Object for raw memory allocation and pointer operations}
View
@@ -1,11 +1,17 @@
+# Namespace of the Hornetseye project.
module Hornetseye
+ # Class for allocating raw memory and for doing pointer operations.
class Malloc
class << self
alias_method :orig_new, :new
+ # Create new Malloc object.
+ #
+ # @param [size] Number of bytes to allocate.
+ # @return [Malloc] A new Malloc object.
def new( size )
retval = orig_new size
retval.instance_eval { @size = size }
@@ -16,10 +22,15 @@ def new( size )
end
+ # Number of bytes allocated.
attr_reader :size
alias_method :orig_plus, :+
+ # Operator for doing pointer arithmetic.
+ #
+ # @param [offset] Non-negative offset for pointer.
+ # @return [Malloc] A new Malloc object.
def +( offset )
if offset > @size
raise "Offset must not be more than #{@size} (but was #{offset})"
@@ -34,6 +45,10 @@ def +( offset )
alias_method :orig_read, :read
+ # Read data from memory.
+ #
+ # @param [length] Number of bytes to read.
+ # @return [String] A string containing the data.
def read( length )
raise "Only #{@size} bytes of memory left to read " +
"(illegal attempt to read #{length} bytes)" if length > @size
@@ -44,6 +59,10 @@ def read( length )
alias_method :orig_write, :write
+ # Write data to memory.
+ #
+ # @param [string] A string with the data.
+ # @return [String] Returns the parameter `string`.
def write( string )
if string.bytesize > @size
raise "Must not write more than #{@size} bytes of memory " +
@@ -58,10 +77,14 @@ def write( string )
end
+# The string class of the standard library.
class String
unless method_defined? :bytesize
+ # This method won't be overriden if it is defined already.
+ #
+ # Provided for compatibility with Ruby 1.8.6. Same as #size.
def bytesize
size
end
View
@@ -1,7 +1,7 @@
require 'date'
Gem::Specification.new do |s|
s.name = %q{malloc}
- s.version = '0.2.0'
+ s.version = '0.2.1'
s.platform = Gem::Platform::RUBY
s.date = Date.today.to_s
s.summary = %q{Object for raw memory allocation and pointer operations}
View
@@ -10,9 +10,9 @@ def test_new
def test_read_write
m = Hornetseye::Malloc.new 6
- m.write 'abcdef'
+ assert_equal 'abcdef', m.write( 'abcdef' )
assert_equal 'abcdef', m.read( 6 )
- m.write 'ghi'
+ assert_equal 'ghi', m.write( 'ghi' )
assert_equal 'ghidef', m.read( 6 )
assert_raise( RuntimeError ) { m.read 7 }
assert_raise( RuntimeError ) { m.write 'abcdefg' }

0 comments on commit 094c120

Please sign in to comment.