Skip to content

Commit

Permalink
Fix pointer deref issue on Macos and Nim >= 2.0 (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko authored May 20, 2024
1 parent 3c238df commit 379901a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,6 @@ jobs:
env TEST_LANG="c" nimble test
# run test against intx
env TEST_LANG="cpp" nimble test
# test conditional compilation for arm654 arch
# test conditional compilation for arm64 arch
# without running the binary
nim c -c --cpu:arm64 --os:linux tests/all_tests
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

nimcache/
build/
nimble.paths
4 changes: 4 additions & 0 deletions config.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# begin Nimble config (version 1)
when fileExists("nimble.paths"):
include "nimble.paths"
# end Nimble config
8 changes: 6 additions & 2 deletions stint/private/primitives/addcarry_subborrow.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ const
useIntrinsics = X86 and not stintNoIntrinsics
useInt128 = GCC_Compatible and sizeof(int) == 8 and not stintNoIntrinsics

const
newerNim = (NimMajor, NimMinor) > (1, 6)
noExplicitPtrDeref = defined(cpp) or newerNim

when useIntrinsics:
when defined(windows):
{.pragma: intrinsics, header:"<intrin.h>", nodecl.}
Expand Down Expand Up @@ -152,7 +156,7 @@ func addC*(cOut: var Carry, sum: var uint64, a, b: uint64, cIn: Carry) {.inline.
{.emit:[dblPrec, " = (unsigned __int128)", a," + (unsigned __int128)", b, " + (unsigned __int128)",cIn,";"].}

# Don't forget to dereference the var param in C mode
when defined(cpp):
when noExplicitPtrDeref:
{.emit:[cOut, " = (NU64)(", dblPrec," >> ", 64'u64, ");"].}
{.emit:[sum, " = (NU64)", dblPrec,";"].}
else:
Expand All @@ -175,7 +179,7 @@ func subB*(bOut: var Borrow, diff: var uint64, a, b: uint64, bIn: Borrow) {.inli

# Don't forget to dereference the var param in C mode
# On borrow the high word will be 0b1111...1111 and needs to be masked
when defined(cpp):
when noExplicitPtrDeref:
{.emit:[bOut, " = (NU64)(", dblPrec," >> ", 64'u64, ") & 1;"].}
{.emit:[diff, " = (NU64)", dblPrec,";"].}
else:
Expand Down

0 comments on commit 379901a

Please sign in to comment.