globalType: support typepatch
This commit is contained in:
@@ -139,7 +139,7 @@ func (p *context) compileMethods(pkg llssa.Package, typ types.Type) {
|
||||
|
||||
// Global variable.
|
||||
func (p *context) compileGlobal(pkg llssa.Package, gbl *ssa.Global) {
|
||||
typ := gbl.Type()
|
||||
typ := globalType(gbl)
|
||||
name, vtype, define := p.varName(gbl.Pkg.Pkg, gbl)
|
||||
if vtype == pyVar || ignoreName(name) || checkCgo(gbl.Name()) {
|
||||
return
|
||||
@@ -803,4 +803,15 @@ func processPkg(ctx *context, ret llssa.Package, pkg *ssa.Package) {
|
||||
}
|
||||
}
|
||||
|
||||
func globalType(gbl *ssa.Global) types.Type {
|
||||
t := gbl.Type()
|
||||
if t, ok := t.(*types.Named); ok {
|
||||
o := t.Obj()
|
||||
if pkg := o.Pkg(); typepatch.IsPatched(pkg) {
|
||||
return gbl.Pkg.Pkg.Scope().Lookup(o.Name()).Type()
|
||||
}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
@@ -463,7 +463,7 @@ func (p *context) varOf(b llssa.Builder, v *ssa.Global) llssa.Expr {
|
||||
}
|
||||
ret := pkg.VarOf(name)
|
||||
if ret == nil {
|
||||
ret = pkg.NewVar(name, v.Type(), llssa.Background(vtype))
|
||||
ret = pkg.NewVar(name, globalType(v), llssa.Background(vtype))
|
||||
}
|
||||
return ret.Expr
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ type Once struct {
|
||||
}
|
||||
|
||||
func (o *Once) Do(f func()) {
|
||||
println("Once.Do start", o.done)
|
||||
if !o.done {
|
||||
o.m.Lock()
|
||||
defer o.m.Unlock()
|
||||
|
||||
@@ -60,6 +60,9 @@ const (
|
||||
)
|
||||
|
||||
func IsPatched(pkg *types.Package) bool {
|
||||
if pkg == nil {
|
||||
return false
|
||||
}
|
||||
p := (*typesPackage)(unsafe.Pointer(pkg))
|
||||
return *(*uint8)(unsafe.Pointer(&p.complete)) == tagPatched
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user