Class: Malloc
- Inherits:
-
Object
- Object
- Malloc
- Defined in:
- lib/malloc_ext.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
- #+(offset) ⇒ Object
- #orig_plus ⇒ Object
- #orig_read ⇒ Object
- #orig_write ⇒ Object
- #read(length) ⇒ Object
- #write(string) ⇒ Object
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
27 28 29 |
# File 'lib/malloc_ext.rb', line 27 def size @size end |
Class Method Details
.new(size) ⇒ Object
19 20 21 22 23 |
# File 'lib/malloc_ext.rb', line 19 def new( size ) retval = orig_new size retval.instance_eval { @size = size } retval end |
.orig_new ⇒ Object
17 |
# File 'lib/malloc_ext.rb', line 17 alias_method :orig_new, :new |
Instance Method Details
#+(offset) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/malloc_ext.rb', line 31 def +( offset ) if offset > @size raise "Offset must not be more than #{@size} (but was #{offset})" end mark, size = self, @size - offset retval = orig_plus offset retval.instance_eval { @mark, @size = mark, size } retval end |
#orig_plus ⇒ Object
29 |
# File 'lib/malloc_ext.rb', line 29 alias_method :orig_plus, :+ |
#orig_read ⇒ Object
41 |
# File 'lib/malloc_ext.rb', line 41 alias_method :orig_read, :read |
#orig_write ⇒ Object
49 |
# File 'lib/malloc_ext.rb', line 49 alias_method :orig_write, :write |
#read(length) ⇒ Object
43 44 45 46 47 |
# File 'lib/malloc_ext.rb', line 43 def read( length ) raise "Only #{@size} bytes of memory left to read " + "(illegal attempt to read #{length} bytes)" if length > @size orig_read length end |
#write(string) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/malloc_ext.rb', line 51 def write( string ) if string.bytesize > @size raise "Must not write more than #{@size} bytes of memory " + "(illegal attempt to write #{string.bytesize} bytes)" end orig_write string end |