deferInit bugfix
This commit is contained in:
@@ -247,10 +247,12 @@ func newParams(fn Type, prog Program) (params []Type, hasVArg bool) {
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
// Name returns the function's name.
|
||||
func (p Function) Name() string {
|
||||
return p.impl.Name()
|
||||
}
|
||||
*/
|
||||
|
||||
// Params returns the function's ith parameter.
|
||||
func (p Function) Param(i int) Expr {
|
||||
|
||||
@@ -131,14 +131,14 @@ type aProgram struct {
|
||||
rtSliceTy llvm.Type
|
||||
rtMapTy llvm.Type
|
||||
|
||||
anyTy Type
|
||||
voidTy Type
|
||||
voidPtr Type
|
||||
voidPPtr Type
|
||||
boolTy Type
|
||||
cstrTy Type
|
||||
cintTy Type
|
||||
cintPtr Type
|
||||
anyTy Type
|
||||
voidTy Type
|
||||
voidPtr Type
|
||||
voidPPtr Type
|
||||
boolTy Type
|
||||
cstrTy Type
|
||||
cintTy Type
|
||||
//cintPtr Type
|
||||
stringTy Type
|
||||
uintptrTy Type
|
||||
intTy Type
|
||||
@@ -444,6 +444,7 @@ func (p Program) Any() Type {
|
||||
return p.anyTy
|
||||
}
|
||||
|
||||
/*
|
||||
// Eface returns the empty interface type.
|
||||
// It is equivalent to Any.
|
||||
func (p Program) Eface() Type {
|
||||
@@ -457,6 +458,7 @@ func (p Program) CIntPtr() Type {
|
||||
}
|
||||
return p.cintPtr
|
||||
}
|
||||
*/
|
||||
|
||||
// CInt returns c.Int type.
|
||||
func (p Program) CInt() Type {
|
||||
@@ -649,13 +651,13 @@ func (p Package) afterBuilder() Builder {
|
||||
|
||||
// AfterInit is called after the package is initialized (init all packages that depends on).
|
||||
func (p Package) AfterInit(b Builder, ret BasicBlock) {
|
||||
p.deferInit()
|
||||
doAfterb := p.afterb != nil
|
||||
doPyLoadModSyms := p.pyHasModSyms()
|
||||
if doAfterb || doPyLoadModSyms {
|
||||
b.SetBlockEx(ret, afterInit, false)
|
||||
if doAfterb {
|
||||
afterb := Builder(p.afterb)
|
||||
p.deferInit(afterb)
|
||||
afterb.Return()
|
||||
b.Call(afterb.Func.Expr)
|
||||
}
|
||||
|
||||
@@ -27,6 +27,16 @@ import (
|
||||
"github.com/goplus/llvm"
|
||||
)
|
||||
|
||||
func TestEndDefer(t *testing.T) {
|
||||
prog := NewProgram(nil)
|
||||
pkg := prog.NewPackage("foo", "foo")
|
||||
sigMain := types.NewSignatureType(nil, nil, nil, nil, nil, false)
|
||||
fn := pkg.NewFunc("main", sigMain, InC)
|
||||
b := fn.MakeBody(1)
|
||||
fn.defer_ = &aDefer{}
|
||||
fn.endDefer(b)
|
||||
}
|
||||
|
||||
func TestUnsafeString(t *testing.T) {
|
||||
prog := NewProgram(nil)
|
||||
prog.SetRuntime(func() *types.Package {
|
||||
@@ -187,6 +197,7 @@ func TestVar(t *testing.T) {
|
||||
if pkg.NewVar("a", types.Typ[types.Int], InGo) != a {
|
||||
t.Fatal("NewVar(a) failed")
|
||||
}
|
||||
pkg.NewVarEx("a", prog.Type(types.Typ[types.Int], InGo))
|
||||
a.Init(prog.Val(100))
|
||||
b := pkg.NewVar("b", types.Typ[types.Int], InGo)
|
||||
b.Init(a.Expr)
|
||||
|
||||
@@ -163,7 +163,7 @@ func (p Program) tyDeferFunc() *types.Signature {
|
||||
}
|
||||
*/
|
||||
|
||||
func (p Package) deferInit(b Builder) {
|
||||
func (p Package) deferInit() {
|
||||
keyVar := p.VarOf(deferKey)
|
||||
if keyVar == nil {
|
||||
return
|
||||
@@ -173,6 +173,7 @@ func (p Package) deferInit(b Builder) {
|
||||
keyVar.Init(keyNil)
|
||||
keyVar.impl.SetLinkage(llvm.LinkOnceAnyLinkage)
|
||||
|
||||
b := p.afterBuilder()
|
||||
eq := b.BinOp(token.EQL, b.Load(keyVar.Expr), keyNil)
|
||||
b.IfThen(eq, func() {
|
||||
b.pthreadKeyCreate(keyVar.Expr, prog.Null(prog.VoidPtr()))
|
||||
|
||||
Reference in New Issue
Block a user