mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-05-07 10:49:28 +00:00
guard allocSharedSeq if given seq is empty
This commit is contained in:
parent
7c03bfd9ac
commit
16e406bdea
@ -25,8 +25,11 @@ proc alloc*(str: string): cstring =
|
||||
|
||||
proc allocSharedSeq*[T](s: seq[T]): SharedSeq[T] =
|
||||
let data = allocShared(sizeof(T) * s.len)
|
||||
if s.len != 0:
|
||||
copyMem(data, unsafeAddr s[0], sizeof(T) * s.len)
|
||||
|
||||
if s.len == 0:
|
||||
return (cast[ptr UncheckedArray[T]](nil), 0)
|
||||
|
||||
copyMem(data, unsafeAddr s[0], sizeof(T) * s.len)
|
||||
return (cast[ptr UncheckedArray[T]](data), s.len)
|
||||
|
||||
proc deallocSharedSeq*[T](s: var SharedSeq[T]) =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user