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

@@ -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