Fix pointer deref issue on Macos and Nim >= 2.0 (#152)

This commit is contained in:
andri lim 2024-05-20 23:39:33 +07:00 committed by GitHub
parent 3c238df6cd
commit 379901ad36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 3 deletions

View File

@ -168,6 +168,6 @@ jobs:
env TEST_LANG="c" nimble test env TEST_LANG="c" nimble test
# run test against intx # run test against intx
env TEST_LANG="cpp" nimble test env TEST_LANG="cpp" nimble test
# test conditional compilation for arm654 arch # test conditional compilation for arm64 arch
# without running the binary # without running the binary
nim c -c --cpu:arm64 --os:linux tests/all_tests nim c -c --cpu:arm64 --os:linux tests/all_tests

1
.gitignore vendored
View File

@ -6,3 +6,4 @@
nimcache/ nimcache/
build/ build/
nimble.paths

4
config.nims Normal file
View File

@ -0,0 +1,4 @@
# begin Nimble config (version 1)
when fileExists("nimble.paths"):
include "nimble.paths"
# end Nimble config

View File

@ -88,6 +88,10 @@ const
useIntrinsics = X86 and not stintNoIntrinsics useIntrinsics = X86 and not stintNoIntrinsics
useInt128 = GCC_Compatible and sizeof(int) == 8 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 useIntrinsics:
when defined(windows): when defined(windows):
{.pragma: intrinsics, header:"<intrin.h>", nodecl.} {.pragma: intrinsics, header:"<intrin.h>", nodecl.}
@ -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,";"].} {.emit:[dblPrec, " = (unsigned __int128)", a," + (unsigned __int128)", b, " + (unsigned __int128)",cIn,";"].}
# Don't forget to dereference the var param in C mode # Don't forget to dereference the var param in C mode
when defined(cpp): when noExplicitPtrDeref:
{.emit:[cOut, " = (NU64)(", dblPrec," >> ", 64'u64, ");"].} {.emit:[cOut, " = (NU64)(", dblPrec," >> ", 64'u64, ");"].}
{.emit:[sum, " = (NU64)", dblPrec,";"].} {.emit:[sum, " = (NU64)", dblPrec,";"].}
else: else:
@ -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 # 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 # 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:[bOut, " = (NU64)(", dblPrec," >> ", 64'u64, ") & 1;"].}
{.emit:[diff, " = (NU64)", dblPrec,";"].} {.emit:[diff, " = (NU64)", dblPrec,";"].}
else: else: