gogyou 0.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/gogyou.rb +1 -1
 - data/lib/gogyou/accessor.rb +20 -13
 - data/lib/gogyou/mixin.rb +1 -2
 - data/spec/gogyou_spec.rb +10 -4
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c1f4c10b0e249b1b9897b5b1c317e0ef5e535830
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: c8ccad916b49f45e18d91bff8538cf1b7e5b6377
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b73dba83766abfce2f63ba2daad894fdf3b7560ed20bfa613d9d388aa707f053dac67f8133f6fe76002eb0958824d8b6cec23fc1a05b58228244d1ab0cfdb503
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 93b5fb1d45270650ff47c10746ec94ddf0b44c59751b8f035af841902a0fc807f02e2c39820447ca9d055aeafa1abc4ee1ab78a9e2f72383e5d7db0a7e325fd1
         
     | 
    
        data/lib/gogyou.rb
    CHANGED
    
    
    
        data/lib/gogyou/accessor.rb
    CHANGED
    
    | 
         @@ -148,6 +148,9 @@ module Gogyou 
     | 
|
| 
       148 
148 
     | 
    
         
             
                def self.define_accessors(accessorclass, model)
         
     | 
| 
       149 
149 
     | 
    
         
             
                  accessorclass.class_eval do
         
     | 
| 
       150 
150 
     | 
    
         
             
                    namecheck = {}
         
     | 
| 
      
 151 
     | 
    
         
            +
                    fieldsize = model.fields.size
         
     | 
| 
      
 152 
     | 
    
         
            +
                    define_method(:size__GOGYOU__, -> { fieldsize })
         
     | 
| 
      
 153 
     | 
    
         
            +
                    alias_method(:size, :size__GOGYOU__)
         
     | 
| 
       151 
154 
     | 
    
         
             
                    model.fields.each do |field|
         
     | 
| 
       152 
155 
     | 
    
         
             
                      name = field.name
         
     | 
| 
       153 
156 
     | 
    
         
             
                      #raise NameError, "wrong field name - #{name}" unless name =~ /\A[A-Za-z_][A-Za-z_0-9]*\Z/
         
     | 
| 
         @@ -267,13 +270,13 @@ module Gogyou 
     | 
|
| 
       267 
270 
     | 
    
         
             
                      bytesize = type.bytesize
         
     | 
| 
       268 
271 
     | 
    
         | 
| 
       269 
272 
     | 
    
         
             
                      if model.bytesize == 0
         
     | 
| 
       270 
     | 
    
         
            -
                        check_index  
     | 
| 
      
 273 
     | 
    
         
            +
                        define_method(:check_index, ->(index) {
         
     | 
| 
       271 
274 
     | 
    
         
             
                          index = index.to_i
         
     | 
| 
       272 
275 
     | 
    
         
             
                          unless index >= 0 && index < self.size
         
     | 
| 
       273 
276 
     | 
    
         
             
                            raise IndexError, "out of element size (index #{index} for 0 ... #{self.size})", caller(2)
         
     | 
| 
       274 
277 
     | 
    
         
             
                          end
         
     | 
| 
       275 
278 
     | 
    
         
             
                          index
         
     | 
| 
       276 
     | 
    
         
            -
                         
     | 
| 
      
 279 
     | 
    
         
            +
                        })
         
     | 
| 
       277 
280 
     | 
    
         | 
| 
       278 
281 
     | 
    
         
             
                        define_method(:<<, ->(value) {
         
     | 
| 
       279 
282 
     | 
    
         
             
                          raise TypeError, "immutable object (#<%s:0x%08X>)" % [self.class, __id__], caller(2) if frozen?
         
     | 
| 
         @@ -292,27 +295,31 @@ module Gogyou 
     | 
|
| 
       292 
295 
     | 
    
         
             
                          (buffer__GOGYOU__.bytesize - offset__GOGYOU__).align_floor(type.bytesize)
         
     | 
| 
       293 
296 
     | 
    
         
             
                        })
         
     | 
| 
       294 
297 
     | 
    
         
             
                      else
         
     | 
| 
       295 
     | 
    
         
            -
                         
     | 
| 
       296 
     | 
    
         
            -
                           
     | 
| 
       297 
     | 
    
         
            -
             
     | 
| 
       298 
     | 
    
         
            -
                             
     | 
| 
      
 298 
     | 
    
         
            +
                        eval <<-EOS
         
     | 
| 
      
 299 
     | 
    
         
            +
                          def check_index(index)
         
     | 
| 
      
 300 
     | 
    
         
            +
                            index = index.to_i
         
     | 
| 
      
 301 
     | 
    
         
            +
                            unless index >= 0 && (#{elements.nil?} || index < #{elements})
         
     | 
| 
      
 302 
     | 
    
         
            +
                              raise IndexError, "out of element size (index \#{index} for 0 ... #{elements})", caller
         
     | 
| 
      
 303 
     | 
    
         
            +
                            end
         
     | 
| 
      
 304 
     | 
    
         
            +
                            index
         
     | 
| 
       299 
305 
     | 
    
         
             
                          end
         
     | 
| 
       300 
     | 
    
         
            -
                          index
         
     | 
| 
       301 
     | 
    
         
            -
                        end
         
     | 
| 
       302 
306 
     | 
    
         | 
| 
       303 
     | 
    
         
            -
             
     | 
| 
       304 
     | 
    
         
            -
                          def bytesize
         
     | 
| 
      
 307 
     | 
    
         
            +
                          def size
         
     | 
| 
       305 
308 
     | 
    
         
             
                            #{elements}
         
     | 
| 
       306 
309 
     | 
    
         
             
                          end
         
     | 
| 
      
 310 
     | 
    
         
            +
             
     | 
| 
      
 311 
     | 
    
         
            +
                          def bytesize
         
     | 
| 
      
 312 
     | 
    
         
            +
                            #{type.bytesize * elements}
         
     | 
| 
      
 313 
     | 
    
         
            +
                          end
         
     | 
| 
       307 
314 
     | 
    
         
             
                        EOS
         
     | 
| 
       308 
315 
     | 
    
         
             
                      end
         
     | 
| 
       309 
316 
     | 
    
         | 
| 
       310 
317 
     | 
    
         
             
                      define_method(:to_s, -> {
         
     | 
| 
       311 
     | 
    
         
            -
                        buffer__GOGYOU__.byteslice(offset__GOGYOU__, bytesize)
         
     | 
| 
      
 318 
     | 
    
         
            +
                        buffer__GOGYOU__.byteslice(offset__GOGYOU__, self.bytesize)
         
     | 
| 
       312 
319 
     | 
    
         
             
                      })
         
     | 
| 
       313 
320 
     | 
    
         | 
| 
       314 
321 
     | 
    
         
             
                      define_method(:[], ->(index) {
         
     | 
| 
       315 
     | 
    
         
            -
                        v = type.aref(buffer__GOGYOU__, offset__GOGYOU__ + check_index 
     | 
| 
      
 322 
     | 
    
         
            +
                        v = type.aref(buffer__GOGYOU__, offset__GOGYOU__ + check_index(index) * bytesize)
         
     | 
| 
       316 
323 
     | 
    
         
             
                        v.infect_from(self, buffer) unless v.frozen?
         
     | 
| 
       317 
324 
     | 
    
         
             
                        v.freeze if frozen? || buffer.frozen? || field.const?
         
     | 
| 
       318 
325 
     | 
    
         
             
                        v
         
     | 
| 
         @@ -320,7 +327,7 @@ module Gogyou 
     | 
|
| 
       320 
327 
     | 
    
         | 
| 
       321 
328 
     | 
    
         
             
                      define_method(:[]=, ->(index, value) {
         
     | 
| 
       322 
329 
     | 
    
         
             
                        raise TypeError, "immutable object (#<%s:0x%08X>)" % [self.class, __id__, index], caller(2) if frozen? or field.const?
         
     | 
| 
       323 
     | 
    
         
            -
                        type.aset(buffer__GOGYOU__, offset__GOGYOU__ + check_index 
     | 
| 
      
 330 
     | 
    
         
            +
                        type.aset(buffer__GOGYOU__, offset__GOGYOU__ + check_index(index) * bytesize, value)
         
     | 
| 
       324 
331 
     | 
    
         
             
                      })
         
     | 
| 
       325 
332 
     | 
    
         
             
                    end
         
     | 
| 
       326 
333 
     | 
    
         
             
                    klass
         
     | 
    
        data/lib/gogyou/mixin.rb
    CHANGED
    
    | 
         @@ -7,7 +7,7 @@ module Gogyou 
     | 
|
| 
       7 
7 
     | 
    
         
             
                module Object
         
     | 
| 
       8 
8 
     | 
    
         
             
                  module Mixin
         
     | 
| 
       9 
9 
     | 
    
         
             
                    def infect_from(*obj)
         
     | 
| 
       10 
     | 
    
         
            -
                      obj.each { |o| taint if o.tainted 
     | 
| 
      
 10 
     | 
    
         
            +
                      obj.each { |o| taint if o.tainted? }
         
     | 
| 
       11 
11 
     | 
    
         
             
                      self
         
     | 
| 
       12 
12 
     | 
    
         
             
                    end
         
     | 
| 
       13 
13 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -136,7 +136,6 @@ module Gogyou 
     | 
|
| 
       136 
136 
     | 
    
         | 
| 
       137 
137 
     | 
    
         
             
                    def swapbyte(bytesize)
         
     | 
| 
       138 
138 
     | 
    
         
             
                      num = 0
         
     | 
| 
       139 
     | 
    
         
            -
                      mask = 0xff
         
     | 
| 
       140 
139 
     | 
    
         
             
                      bytesize.times do |i|
         
     | 
| 
       141 
140 
     | 
    
         
             
                        num <<= 8
         
     | 
| 
       142 
141 
     | 
    
         
             
                        num |= (self >> (i * 8)) & 0xff
         
     | 
    
        data/spec/gogyou_spec.rb
    CHANGED
    
    | 
         @@ -117,15 +117,21 @@ end 
     | 
|
| 
       117 
117 
     | 
    
         
             
            describe Gogyou::Accessor do
         
     | 
| 
       118 
118 
     | 
    
         
             
              it "fixed bytesize struct" do
         
     | 
| 
       119 
119 
     | 
    
         
             
                type = Gogyou.struct {
         
     | 
| 
       120 
     | 
    
         
            -
                   
     | 
| 
      
 120 
     | 
    
         
            +
                  char :a, 16
         
     | 
| 
      
 121 
     | 
    
         
            +
                  int32_t :b
         
     | 
| 
      
 122 
     | 
    
         
            +
                  int8_t :c
         
     | 
| 
       121 
123 
     | 
    
         
             
                }
         
     | 
| 
       122 
124 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
                expect(type.bytesize).to eq  
     | 
| 
      
 125 
     | 
    
         
            +
                expect(type.bytesize).to eq 24
         
     | 
| 
       124 
126 
     | 
    
         
             
                expect(type.bytealign).to eq 4
         
     | 
| 
       125 
127 
     | 
    
         
             
                expect(type.extensible?).to eq false
         
     | 
| 
       126 
128 
     | 
    
         | 
| 
       127 
     | 
    
         
            -
                obj = type. 
     | 
| 
       128 
     | 
    
         
            -
                expect(obj.bytesize).to eq  
     | 
| 
      
 129 
     | 
    
         
            +
                obj = type.bind((?a .. ?z).to_a.join)
         
     | 
| 
      
 130 
     | 
    
         
            +
                expect(obj.bytesize).to eq 24
         
     | 
| 
      
 131 
     | 
    
         
            +
                expect(obj.size).to eq 3
         
     | 
| 
      
 132 
     | 
    
         
            +
                expect(obj.a.bytesize).to eq 16
         
     | 
| 
      
 133 
     | 
    
         
            +
                expect(obj.a[1]).to eq ?b.ord
         
     | 
| 
      
 134 
     | 
    
         
            +
                expect(obj.a.to_s).to eq "abcdefghijklmnop"
         
     | 
| 
       129 
135 
     | 
    
         
             
              end
         
     | 
| 
       130 
136 
     | 
    
         | 
| 
       131 
137 
     | 
    
         
             
              it "extensibity struct" do
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: gogyou
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version:  
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - dearblue
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2014-09- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2014-09-11 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: rspec
         
     | 
| 
         @@ -57,8 +57,8 @@ extra_rdoc_files: 
     | 
|
| 
       57 
57 
     | 
    
         
             
            - lib/gogyou/accessor.rb
         
     | 
| 
       58 
58 
     | 
    
         
             
            - lib/gogyou/mixin.rb
         
     | 
| 
       59 
59 
     | 
    
         
             
            - lib/gogyou/model.rb
         
     | 
| 
       60 
     | 
    
         
            -
            - lib/gogyou/typespec.rb
         
     | 
| 
       61 
60 
     | 
    
         
             
            - lib/gogyou/primitives.rb
         
     | 
| 
      
 61 
     | 
    
         
            +
            - lib/gogyou/typespec.rb
         
     | 
| 
       62 
62 
     | 
    
         
             
            files:
         
     | 
| 
       63 
63 
     | 
    
         
             
            - LICENSE.markdown
         
     | 
| 
       64 
64 
     | 
    
         
             
            - README.markdown
         
     |