Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Implemented Malloc#export

  • Loading branch information...
commit bf413c901fdb1185ec9a2ad2812c14441ab12a9e 1 parent 0f078ae
@wedesoft authored
Showing with 18 additions and 1 deletion.
  1. +1 −1  Rakefile
  2. +11 −0 lib/malloc_ext.rb
  3. +6 −0 test/tc_malloc.rb
View
2  Rakefile
@@ -7,7 +7,7 @@ require 'rake/loaders/makefile'
require 'rbconfig'
PKG_NAME = 'malloc'
-PKG_VERSION = '1.3.7'
+PKG_VERSION = '1.4.0'
CFG = RbConfig::CONFIG
CXX = ENV[ 'CXX' ] || 'g++'
RB_FILES = FileList[ 'lib/**/*.rb' ]
View
11 lib/malloc_ext.rb
@@ -113,6 +113,17 @@ def to_s
inspect
end
+ # Read complete data
+ #
+ # @example Export to string
+ # m = Malloc.new 3
+ # m.write 'abc'
+ # m.export
+ # "abc"
+ def export
+ read @size
+ end
+
# Operator for doing pointer arithmetic
#
# @example Pointer arithmetic
View
6 test/tc_malloc.rb
@@ -61,6 +61,12 @@ def test_read_write
assert_raise( RuntimeError ) { m.write Malloc.new( 7 ) }
end
+ def test_export
+ m = Malloc.new 3
+ m.write 'abc'
+ assert_equal 'abc', m.export
+ end
+
def test_plus
assert_raise( RuntimeError ) { Malloc.new( 2 ) + ( -1 ) }
assert_nothing_raised { Malloc.new( 2 ) + 2 }
Please sign in to comment.
Something went wrong with that request. Please try again.