Skip to content

Commit 42dd55b

Browse files
committed
fix: make tests green with the race detector
1 parent bd7c07e commit 42dd55b

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ jobs:
5656
env:
5757
PKG_CONFIG_PATH: ${{ github.workspace }}/fswatch/target/lib/pkgconfig
5858
LD_LIBRARY_PATH: ${{ github.workspace }}/fswatch/target/lib
59-
run: go test
59+
run: go test -race

fswatch.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#include "fswatch.h"
22
#include "_cgo_export.h"
3-
#include <stdint.h>
43

5-
void process_events(fsw_cevent const *const events,
6-
const unsigned int event_num, void *data) {
4+
static inline void process_events(fsw_cevent const *const events,
5+
const unsigned int event_num, void *data) {
76
go_callback((fsw_cevent *)events, event_num, (uintptr_t)data);
8-
}
7+
}
8+
9+
void set_callback(const FSW_HANDLE handle, uintptr_t data) {
10+
fsw_set_callback(handle, process_events, (void *)data);
11+
}

fswatch.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package fswatch
33

44
// #cgo pkg-config: libfswatch
5+
// #cgo CFLAGS: -Wall -Werror
56
// #include <stdint.h>
67
// #include <stdlib.h>
78
// #include <libfswatch/c/libfswatch.h>
@@ -139,7 +140,7 @@ func NewSession(paths []string, c Callback, options ...Option) (*Session, error)
139140
h := cgo.NewHandle(s)
140141
s.callback = c
141142
s.cgoHandle = h
142-
C.fsw_set_callback(s.handle, C.FSW_CEVENT_CALLBACK(C.process_events), unsafe.Pointer(h)) //nolint:unsafeptr
143+
C.set_callback(s.handle, C.uintptr_t(h))
143144

144145
return s, nil
145146
}

fswatch.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1+
#include <stdint.h>
12
#include <libfswatch/c/libfswatch.h>
23

3-
void process_events(fsw_cevent const *const events,
4-
const unsigned int event_num, void *data);
4+
void set_callback(const FSW_HANDLE handle, uintptr_t data);

0 commit comments

Comments
 (0)