py.Str; py.FromCStr/FromCStrAndLen/FromGoString

This commit is contained in:
xushiwei
2024-07-04 18:34:00 +08:00
parent 23da63767c
commit e55e90db1a
11 changed files with 77 additions and 17 deletions

View File

@@ -46,7 +46,7 @@ func NewFuncWithQualName(code, globals, qualname *Object) *Object
// Return true if o is a function object (has type PyFunction_Type). The
// parameter must not be nil. This function always succeeds.
//
// llgo:link (*Object).FuncCheck C.PyFunction_Check
//- llgo:link (*Object).FuncCheck C.PyFunction_Check
func (o *Object) FuncCheck() c.Int { return 0 }
*/

View File

@@ -49,5 +49,5 @@ func (t *Object) TypeFlags() uint32 { return 0 }
// llgo:link (*Object).TypeModule C.PyType_GetModule
func (t *Object) TypeModule() *Object { return nil }
// llgo:link (*Object).TypeModuleByDef C.PyType_GetModuleByDef
// -llgo:link (*Object).TypeModuleByDef C.PyType_GetModuleByDef
// func (t *Object) TypeModuleByDef(def *ModuleDef) *Object { return nil }

View File

@@ -24,6 +24,20 @@ import (
// https://docs.python.org/3/c-api/unicode.html
//go:linkname Str llgo.pystr
func Str(s string) *Object
//go:linkname FromCStr C.PyUnicode_FromString
func FromCStr(str *c.Char) *Object
//go:linkname FromCStrAndLen C.PyUnicode_FromStringAndSize
func FromCStrAndLen(str *c.Char, n int) *Object
// FromGoString returns a new Unicode object from a Go string.
func FromGoString(s string) *Object {
return FromCStrAndLen(c.GoStringData(s), len(s))
}
// Return a pointer to the UTF-8 encoding of the Unicode object, and store the
// size of the encoded representation (in bytes) in size. The size argument can
// be nil; in this case no size will be stored. The returned buffer always has