Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute read/write fails for offset views in java implementation #3

Open
sh54 opened this issue May 31, 2021 · 1 comment
Open

Absolute read/write fails for offset views in java implementation #3

sh54 opened this issue May 31, 2021 · 1 comment

Comments

@sh54
Copy link
Contributor

sh54 commented May 31, 2021

The following:

(let [view (-> (binf.buffer/alloc 64)
               (binf/view 32 16)
               (binf/endian-set :little-endian))]
  (binf/wa-b8 view 0 42)
  (t/is (= 42 (binf/ra-u8 view 0))))

Works in clojurescript but fails in clojure with the exception:

Unhandled java.lang.IndexOutOfBoundsException 32

       HeapByteBuffer.java:  171  java.nio.HeapByteBuffer/get
                  impl.clj:   89  helins.binf.protocol.impl/eval17986/fn
             protocol.cljc:   24  helins.binf.protocol$eval11976$fn__12035$G__11961__12042/invoke
                 binf.cljc:   69  helins.binf$ra_u8/invokeStatic
                 binf.cljc:   63  helins.binf$ra_u8/invoke
                      REPL:   66  helins.binf.test/eval18113

Fix:

(extend-type ByteBuffer
  binf.protocol/-IByteBuffer
  (-array-index [this position]
    position))

This is the same the existing implementation for DirectByteBuffer.

@helins
Copy link
Owner

helins commented Jun 3, 2021

Latest commit on main has fixed this (not yet released) if you fancy giving it a go.

I rewrote the tests using test.check so hopefully there won't be anymore edge cases. But I'll wait a bit before cutting a release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants