Merge pull request #448 from xushiwei/q

patch fmt: printArg; py.Str; py.FromCStr/FromCStrAndLen/FromGoString
This commit is contained in:
xushiwei
2024-07-04 18:44:33 +08:00
committed by GitHub
16 changed files with 111 additions and 40 deletions

View File

@@ -174,6 +174,7 @@ type aProgram struct {
callFOArgs *types.Signature
loadPyModS *types.Signature
getAttrStr *types.Signature
pyUniStr *types.Signature
mallocTy *types.Signature
freeTy *types.Signature

View File

@@ -184,6 +184,17 @@ func (p Program) tyLoadPyModSyms() *types.Signature {
return p.loadPyModS
}
// func(*char) *Object
func (p Program) tyPyUnicodeFromString() *types.Signature {
if p.pyUniStr == nil {
charPtr := types.NewPointer(types.Typ[types.Int8])
params := types.NewTuple(types.NewParam(token.NoPos, nil, "", charPtr))
results := types.NewTuple(p.paramObjPtr())
p.pyUniStr = types.NewSignatureType(nil, nil, nil, params, results, false)
}
return p.pyUniStr
}
// func(*Objecg, *char) *Object
func (p Program) tyGetAttrString() *types.Signature {
if p.getAttrStr == nil {
@@ -332,6 +343,12 @@ func (b Builder) callPyInit() (ret Expr) {
return b.Call(fn)
}
// PyStr returns a py-style string constant expression.
func (b Builder) PyStr(v string) Expr {
fn := b.Pkg.pyFunc("PyUnicode_FromString", b.Prog.tyPyUnicodeFromString())
return b.Call(fn, b.CStr(v))
}
// -----------------------------------------------------------------------------
type aPyGlobal struct {