File tree 8 files changed +11
-47
lines changed
8 files changed +11
-47
lines changed Original file line number Diff line number Diff line change @@ -39,24 +39,7 @@ <h3 id="go-command">Go command</h3>
39
39
40
40
< h3 id ="cgo "> Cgo</ h3 >
41
41
42
- < p > <!-- CL 497837 --> The special comment that precedes
43
- < code > import</ code > < code > "C"</ code > may now include two
44
- new < code > #cgo</ code > directives.
45
- < ul >
46
- < li >
47
- < code > #cgo</ code > < code > noescape</ code > < code > cFunctionName</ code >
48
- tells cgo that Go pointers passed to the C function
49
- < code > cFunctionName</ code > do not escape.
50
- </ li >
51
- < li >
52
- < code > #cgo</ code > < code > nocallback</ code > < code > cFunctionName</ code >
53
- tells cgo that the C function < code > cFunctionName</ code > does
54
- not call any Go functions.
55
- </ li >
56
- </ ul >
57
- See < a href ="/cmd/cgo#hdr-Optimizing_calls_of_C_code "> the < code > cgo</ code >
58
- documentation</ a > for more details.
59
- </ p >
42
+ <!-- CL 497837 reverted -->
60
43
61
44
< h2 id ="runtime "> Runtime</ h2 >
62
45
Original file line number Diff line number Diff line change @@ -420,30 +420,6 @@ passing uninitialized C memory to Go code if the Go code is going to
420
420
store pointer values in it. Zero out the memory in C before passing it
421
421
to Go.
422
422
423
- # Optimizing calls of C code
424
-
425
- When passing a Go pointer to a C function the compiler normally ensures
426
- that the Go object lives on the heap. If the C function does not keep
427
- a copy of the Go pointer, and never passes the Go pointer back to Go code,
428
- then this is unnecessary. The #cgo noescape directive may be used to tell
429
- the compiler that no Go pointers escape via the named C function.
430
- If the noescape directive is used and the C function does not handle the
431
- pointer safely, the program may crash or see memory corruption.
432
-
433
- For example:
434
-
435
- // #cgo noescape cFunctionName
436
-
437
- When a Go function calls a C function, it prepares for the C function to
438
- call back to a Go function. the #cgo nocallback directive may be used to
439
- tell the compiler that these preparations are not necessary.
440
- If the nocallback directive is used and the C function does call back into
441
- Go code, the program will panic.
442
-
443
- For example:
444
-
445
- // #cgo nocallback cFunctionName
446
-
447
423
# Special cases
448
424
449
425
A few special C types which would normally be represented by a pointer
Original file line number Diff line number Diff line change @@ -94,8 +94,10 @@ func (f *File) ProcessCgoDirectives() {
94
94
directive := fields [1 ]
95
95
funcName := fields [2 ]
96
96
if directive == "nocallback" {
97
+ fatalf ("#cgo nocallback disabled until Go 1.23" )
97
98
f .NoCallbacks [funcName ] = true
98
99
} else if directive == "noescape" {
100
+ fatalf ("#cgo noescape disabled until Go 1.23" )
99
101
f .NoEscapes [funcName ] = true
100
102
}
101
103
}
Original file line number Diff line number Diff line change @@ -117,7 +117,8 @@ int add(int x, int y) {
117
117
118
118
// escape vs noescape
119
119
120
- #cgo noescape handleGoStringPointerNoescape
120
+ // TODO(#56378): enable in Go 1.23:
121
+ // #cgo noescape handleGoStringPointerNoescape
121
122
void handleGoStringPointerNoescape(void *s) {}
122
123
123
124
void handleGoStringPointerEscape(void *s) {}
Original file line number Diff line number Diff line change 5
5
package main
6
6
7
7
/*
8
- // ERROR MESSAGE: #cgo noescape noMatchedCFunction: no matched C function
8
+ // TODO(#56378): change back to "#cgo noescape noMatchedCFunction: no matched C function" in Go 1.23
9
+ // ERROR MESSAGE: #cgo noescape disabled until Go 1.23
9
10
#cgo noescape noMatchedCFunction
10
11
*/
11
12
import "C"
Original file line number Diff line number Diff line change @@ -754,6 +754,7 @@ func TestNeedmDeadlock(t *testing.T) {
754
754
}
755
755
756
756
func TestCgoNoCallback (t * testing.T ) {
757
+ t .Skip ("TODO(#56378): enable in Go 1.23" )
757
758
got := runTestProg (t , "testprogcgo" , "CgoNoCallback" )
758
759
want := "function marked with #cgo nocallback called back into Go"
759
760
if ! strings .Contains (got , want ) {
@@ -762,6 +763,7 @@ func TestCgoNoCallback(t *testing.T) {
762
763
}
763
764
764
765
func TestCgoNoEscape (t * testing.T ) {
766
+ t .Skip ("TODO(#56378): enable in Go 1.23" )
765
767
got := runTestProg (t , "testprogcgo" , "CgoNoEscape" )
766
768
want := "OK\n "
767
769
if got != want {
Original file line number Diff line number Diff line change @@ -8,8 +8,7 @@ package main
8
8
// But it do callback to go in this test, Go should crash here.
9
9
10
10
/*
11
- #cgo nocallback runCShouldNotCallback
12
-
11
+ // TODO(#56378): #cgo nocallback runCShouldNotCallback
13
12
extern void runCShouldNotCallback();
14
13
*/
15
14
import "C"
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ package main
13
13
// 2. less than 100 new allocated heap objects after invoking withoutNoEscape 100 times.
14
14
15
15
/*
16
- #cgo noescape runCWithNoEscape
16
+ // TODO(#56378): #cgo noescape runCWithNoEscape
17
17
18
18
void runCWithNoEscape(void *p) {
19
19
}
You can’t perform that action at this time.
0 commit comments