Skip to content
Snippets Groups Projects
Commit 5dd43cf9 authored by Jooyung Han's avatar Jooyung Han
Browse files

Fix checkCalledFromInit

This function checks if it is called from init() by looking into
callers. By the way, it may fail when init() is inlined.

To fix this, CallersFrames() is used to translate PCs into symbolic
information accounting for inlined functions.

Test: go test ./...
Change-Id: I18b3c3ffdaf71f775e3522c87607aec5df7b09c5
parent a0b59d9d
Branches
No related tags found
No related merge requests found
......@@ -158,8 +158,9 @@ func callerName(skip int) (pkgPath, funcName string, ok bool) {
if n != 1 {
return "", "", false
}
f := runtime.FuncForPC(pc[0]).Name()
frames := runtime.CallersFrames(pc[:])
frame, _ := frames.Next()
f := frame.Function
s := pkgPathRe.FindStringSubmatch(f)
if len(s) < 3 {
panic(fmt.Errorf("failed to extract package path and function name from %q", f))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment