Skip to content

Commit 3b3ce57

Browse files
committed
fix: nph linting
1 parent e7c2be6 commit 3b3ce57

10 files changed

Lines changed: 40 additions & 43 deletions

File tree

ffi/cbor_serial.nim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export cbor_serialization, options, results
3535
const CborNullByte*: byte = 0xf6'u8
3636
## CBOR encoding of `null` — used as the wire sentinel for empty OK payloads.
3737

38-
3938
proc cborEncode*[T](x: T): seq[byte] =
4039
## CBOR-encode any cbor_serialization-supported type (plus `pointer` / `ptr T`
4140
## via our custom writers) into a fresh `seq[byte]`.

ffi/codegen/rust.nim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ proc reqStructName(p: FFIProcMeta): string =
6363
else:
6464
camel & "Req"
6565

66-
6766
proc generateCargoToml*(libName: string): string =
6867
# `flume` is the unified callback channel (PR #23 Rust review, item 8): one
6968
# primitive that supports both `recv_timeout` (blocking trampoline) and

ffi/event_thread.nim

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ proc emitLivenessEvent[T, P](ctx: ptr FFIContext[T], name: string, payload: P) =
4747
chronicles.error "liveness event encode failed", name = name, err = exc.msg
4848
return
4949
let dataPtr: pointer =
50-
if event.len > 0: cast[pointer](unsafeAddr event[0])
51-
else: cast[pointer](emptyListenerPayload)
50+
if event.len > 0:
51+
cast[pointer](unsafeAddr event[0])
52+
else:
53+
cast[pointer](emptyListenerPayload)
5254
ctx.dispatchToListeners(name, dataPtr, event.len)
5355

5456
proc onNotResponding*(ctx: ptr FFIContext) =
@@ -105,8 +107,7 @@ proc check[T](hb: var HeartbeatMonitor, ctx: ptr FFIContext[T]) =
105107
hb.lastValue = cur
106108
hb.lastChange = Moment.now()
107109
hb.notifiedStale = false
108-
elif not hb.notifiedStale and
109-
Moment.now() - hb.lastChange > FFIHeartbeatStaleThreshold:
110+
elif not hb.notifiedStale and Moment.now() - hb.lastChange > FFIHeartbeatStaleThreshold:
110111
onNotResponding(ctx)
111112
hb.notifiedStale = true
112113

ffi/ffi_context.nim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@ type FFIContext*[T] = object
3232
reqReceivedSignal: ThreadSignalPtr
3333
# to signal main thread, interfacing with the FFI thread, that FFI thread received the request
3434
stopSignal: ThreadSignalPtr
35-
threadExitSignal: ThreadSignalPtr # bounds destroyFFIContext's wait so a blocked loop cannot hang the caller
36-
eventQueueSignal: ThreadSignalPtr # wakes the event thread on enqueue (used once dispatch is rewired in PR #69)
35+
threadExitSignal: ThreadSignalPtr
36+
# bounds destroyFFIContext's wait so a blocked loop cannot hang the caller
37+
eventQueueSignal: ThreadSignalPtr
38+
# wakes the event thread on enqueue (used once dispatch is rewired in PR #69)
3739
eventThreadExitSignal: ThreadSignalPtr # mirrors threadExitSignal for the event thread
3840
userData*: pointer
3941
eventRegistry*: FFIEventRegistry
4042
eventQueue*: EventQueue
41-
ffiHeartbeat*: Atomic[int64] # advanced each FFI-thread loop; event thread reads for liveness
43+
ffiHeartbeat*: Atomic[int64]
44+
# advanced each FFI-thread loop; event thread reads for liveness
4245
running: Atomic[bool] # To control when the threads are running
4346
registeredRequests: ptr Table[cstring, FFIRequestProc]
4447
# Pointer to with the registered requests at compile time

ffi/ffi_events.nim

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ import std/[locks, sequtils, options, tables]
1010
import chronicles
1111
import ./ffi_types, ./cbor_serial
1212

13-
1413
type EventEnvelope*[T] = object
1514
## Standard wire shape for CBOR-encoded FFI events:
1615
## { eventType: tstr, payload: <T> }
1716
## Pair with `dispatchFFIEventCbor` (or call `cborEncode` directly).
1817
eventType*: string
1918
payload*: T
2019

21-
2220
type
2321
FFIEventListener* = object
2422
id*: uint64
@@ -33,7 +31,6 @@ type
3331
nextId*: uint64 ## Monotonic id source. 0 is reserved as "invalid"; ids start at 1.
3432
byEvent*: Table[string, seq[FFIEventListener]]
3533

36-
3734
proc initEventRegistry*(reg: var FFIEventRegistry) =
3835
## Must be called exactly once on the owning thread before the registry
3936
## is shared. The embedded `Lock` wraps a platform primitive that cannot
@@ -129,7 +126,6 @@ proc snapshotListeners*(
129126
listeners.add(l)
130127
listeners
131128

132-
133129
const EventQueueCapacity* = 1024
134130
## ~24 KiB per context. Sustained backlog at this depth means a
135131
## listener is wedged — what the stuck flag exists to surface.
@@ -202,7 +198,6 @@ proc eventQueueLen*(q: var EventQueue): int {.raises: [], gcsafe.} =
202198
withLock q.lock:
203199
return q.count
204200

205-
206201
const emptyListenerPayload*: cstring = ""
207202
## Non-nil zero-length buffer handed to listeners when a payload is
208203
## empty, so a consumer doing `std::string(data, len)` / `memcpy` never
@@ -216,17 +211,21 @@ proc notifyListeners*(
216211
## consumer doing `std::string(data, len)` / `memcpy` never receives nil.
217212
let n = max(dataLen, 0)
218213
let dataPtr =
219-
if n > 0 and not data.isNil(): cast[ptr cchar](data)
220-
else: cast[ptr cchar](emptyListenerPayload)
214+
if n > 0 and not data.isNil():
215+
cast[ptr cchar](data)
216+
else:
217+
cast[ptr cchar](emptyListenerPayload)
221218
for listener in listeners:
222219
listener.callback(retCode, dataPtr, cast[csize_t](n), listener.userData)
223220

224221
proc notifyListenersErr*(listeners: seq[FFIEventListener], msg: string) =
225222
## Error fan-out: adapts the message string to `notifyListeners`, which
226223
## supplies the non-nil pointer for the empty-message case.
227224
let p =
228-
if msg.len > 0: cast[pointer](unsafeAddr msg[0])
229-
else: cast[pointer](emptyListenerPayload)
225+
if msg.len > 0:
226+
cast[pointer](unsafeAddr msg[0])
227+
else:
228+
cast[pointer](emptyListenerPayload)
230229
notifyListeners(listeners, RET_ERR, p, msg.len)
231230

232231
var ffiCurrentEventRegistry* {.threadvar.}: ptr FFIEventRegistry
@@ -269,8 +268,10 @@ template dispatchFFIEvent*(eventName: string, body: untyped) =
269268
withFFIEventDispatch(eventName, listeners):
270269
let event = body
271270
let dataPtr: pointer =
272-
if event.len > 0: cast[pointer](unsafeAddr event[0])
273-
else: cast[pointer](emptyListenerPayload)
271+
if event.len > 0:
272+
cast[pointer](unsafeAddr event[0])
273+
else:
274+
cast[pointer](emptyListenerPayload)
274275
notifyListeners(listeners, RET_OK, dataPtr, event.len)
275276

276277
template dispatchFFIEventCbor*(eventName: string, eventPayload: typed) =

ffi/internal/ffi_macro.nim

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ when defined(ffiGenBindings):
77
import ../codegen/cpp
88
import ../codegen/cddl
99

10-
1110
proc isPtr(typ: NimNode): bool =
1211
## True iff `typ` is a `ptr T` type expression — i.e. an `nnkPtrTy` AST node.
1312
## Used by the binding-generator metadata path to flag pointer-typed params
@@ -597,7 +596,6 @@ macro ffiRaw*(prc: untyped): untyped =
597596
echo stmts.repr
598597
return stmts
599598

600-
601599
macro ffi*(prc: untyped): untyped =
602600
## Simplified FFI macro — applies to procs or types.
603601
##
@@ -837,7 +835,6 @@ macro ffi*(prc: untyped): untyped =
837835
echo stmts.repr
838836
return stmts
839837

840-
841838
proc buildCtorRequestType(
842839
reqTypeName: NimNode, paramNames: seq[string], paramTypes: seq[NimNode]
843840
): NimNode =
@@ -1248,7 +1245,6 @@ macro ffiCtor*(prc: untyped): untyped =
12481245
echo stmts.repr
12491246
return stmts
12501247

1251-
12521248
macro ffiDtor*(prc: untyped): untyped =
12531249
## Defines a C-exported destructor that tears down the FFIContext after the
12541250
## body runs.
@@ -1361,7 +1357,6 @@ macro ffiDtor*(prc: untyped): untyped =
13611357
echo stmts.repr
13621358
return stmts
13631359

1364-
13651360
macro ffiEvent*(wireName: static[string], prc: untyped): untyped =
13661361
## Declares a library-initiated event. The annotated proc has an empty
13671362
## body — the macro fills it with a `dispatchFFIEventCbor` call so the
@@ -1449,7 +1444,6 @@ macro ffiEvent*(wireName: static[string], prc: untyped): untyped =
14491444
echo generated.repr
14501445
return generated
14511446

1452-
14531447
macro genBindings*(
14541448
outputDir: static[string] = ffiOutputDir, nimSrcRelPath: static[string] = ffiSrcPath
14551449
): untyped =

tests/e2e/cpp/CMakeLists.txt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,18 @@ elseif(NIM_FFI_SANITIZER STREQUAL "tsan")
8181
"TSAN_OPTIONS=halt_on_error=1:second_deadlock_stack=1:history_size=7")
8282
endif()
8383

84+
# Discover at test time, not build time: a POST_BUILD discovery run launches the
85+
# freshly-linked exe while Windows Defender is still scanning it (and its staged
86+
# DLLs), which routinely overran the default 5s timeout on CI. PRE_TEST defers
87+
# enumeration to `ctest`, and the bumped timeout absorbs first-launch scan delays.
8488
include(GoogleTest)
8589
if(_san_test_env)
86-
gtest_discover_tests(timer_e2e_tests PROPERTIES ENVIRONMENT "${_san_test_env}")
90+
gtest_discover_tests(timer_e2e_tests
91+
DISCOVERY_MODE PRE_TEST
92+
DISCOVERY_TIMEOUT 120
93+
PROPERTIES ENVIRONMENT "${_san_test_env}")
8794
else()
88-
gtest_discover_tests(timer_e2e_tests)
95+
gtest_discover_tests(timer_e2e_tests
96+
DISCOVERY_MODE PRE_TEST
97+
DISCOVERY_TIMEOUT 120)
8998
endif()

tests/unit/test_event_dispatch.nim

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ when not defined(gcRefc):
235235
# actually landed so a silently-broken dispatch loop is caught.
236236
check evt.called
237237

238-
239238
## A foreign-thread mutation must not be able to invalidate the
240239
## listener's `userData` while an in-flight dispatch is mid-invocation.
241240
## The dispatch templates hold `reg.lock` for the entire snapshot +
@@ -317,16 +316,14 @@ suite "liveness events":
317316
defer:
318317
deinitCallbackData(evt)
319318

320-
discard addEventListener(
321-
ctx[].eventRegistry, NotRespondingEventName, captureCb, addr evt
322-
)
319+
discard
320+
addEventListener(ctx[].eventRegistry, NotRespondingEventName, captureCb, addr evt)
323321

324322
onNotResponding(ctx)
325323

326324
waitCallback(evt)
327325
check evt.retCode == RET_OK
328-
let decoded =
329-
cborDecode(callbackBytes(evt), EventEnvelope[NotRespondingEvent])
326+
let decoded = cborDecode(callbackBytes(evt), EventEnvelope[NotRespondingEvent])
330327
check decoded.isOk()
331328
check decoded.value.eventType == NotRespondingEventName
332329

@@ -343,9 +340,8 @@ suite "liveness events":
343340
defer:
344341
deinitCallbackData(evt)
345342

346-
discard addEventListener(
347-
ctx[].eventRegistry, RespondingEventName, captureCb, addr evt
348-
)
343+
discard
344+
addEventListener(ctx[].eventRegistry, RespondingEventName, captureCb, addr evt)
349345

350346
onResponding(ctx)
351347

@@ -387,9 +383,7 @@ suite "event thread drains queued events":
387383
deinitCallbackData(evt)
388384

389385
const QueuedEvtName = "queued_evt"
390-
discard addEventListener(
391-
ctx[].eventRegistry, QueuedEvtName, captureCb, addr evt
392-
)
386+
discard addEventListener(ctx[].eventRegistry, QueuedEvtName, captureCb, addr evt)
393387

394388
# `tryEnqueueEvent` takes ownership of both buffers on success; the
395389
# event thread c_frees them after dispatch returns.

tests/unit/test_event_listener.nim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ proc tagCb(
4848
copyMem(addr payload[0], msg, int(len))
4949
record(t[].rec[], t[].name, retCode, payload)
5050

51-
5251
suite "FFIEventRegistry mutation":
5352
test "addEventListener assigns monotonically increasing non-zero ids":
5453
var reg: FFIEventRegistry

tests/unit/test_ffi_context.nim

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,6 @@ suite "sendRequestToFFIThread":
324324
check d.retCode == RET_OK
325325
check cborDecode(callbackBytes(d), string).value == "pong:" & msg
326326

327-
328327
type SimpleLib = object
329328
value: int
330329

@@ -372,7 +371,6 @@ suite "ffiCtor macro":
372371

373372
check SimpleLibFFIPool.destroyFFIContext(ctx).isOk()
374373

375-
376374
type SendConfig {.ffi.} = object
377375
message: string
378376

0 commit comments

Comments
 (0)