mirror of
https://github.com/Crocmagnon/fatcontext.git
synced 2025-02-05 12:12:32 +01:00
fix: cgo
This commit is contained in:
parent
7b0afb1f92
commit
2046ce80db
3 changed files with 59 additions and 0 deletions
|
@ -62,6 +62,10 @@ func (r *runner) run(pass *analysis.Pass) (interface{}, error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if body == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
assignStmt := findNestedContext(pass, node, body.List)
|
assignStmt := findNestedContext(pass, node, body.List)
|
||||||
if assignStmt == nil {
|
if assignStmt == nil {
|
||||||
return
|
return
|
||||||
|
|
|
@ -22,6 +22,10 @@ func TestAnalyzer(t *testing.T) {
|
||||||
desc: "no func decl",
|
desc: "no func decl",
|
||||||
dir: "no_structpointer",
|
dir: "no_structpointer",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "no func decl",
|
||||||
|
dir: "cgo",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
desc: "func decl",
|
desc: "func decl",
|
||||||
dir: "common",
|
dir: "common",
|
||||||
|
|
51
pkg/analyzer/testdata/src/cgo/cgo.go
vendored
Normal file
51
pkg/analyzer/testdata/src/cgo/cgo.go
vendored
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package cgo
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void myprint(char* s) {
|
||||||
|
printf("%d\n", s);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
cs := C.CString("Hello from stdio\n")
|
||||||
|
C.myprint(cs)
|
||||||
|
C.free(unsafe.Pointer(cs))
|
||||||
|
}
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
ctx := context.WithValue(ctx, "key", i)
|
||||||
|
ctx = context.WithValue(ctx, "other", "val")
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
ctx = context.WithValue(ctx, "key", i) // want "nested context in loop"
|
||||||
|
ctx = context.WithValue(ctx, "other", "val")
|
||||||
|
}
|
||||||
|
|
||||||
|
for item := range []string{"one", "two", "three"} {
|
||||||
|
ctx = wrapContext(ctx) // want "nested context in loop"
|
||||||
|
ctx := context.WithValue(ctx, "key", item)
|
||||||
|
ctx = wrapContext(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
ctx = wrapContext(ctx) // want "nested context in loop"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func wrapContext(ctx context.Context) context.Context {
|
||||||
|
return context.WithoutCancel(ctx)
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue