ionspin / kotlin-multiplatform-bignum

A Kotlin multiplatform library for arbitrary precision arithmetics
Apache License 2.0
350 stars 41 forks source link

IncorrectDereferenceException while using `BigInteger.fromByteArray` in multiplatform native code #159

Closed william-reed closed 3 years ago

william-reed commented 3 years ago

When using BigInteger.fromByteArray from native multiplatform code (iOS specifically) I came upon the error IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread. The stack trace ultimately points to

internal val chosenArithmetic: BigIntegerArithmetic =
    BigInteger63Arithmetic

in Configuration.kt

It may be as simple as adding the @SharedImmutable annotation to that top level value (at a quick glance it does look like BigInteger63Arithmetic is immutable). I haven't been able to try that out yet though.

ionspin commented 3 years ago

Thanks for reporting the issue, and I think you're right, annotation might be good enough, I'll try it out.

ionspin commented 3 years ago

Fixed by #160 Should be available in 0.2.9-SNAPSHOT once the build finishes.