From db77aa566751fe67e3558e7268a511842339722b Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 8 Oct 2020 11:46:22 -0700 Subject: [PATCH 1/2] Added module `pointers` containing `toUncheckedArray` --- changelog.md | 3 +++ src/fusion/pointers.nim | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 changelog.md create mode 100644 src/fusion/pointers.nim diff --git a/changelog.md b/changelog.md new file mode 100644 index 00000000..5c2e7664 --- /dev/null +++ b/changelog.md @@ -0,0 +1,3 @@ +## additions and changes + +- Added module `pointers` containing `toUncheckedArray` diff --git a/src/fusion/pointers.nim b/src/fusion/pointers.nim new file mode 100644 index 00000000..4c92f74b --- /dev/null +++ b/src/fusion/pointers.nim @@ -0,0 +1,17 @@ +##[ +Convenience procs to deal with pointer-like variables. +]## + +proc toUncheckedArray*[T](a: ptr T): ptr UncheckedArray[T] {.inline.} = + ## Shortcut for `cast[ptr UncheckedArray[T]](a)`, where T is inferred. + ## This allows array indexing operations on `a`. + ## This is unsafe as it returns `UncheckedArray`. + runnableExamples: + var a = @[10, 11, 12] + let pa = a[1].addr.toUncheckedArray + doAssert pa[-1] == 10 + pa[0] = 100 + doAssert a == @[10, 100, 12] + pa[0] += 5 + doAssert a[1] == 105 + cast[ptr UncheckedArray[T]](a) From afc19b15cade5fd8219fc12f3e9378a609fafbc3 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 8 Oct 2020 11:48:40 -0700 Subject: [PATCH 2/2] add .gitattributes to avoid changelog conflicts --- .gitattributes | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..674da793 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# Avoids changelog conflicts by assuming additions-only, which is by far the common case. +# In the rare case where branch b1 rebases against branch b2 and both branches +# modified the same changelog entry, you'll end up with that changelog entry +# duplicated, which is easily identifiable and fixable. +/changelog.md merge=union +