jit_buffer 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4be349fa4c465e35b8ef2bd1af1c80d26591146805978803b77ce24487c10724
4
- data.tar.gz: 175b24a10629507a105dd34670c1eae51537ceccc2eae60c3fc907a9c16ffb33
3
+ metadata.gz: 042d1a4c8ee681237a3829d1ae950a726558383b26262d828aab558e6bb51bfa
4
+ data.tar.gz: 7ef264b37a228f8845938c7d10162bb4b39aee153dd8f8a11b59774a1688423b
5
5
  SHA512:
6
- metadata.gz: 23302857f3b5646d1c403cfbced18a4f7a98e8af0b93c070a9bc5a0e7c112be3a59bfbfad1952c41991213ad626becc4a36b43ca5040a751518c9d1c23d66be2
7
- data.tar.gz: 22690c0bbbc23340c6bbfce56399861834d8960337180f2cc25cfeddee2573887da491aa9e92daf985617b42c30e5e816b2ce38e7564e7bef4c0b42af4331989
6
+ metadata.gz: 5c3eb5c03d5c91ed27cb1dd13448e6a5ef95ade94388e9fd0f50c6bcda6d7d449432b0d1c06425ca5c795f9df74e19465ca6823f6d34a18023557437ae3e7bc3
7
+ data.tar.gz: c57d3e2fc3c0102b3de9a9f6a132b11d3b77d0d57653845ede834035b8fdff95ea2e633e140240fab56e01e50cef99d385c97eea0241d4ab2a219a737efb3d93
data/lib/jit_buffer.rb CHANGED
@@ -8,7 +8,7 @@ class Fiddle::Function
8
8
  end unless Fiddle::Function.method_defined?(:to_proc)
9
9
 
10
10
  class JITBuffer
11
- VERSION = '1.0.2'
11
+ VERSION = '1.0.3'
12
12
 
13
13
  class Exception < StandardError
14
14
  end
@@ -93,7 +93,7 @@ class JITBuffer
93
93
  super(MMAP.mmap_buffer(size), size)
94
94
  end
95
95
 
96
- attr_reader :pos
96
+ attr_reader :pos, :size
97
97
 
98
98
  def initialize memory, size
99
99
  @writeable = false
@@ -112,7 +112,7 @@ class JITBuffer
112
112
 
113
113
  def write bytes
114
114
  raise(ReadOnlyException, "Buffer is read only!") unless @writeable
115
- raise OutOfBoundsException if pos + bytes.bytesize >= @size
115
+ raise OutOfBoundsException if pos + bytes.bytesize > @size
116
116
  @memory[pos, bytes.length] = bytes
117
117
  @pos += bytes.bytesize
118
118
  end
@@ -125,7 +125,7 @@ class JITBuffer
125
125
  end
126
126
 
127
127
  def read len
128
- raise(OutOfBoundsException, "You've gone too far!") if pos + len >= @size
128
+ raise(OutOfBoundsException, "You've gone too far!") if pos + len > @size
129
129
  x = @memory[pos, pos + len]
130
130
  @pos += len
131
131
  x
@@ -2,6 +2,49 @@ require "helper"
2
2
  require "jit_buffer"
3
3
 
4
4
  class JITBufferTest < Minitest::Test
5
+ def test_fill_buffer_with_putc
6
+ jit = JITBuffer.new 4096
7
+ str = [0xCC] * 4096
8
+ jit.writeable!
9
+ str.each { |c| jit.putc c }
10
+ assert_equal 4096, jit.pos
11
+ jit.seek 0
12
+
13
+ bytes = []
14
+ 4096.times { bytes << (jit.getc & 0xFF) }
15
+ assert_equal 4096, jit.pos
16
+ assert_equal str, bytes
17
+ end
18
+
19
+ def test_fill_buffer_read_with_getc
20
+ jit = JITBuffer.new 4096
21
+ str = ([0xCC] * 4096).pack("C*")
22
+ jit.writeable!
23
+ jit.write(str)
24
+ assert_equal 4096, jit.pos
25
+ jit.seek 0
26
+
27
+ bytes = []
28
+ 4096.times { bytes << jit.getc }
29
+ assert_equal 4096, jit.pos
30
+ assert_equal str, bytes.pack("C*")
31
+ end
32
+
33
+ def test_fill_buffer
34
+ jit = JITBuffer.new 4096
35
+ str = ([0xCC] * 4096).pack("C*")
36
+ jit.writeable!
37
+ jit.write(str)
38
+ assert_equal 4096, jit.pos
39
+ jit.seek 0
40
+ assert_equal str, jit.read(4096)
41
+ end
42
+
43
+ def test_size
44
+ jit = JITBuffer.new 4096
45
+ assert_equal 4096, jit.size
46
+ end
47
+
5
48
  def test_make_writeable
6
49
  jit = JITBuffer.new 4096
7
50
  jit.writeable!
@@ -60,7 +103,7 @@ class JITBufferTest < Minitest::Test
60
103
 
61
104
  jit.executable!
62
105
  func = Fiddle::Function.new(jit.to_i + 8, [], Fiddle::TYPE_INT)
63
- assert_equal 43, func.call
106
+ assert_equal 0x2b, func.call
64
107
  end
65
108
 
66
109
  def test_invalid_write
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jit_buffer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-04 00:00:00.000000000 Z
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -72,7 +72,7 @@ homepage: https://github.com/tenderlove/jit_buffer
72
72
  licenses:
73
73
  - Apache-2.0
74
74
  metadata: {}
75
- post_install_message:
75
+ post_install_message:
76
76
  rdoc_options: []
77
77
  require_paths:
78
78
  - lib
@@ -87,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 3.0.3.1
91
- signing_key:
90
+ rubygems_version: 3.4.0.dev
91
+ signing_key:
92
92
  specification_version: 4
93
93
  summary: A JIT Buffer object for Ruby.
94
94
  test_files: