From 05c8e1d85da4aec8042c8d613e2744feeda2ae5b Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 5 Dec 2025 07:46:47 +0800 Subject: [PATCH] fixes #25324; Channel incorrectly takes a sink argument in refc (#25328) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … it performs a deep copy internally fixes #25324 notes that > Enabling `-d:nimPreviewSlimSystem` removes the import of `channels_builtin` in in the `system` module, which is replaced by [threading/channels](https://github.com/nim-lang/threading/blob/master/threading/channels.nim). (cherry picked from commit 5d4829415a575b02cd2c56fee841ec111496cb50) --- lib/system/channels_builtin.nim | 38 ++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/system/channels_builtin.nim b/lib/system/channels_builtin.nim index 799546a16d..1cc9443778 100644 --- a/lib/system/channels_builtin.nim +++ b/lib/system/channels_builtin.nim @@ -367,23 +367,35 @@ proc sendImpl(q: PRawChannel, typ: PNimType, msg: pointer, noBlock: bool): bool releaseSys(q.lock) result = true -proc send*[TMsg](c: var Channel[TMsg], msg: sink TMsg) {.inline.} = - ## Sends a message to a thread. `msg` is deeply copied. - discard sendImpl(cast[PRawChannel](addr c), cast[PNimType](getTypeInfo(msg)), unsafeAddr(msg), false) - when defined(gcDestructors): +when defined(gcDestructors): + proc send*[TMsg](c: var Channel[TMsg], msg: sink TMsg) {.inline.} = + ## Sends a message to a thread. + discard sendImpl(cast[PRawChannel](addr c), cast[PNimType](getTypeInfo(msg)), unsafeAddr(msg), false) wasMoved(msg) -proc trySend*[TMsg](c: var Channel[TMsg], msg: sink TMsg): bool {.inline.} = - ## Tries to send a message to a thread. - ## - ## `msg` is deeply copied. Doesn't block. - ## - ## Returns `false` if the message was not sent because number of pending items - ## in the channel exceeded `maxItems`. - result = sendImpl(cast[PRawChannel](addr c), cast[PNimType](getTypeInfo(msg)), unsafeAddr(msg), true) - when defined(gcDestructors): + proc trySend*[TMsg](c: var Channel[TMsg], msg: sink TMsg): bool {.inline.} = + ## Tries to send a message to a thread. + ## + ## Doesn't block. + ## + ## Returns `false` if the message was not sent because number of pending items + ## in the channel exceeded `maxItems`. + result = sendImpl(cast[PRawChannel](addr c), cast[PNimType](getTypeInfo(msg)), unsafeAddr(msg), true) if result: wasMoved(msg) +else: + proc send*[TMsg](c: var Channel[TMsg], msg: TMsg) {.inline.} = + ## Sends a message to a thread. `msg` is deeply copied. + discard sendImpl(cast[PRawChannel](addr c), cast[PNimType](getTypeInfo(msg)), unsafeAddr(msg), false) + + proc trySend*[TMsg](c: var Channel[TMsg], msg: TMsg): bool {.inline.} = + ## Tries to send a message to a thread. + ## + ## `msg` is deeply copied. Doesn't block. + ## + ## Returns `false` if the message was not sent because number of pending items + ## in the channel exceeded `maxItems`. + result = sendImpl(cast[PRawChannel](addr c), cast[PNimType](getTypeInfo(msg)), unsafeAddr(msg), true) proc llRecv(q: PRawChannel, res: pointer, typ: PNimType) = q.ready = true