From 4aaaa3379a1407e7e8232f5fb0a8d7886b26f3e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C8=98tefan=20Talpalaru?= Date: Sat, 20 Nov 2021 01:30:23 +0100 Subject: [PATCH] Nim-1.6 fixes (#239) --- chronos/asyncloop.nim | 4 ++-- chronos/asyncsync.nim | 8 ++++++-- chronos/transports/stream.nim | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/chronos/asyncloop.nim b/chronos/asyncloop.nim index 03d1c96..44d1cff 100644 --- a/chronos/asyncloop.nim +++ b/chronos/asyncloop.nim @@ -323,7 +323,7 @@ when defined(windows) or defined(nimdoc): AsyncFD* = distinct int proc hash(x: AsyncFD): Hash {.borrow.} - proc `==`*(x: AsyncFD, y: AsyncFD): bool {.borrow.} + proc `==`*(x: AsyncFD, y: AsyncFD): bool {.borrow, gcsafe.} proc getFunc(s: SocketHandle, fun: var pointer, guid: var GUID): bool = var bytesRet: DWORD @@ -516,7 +516,7 @@ elif unixPlatform: selector: Selector[SelectorData] keys: seq[ReadyKey] - proc `==`*(x, y: AsyncFD): bool {.borrow.} + proc `==`*(x, y: AsyncFD): bool {.borrow, gcsafe.} proc globalInit() = # We are ignoring SIGPIPE signal, because we are working with EPIPE. diff --git a/chronos/asyncsync.nim b/chronos/asyncsync.nim index eed5f4e..007c44a 100644 --- a/chronos/asyncsync.nim +++ b/chronos/asyncsync.nim @@ -571,8 +571,10 @@ proc emit[T](bus: AsyncEventBus, event: string, data: T, loc: ptr SrcLoc) = # Schedule subscriber's callbacks, which are subscribed to the event. for subscriber in item.subscribers: + # Nim-1.6 says: "'subscriber' is of type which cannot be captured as it would violate memory safety" + let subscriber_copy = subscriber callSoon(proc(udata: pointer) = - subscriber.cb(bus, event, subscriber, payload) + subscriber_copy.cb(bus, event, subscriber_copy, payload) ) # Schedule waiters which are waiting all events @@ -583,8 +585,10 @@ proc emit[T](bus: AsyncEventBus, event: string, data: T, loc: ptr SrcLoc) = # Schedule subscriber's callbacks which are subscribed to all events. for subscriber in bus.subscribers: + # Nim-1.6 says: "'subscriber' is of type which cannot be captured as it would violate memory safety" + let subscriber_copy = subscriber callSoon(proc(udata: pointer) = - subscriber.cb(bus, event, subscriber, payload) + subscriber_copy.cb(bus, event, subscriber_copy, payload) ) template emit*[T](bus: AsyncEventBus, event: string, data: T) = diff --git a/chronos/transports/stream.nim b/chronos/transports/stream.nim index 7e7793e..7b8520f 100644 --- a/chronos/transports/stream.nim +++ b/chronos/transports/stream.nim @@ -1642,7 +1642,7 @@ else: break return retFuture - proc acceptLoop(udata: pointer) = + proc acceptLoop(udata: pointer) {.gcsafe.} = var saddr: Sockaddr_storage slen: SockLen