Skip to content

Commit 24e8d8a

Browse files
committed
make autogen fntype private
1 parent 5edc2b9 commit 24e8d8a

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

doc/en/dev/llcppg.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ func (recv_ *Sqlite3) Exec(sql *c.Char, callback func(c.Pointer, c.Int, **c.Char
9494
}
9595
```
9696

97-
LLGo cannot use anonymous function types directly as field types. To preserve type information, llcppg automatically generates named function types and references them in the field and following this naming convention:
97+
To work around LLGo's inability to use anonymous function types directly in struct fields, llcppg automatically generates a corresponding named function type. This generated type is intentionally made unexported (private) to mirror C/C++ semantics, where anonymous function types are not externally accessible. Crucially, even though the type itself is private, this does not affect the ability to assign a compatible function to the field during normal use in Go. All such function types follow the specific naming convention:
98+
9899
```
99-
LLGO_<namespaces>_<typename>_<nested_field_typename>_<fieldname>
100+
llgo_<namespaces>_<typename>_<nested_field_typename>_<fieldname>
100101
```
101102

102103
```c
@@ -107,13 +108,13 @@ typedef struct Hooks {
107108
```
108109
```go
109110
// llgo:type C
110-
type LLGO_Hooks_MallocFn func(c.SizeT) c.Pointer
111+
type llgo_Hooks_MallocFn func(c.SizeT) c.Pointer
111112
// llgo:type C
112-
type LLGO_Hooks_FreeFn func(c.Pointer)
113+
type llgo_Hooks_FreeFn func(c.Pointer)
113114

114115
type Hooks struct {
115-
MallocFn LLGO_Hooks_MallocFn
116-
FreeFn LLGO_Hooks_FreeFn
116+
MallocFn llgo_Hooks_MallocFn
117+
FreeFn llgo_Hooks_FreeFn
117118
}
118119
```
119120

@@ -129,13 +130,13 @@ namespace A {
129130
```
130131
```go
131132
// llgo:type C
132-
type LLGO_A_Hooks_MallocFn func(c.SizeT) c.Pointer
133+
type llgo_A_Hooks_MallocFn func(c.SizeT) c.Pointer
133134
// llgo:type C
134-
type LLGO_A_Hooks_FreeFn func(c.Pointer)
135+
type llgo_A_Hooks_FreeFn func(c.Pointer)
135136

136137
type Hooks struct {
137-
MallocFn LLGO_A_Hooks_MallocFn
138-
FreeFn LLGO_A_Hooks_FreeFn
138+
MallocFn llgo_A_Hooks_MallocFn
139+
FreeFn llgo_A_Hooks_FreeFn
139140
}
140141
```
141142
in nested struct
@@ -150,15 +151,15 @@ struct Foo {
150151
```
151152
```go
152153
// llgo:type C
153-
type LLGO_Foo_Hooks_MallocFn func(c.SizeT) c.Pointer
154+
type llgo_Foo_Hooks_MallocFn func(c.SizeT) c.Pointer
154155

155156
// llgo:type C
156-
type LLGO_Foo_Hooks_FreeFn func(c.Pointer)
157+
type llgo_Foo_Hooks_FreeFn func(c.Pointer)
157158

158159
type Foo struct {
159160
Hooks struct {
160-
MallocFn LLGO_Foo_Hooks_MallocFn
161-
FreeFn LLGO_Foo_Hooks_FreeFn
161+
MallocFn llgo_Foo_Hooks_MallocFn
162+
FreeFn llgo_Foo_Hooks_FreeFn
162163
}
163164
}
164165
```

0 commit comments

Comments
 (0)