Skip to content

Commit 6ec931c

Browse files
authored
sync: fix C.pthread_mutex_t struct typedef is missing in darwin (fix: #15491) (#15845)
1 parent 5c716af commit 6ec931c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

vlib/sync/sync_darwin.c.v

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ fn C.pthread_cond_wait(voidptr, voidptr) int
3030
fn C.pthread_cond_timedwait(voidptr, voidptr, voidptr) int
3131
fn C.pthread_cond_destroy(voidptr) int
3232

33+
[typedef]
34+
struct C.pthread_mutex_t {}
35+
36+
[typedef]
37+
struct C.pthread_rwlock_t {}
38+
39+
[typedef]
40+
struct C.pthread_rwlockattr_t {}
41+
42+
[typedef]
43+
struct C.sem_t {}
44+
3345
// [init_with=new_mutex] // TODO: implement support for this struct attribute, and disallow Mutex{} from outside the sync.new_mutex() function.
3446
[heap]
3547
pub struct Mutex {

vlib/v/tests/str_gen_test.v

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sync
2+
13
fn test_array_of_floats() {
24
// f64 array
35
aa := [1.2, 3.4, 5.67]
@@ -444,3 +446,20 @@ fn test_fixed_array_of_function() {
444446
println(a)
445447
assert '$a' == '[fn (string), fn (string)]'
446448
}
449+
450+
struct CTypeDefStruct {
451+
mutex &sync.Mutex
452+
}
453+
454+
fn test_c_struct_typedef() {
455+
$if macos || linux {
456+
c := CTypeDefStruct{
457+
mutex: sync.new_mutex()
458+
}
459+
assert c.str() == r'CTypeDefStruct{
460+
mutex: &sync.Mutex{
461+
mutex: pthread_mutex_t{}
462+
}
463+
}'
464+
}
465+
}

0 commit comments

Comments
 (0)