From bec10d3259eec306bb336837dece7bc60173d547 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 5 May 2021 20:00:30 -0700 Subject: [PATCH 1/3] fix #14873 properly by skipping `abi` field in importc type --- lib/core/locks.nim | 5 ----- lib/system/syslocks.nim | 8 -------- tests/stdlib/uselocks.nim | 1 + 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/lib/core/locks.nim b/lib/core/locks.nim index 92967b9db6580..baec458292165 100644 --- a/lib/core/locks.nim +++ b/lib/core/locks.nim @@ -28,11 +28,6 @@ type {.push stackTrace: off.} - -proc `$`*(lock: Lock): string = - # workaround bug #14873 - result = "()" - proc initLock*(lock: var Lock) {.inline.} = ## Initializes the given lock. when not defined(js): diff --git a/lib/system/syslocks.nim b/lib/system/syslocks.nim index 2f0c8b0ba0b9d..9e8da610d1225 100644 --- a/lib/system/syslocks.nim +++ b/lib/system/syslocks.nim @@ -102,26 +102,18 @@ else: SysLockObj {.importc: "pthread_mutex_t", pure, final, header: """#include #include """.} = object - when defined(linux) and defined(amd64): - abi: array[40 div sizeof(clong), clong] SysLockAttr {.importc: "pthread_mutexattr_t", pure, final header: """#include #include """.} = object - when defined(linux) and defined(amd64): - abi: array[4 div sizeof(cint), cint] # actually a cint SysCondObj {.importc: "pthread_cond_t", pure, final, header: """#include #include """.} = object - when defined(linux) and defined(amd64): - abi: array[48 div sizeof(clonglong), clonglong] SysCondAttr {.importc: "pthread_condattr_t", pure, final header: """#include #include """.} = object - when defined(linux) and defined(amd64): - abi: array[4 div sizeof(cint), cint] # actually a cint SysLockType = distinct cint diff --git a/tests/stdlib/uselocks.nim b/tests/stdlib/uselocks.nim index e9d23f9d9ac27..325eb3b072fd9 100644 --- a/tests/stdlib/uselocks.nim +++ b/tests/stdlib/uselocks.nim @@ -11,5 +11,6 @@ proc use* (m: var MyType): int = result = 3 block: + # bug #14873 var l: Lock doAssert $l == "()" From dfc0fad3fdda4362a79a80e81aea7afe34cc9b19 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 5 May 2021 20:05:14 -0700 Subject: [PATCH 2/3] add test --- tests/stdlib/uselocks.nim | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/stdlib/uselocks.nim b/tests/stdlib/uselocks.nim index 325eb3b072fd9..8c41a194cf6e3 100644 --- a/tests/stdlib/uselocks.nim +++ b/tests/stdlib/uselocks.nim @@ -14,3 +14,16 @@ block: # bug #14873 var l: Lock doAssert $l == "()" + +when true: # intentional + # bug https://github.com/nim-lang/Nim/issues/14873#issuecomment-784241605 + type + Test = object + path: string # Removing this makes both cases work. + lock: Lock + # A: This is not fine. + var a = Test() + proc main(): void = + # B: This is fine. + var b = Test() + main() From 76782106f2c44529d83b52f383e3ee0500ee01a9 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Thu, 6 May 2021 00:40:26 -0700 Subject: [PATCH 3/3] fix test for windows --- tests/stdlib/uselocks.nim | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/stdlib/uselocks.nim b/tests/stdlib/uselocks.nim index 8c41a194cf6e3..e82de8adf99e8 100644 --- a/tests/stdlib/uselocks.nim +++ b/tests/stdlib/uselocks.nim @@ -13,7 +13,9 @@ proc use* (m: var MyType): int = block: # bug #14873 var l: Lock - doAssert $l == "()" + doAssert ($l).len > 0 + # on posix, "()", on windows, something else, but that shouldn't be part of the spec + # what matters is that `$` doesn't cause the codegen bug mentioned when true: # intentional # bug https://github.com/nim-lang/Nim/issues/14873#issuecomment-784241605