bindata 2.4.3 → 2.4.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bindata might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd9ce2f3336fc2e9f8e3250a278732351d6a1af220603fb62763b3ef83caaf5e
4
- data.tar.gz: f8f15a3836564c6a51891231a276ed0848cc92bdb4663c5aca6d4eecd0f53ec4
3
+ metadata.gz: bc513e5824615b4b143e4a733bd6e8290bdfa831ab111267475a167f31125bb1
4
+ data.tar.gz: 93b4a5203a1d641dd1af806b769f92f8daf50644e9815d01fa2dbfec9f30bc8e
5
5
  SHA512:
6
- metadata.gz: 5abcc6829c6b6ea410bc3c542d4b60d40a83e6ac883bb3a4b09dfefdc1e5a4ae1d37307d75e53cbbc1593a17dd327269974835a6f0936f2ab21f66fe69f120ba
7
- data.tar.gz: ba8d7abcaac0ceb95acb6ffa8b24b7253495241fbd483ef887103a63d5c65c9649954a1998a70289e64823d0fb85bef1ba22a5bfb126b1cae9708a7412658220
6
+ metadata.gz: 88c701264083edfa92d193c33d394f7cb4bdc2f12722089ff27bb296bad28665f8e28a63158c98a8a45a189c68ce4792c027615ac0c9f1c61cacee1e02e817cc
7
+ data.tar.gz: dd1f06f1b17cbc005ca5399d86b62cfe420787d8a2f820d24f589f30dd58af99ed539eb5d5873f90b3877f986093a3bc5f176dcb7aaaeea176381809272b20ff
@@ -1,5 +1,11 @@
1
1
  = BinData Changelog
2
2
 
3
+ == Version 2.4.4 (2018-10-03)
4
+
5
+ * Display a hint when endian is omitted. Requested by Tails.
6
+ * Add thread safety to Integer/BitField creation. Requested by jbpeirce.
7
+ * Ensure windows sockets are unseekable. Thanks to Brent Cook.
8
+
3
9
  == Version 2.4.3 (2018-03-10)
4
10
 
5
11
  * Add Uint8Arrays. Requested by masarakki.
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Version ](http://img.shields.io/gem/v/bindata.svg) ](https://rubygems.org/gems/bindata)
4
4
  [![Travis CI ](http://img.shields.io/travis/dmendel/bindata/master.svg) ](https://travis-ci.org/dmendel/bindata)
5
- [![Quality ](http://img.shields.io/codeclimate/github/dmendel/bindata.svg)](https://codeclimate.com/github/dmendel/bindata)
6
5
  [![Coverage ](http://img.shields.io/coveralls/dmendel/bindata.svg) ](https://coveralls.io/r/dmendel/bindata)
7
6
 
8
7
  Do you ever find yourself writing code like this?
@@ -1,13 +1,5 @@
1
1
  # BinData -- Binary data manipulator.
2
- # Copyright (c) 2007 - 2016 Dion Mendel.
3
-
4
- if RUBY_VERSION <= "1.9"
5
- fail "BinData requires ruby >= 1.9.3. Use BinData version 1.8.x instead"
6
- end
7
-
8
- if RUBY_VERSION == "2.1.0" and RUBY_PATCHLEVEL == "0"
9
- fail "Ruby 2.1.0p0 has a bug that causes BinData to fail. Upgrade your ruby version"
10
- end
2
+ # Copyright (c) 2007 - 2018 Dion Mendel.
11
3
 
12
4
  require 'bindata/version'
13
5
  require 'bindata/array'
@@ -36,10 +28,10 @@ require 'bindata/warnings'
36
28
  # A declarative way to read and write structured binary data.
37
29
  #
38
30
  # A full reference manual is available online at
39
- # http://bindata.rubyforge.org/manual.html
31
+ # https://github.com/dmendel/bindata/wiki
40
32
  #
41
33
  # == License
42
34
  #
43
35
  # BinData is released under the same license as Ruby.
44
36
  #
45
- # Copyright (c) 2007 - 2016 Dion Mendel.
37
+ # Copyright (c) 2007 - 2018 Dion Mendel.
@@ -1,3 +1,4 @@
1
+ require 'thread'
1
2
  require 'bindata/base_primitive'
2
3
 
3
4
  module BinData
@@ -5,15 +6,18 @@ module BinData
5
6
  # The integer is defined by endian and number of bits.
6
7
 
7
8
  module BitField #:nodoc: all
9
+ @@mutex = Mutex.new
10
+
8
11
  class << self
9
12
  def define_class(name, nbits, endian, signed = :unsigned)
10
- unless BinData.const_defined?(name)
11
- BinData.module_eval <<-END
12
- class #{name} < BinData::BasePrimitive
13
- # nbits is either an integer or the symbol `:nbits`
14
- BitField.define_methods(self, #{nbits.inspect}, :#{endian}, :#{signed})
15
- end
16
- END
13
+ @@mutex.synchronize do
14
+ unless BinData.const_defined?(name)
15
+ new_class = Class.new(BinData::BasePrimitive)
16
+ BitField.define_methods(new_class, nbits, endian.to_sym, signed.to_sym)
17
+ RegisteredClasses.register(name, new_class)
18
+
19
+ BinData.const_set(name, new_class)
20
+ end
17
21
  end
18
22
 
19
23
  BinData.const_get(name)
@@ -1,3 +1,4 @@
1
+ require 'thread'
1
2
  require 'bindata/base_primitive'
2
3
 
3
4
  module BinData
@@ -5,14 +6,18 @@ module BinData
5
6
  # is defined by endian, signedness and number of bytes.
6
7
 
7
8
  module Int #:nodoc: all
9
+ @@mutex = Mutex.new
10
+
8
11
  class << self
9
12
  def define_class(name, nbits, endian, signed)
10
- unless BinData.const_defined?(name)
11
- BinData.module_eval <<-END
12
- class #{name} < BinData::BasePrimitive
13
- Int.define_methods(self, #{nbits}, :#{endian}, :#{signed})
14
- end
15
- END
13
+ @@mutex.synchronize do
14
+ unless BinData.const_defined?(name)
15
+ new_class = Class.new(BinData::BasePrimitive)
16
+ Int.define_methods(new_class, nbits, endian.to_sym, signed.to_sym)
17
+ RegisteredClasses.register(name, new_class)
18
+
19
+ BinData.const_set(name, new_class)
20
+ end
16
21
  end
17
22
 
18
23
  BinData.const_get(name)
@@ -29,7 +29,7 @@ module BinData
29
29
 
30
30
  def seekable?
31
31
  @raw_io.pos
32
- rescue NoMethodError, Errno::ESPIPE, Errno::EPIPE
32
+ rescue NoMethodError, Errno::ESPIPE, Errno::EPIPE, Errno::EINVAL
33
33
  nil
34
34
  end
35
35
 
@@ -24,7 +24,7 @@ module BinData
24
24
  end
25
25
 
26
26
  def register(name, class_to_register)
27
- return if class_to_register.nil?
27
+ return if name.nil? || class_to_register.nil?
28
28
 
29
29
  formatted_name = underscore_name(name)
30
30
  warn_if_name_is_already_registered(formatted_name, class_to_register)
@@ -37,8 +37,14 @@ module BinData
37
37
  end
38
38
 
39
39
  def lookup(name, hints = {})
40
- key = normalize_name(name, hints)
41
- @registry[key] || raise(UnRegisteredTypeError, name.to_s)
40
+ the_class = @registry[normalize_name(name, hints)]
41
+ if the_class
42
+ the_class
43
+ elsif @registry[normalize_name(name, hints.merge(endian: :big))]
44
+ raise(UnRegisteredTypeError, "#{name}, do you need to specify endian?")
45
+ else
46
+ raise(UnRegisteredTypeError, name)
47
+ end
42
48
  end
43
49
 
44
50
  # Convert CamelCase +name+ to underscore style.
@@ -1,3 +1,3 @@
1
1
  module BinData
2
- VERSION = "2.4.3"
2
+ VERSION = "2.4.4"
3
3
  end
@@ -71,6 +71,14 @@ describe BinData::Registry, "with numerics" do
71
71
  }.must_raise BinData::UnRegisteredTypeError
72
72
  end
73
73
 
74
+ it "provides a nice error message when endian is omitted" do
75
+ begin
76
+ r.lookup("int24")
77
+ rescue BinData::UnRegisteredTypeError => e
78
+ e.message.must_equal "int24, do you need to specify endian?"
79
+ end
80
+ end
81
+
74
82
  it "does not lookup non byte based integers" do
75
83
  lambda {
76
84
  r.lookup("int3")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bindata
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.3
4
+ version: 2.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dion Mendel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-09 00:00:00.000000000 Z
11
+ date: 2018-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
165
  version: '0'
166
166
  requirements: []
167
167
  rubyforge_project: bindata
168
- rubygems_version: 2.6.14
168
+ rubygems_version: 2.7.6
169
169
  signing_key:
170
170
  specification_version: 4
171
171
  summary: A declarative way to read and write binary file formats