Skip to content

Commit

Permalink
findExternLinkFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Mar 24, 2023
1 parent d7d1cc3 commit c771b73
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions opblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"sync/atomic"
"unsafe"

"github.com/goplus/igop/load"
"github.com/goplus/reflectx"
"github.com/visualfc/funcval"
"github.com/visualfc/xtype"
Expand Down Expand Up @@ -249,6 +250,41 @@ func findExternValue(interp *Interp, name string) (ext reflect.Value, ok bool) {
return
}

func findExternLinkFunc(interp *Interp, link *load.Linkname) (ext reflect.Value, ok bool) {
fullName := link.PkgPath + "." + link.Name
// check override value
ext, ok = interp.ctx.override[fullName]
if ok {
return
}
// check extern value
ext, ok = externValues[fullName]
if ok {
return
}
// check install pkg
if pkg, found := interp.installed(link.PkgPath); found {
if recv := link.Recv; recv != "" {
var star bool
if recv[0] == '*' {
star = true
recv = recv[1:]
}
if typ, ok := pkg.NamedTypes[recv]; ok {
if star {
typ = reflect.PtrTo(typ)
}
if m, ok := reflectx.MethodByName(typ, link.Method); ok {
return m.Func, true
}
}
return
}
ext, ok = pkg.Funcs[link.Name]
}
return
}

func findExternVar(interp *Interp, pkgPath string, name string) (ext reflect.Value, ok bool) {
fullName := pkgPath + "." + name
// check override value
Expand Down
2 changes: 1 addition & 1 deletion visit.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func wrapMethodType(sig *types.Signature) *types.Signature {
}

func (visit *visitor) findLinkFunc(sym *load.LinkSym) (ext reflect.Value, ok bool) {
ext, ok = findExternValue(visit.intp, sym.Linkname.PkgPath+"."+sym.Linkname.Name)
ext, ok = findExternLinkFunc(visit.intp, &sym.Linkname)
if ok {
return
}
Expand Down

0 comments on commit c771b73

Please sign in to comment.