py.Str; py.FromCStr/FromCStrAndLen/FromGoString
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user