MCPcopy Create free account
hub / github.com/libgit2/git2go / checkPkg

Function checkPkg

script/check-MakeGitError-thread-lock.go:51–73  ·  view source on GitHub ↗
(pkg *ast.Package)

Source from the content-addressed store, hash-verified

49}
50
51func checkPkg(pkg *ast.Package) error {
52 var violations []string
53 ast.Inspect(pkg, func(node ast.Node) bool {
54 switch node := node.(type) {
55 case *ast.FuncDecl:
56 var b bytes.Buffer
57 if err := printer.Fprint(&b, fset, node); err != nil {
58 log.Fatal(err)
59 }
60 src := b.String()
61
62 if strings.Contains(src, "MakeGitError") && !strings.Contains(src, "runtime.LockOSThread()") && !strings.Contains(src, "defer runtime.UnlockOSThread()") && !ignoreViolationsInFunc[node.Name.Name] {
63 pos := fset.Position(node.Pos())
64 violations = append(violations, fmt.Sprintf("%s at %s:%d", node.Name.Name, pos.Filename, pos.Line))
65 }
66 }
67 return true
68 })
69 if len(violations) > 0 {
70 return fmt.Errorf("%d non-thread-locked calls to MakeGitError found. To fix, add the following to each func below that calls MakeGitError, before the cgo call that might produce the error:\n\n\truntime.LockOSThread()\n\tdefer runtime.UnlockOSThread()\n\n%s", len(violations), strings.Join(violations, "\n"))
71 }
72 return nil
73}

Callers 1

mainFunction · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…