Skip to content

Commit

Permalink
fix nim-lang#14873 properly by skipping abi field in importc type (n…
Browse files Browse the repository at this point in the history
…im-lang#17944)

* fix nim-lang#14873 properly by skipping `abi` field in importc type

* add test

* fix test for windows
  • Loading branch information
timotheecour authored and PMunch committed Mar 28, 2022
1 parent 94cd570 commit f43882b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
5 changes: 0 additions & 5 deletions lib/core/locks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 0 additions & 8 deletions lib/system/syslocks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,18 @@ else:
SysLockObj {.importc: "pthread_mutex_t", pure, final,
header: """#include <sys/types.h>
#include <pthread.h>""".} = object
when defined(linux) and defined(amd64):
abi: array[40 div sizeof(clong), clong]

SysLockAttr {.importc: "pthread_mutexattr_t", pure, final
header: """#include <sys/types.h>
#include <pthread.h>""".} = 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 <sys/types.h>
#include <pthread.h>""".} = object
when defined(linux) and defined(amd64):
abi: array[48 div sizeof(clonglong), clonglong]

SysCondAttr {.importc: "pthread_condattr_t", pure, final
header: """#include <sys/types.h>
#include <pthread.h>""".} = object
when defined(linux) and defined(amd64):
abi: array[4 div sizeof(cint), cint] # actually a cint

SysLockType = distinct cint

Expand Down
18 changes: 17 additions & 1 deletion tests/stdlib/uselocks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,21 @@ proc use* (m: var MyType): int =
result = 3

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
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()

0 comments on commit f43882b

Please sign in to comment.