Files
Nim/tests/stdlib/tlocks.nim
ringabout 9595e17ba5 fixes #25205 #14873; resets importc obj with nimZeroMem in specializeResetT for refc (#25207)
fixes #25205
fixes #14873

```nim
  type
    SysLockObj {.importc: "pthread_mutex_t", pure, final,
               header: """#include <sys/types.h>
                          #include <pthread.h>""", byref.} = object
      when defined(linux) and defined(amd64):
        abi: array[40 div sizeof(clong), clong]
```

Before this PR, in refc, `resetLoc` generates field assignments for each
fields of `importc` object. But the field `abi` is not a genuine field,
which doesn't exits in the struct. We could use `zeroMem` to reset the
memory if not leave it alone

(cherry picked from commit 02609f1872)
2025-10-08 08:33:16 +02:00

39 lines
500 B
Nim

discard """
targets: "c cpp js"
matrix: "--mm:refc; --mm:orc"
"""
#bug #6049
import uselocks
import std/assertions
var m = createMyType[int]()
doAssert m.use() == 3
import std/locks
type
S = object
r: proc()
B = object
d: Lock
w: S
proc v(x: ptr B) {.exportc.} = reset(x[])
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()