cpp/std: support nogc

This commit is contained in:
xushiwei
2024-07-29 08:55:27 +08:00
parent e0892fcebb
commit 8b6b039c13
3 changed files with 75 additions and 10 deletions

View File

@@ -20,7 +20,6 @@ import (
"unsafe"
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/bdwgc"
)
// -----------------------------------------------------------------------------
@@ -32,7 +31,7 @@ type StringView = string
// String represents a C++ std::string object.
type String struct {
Unused [24]byte
Unused [3]uintptr
}
// llgo:link (*String).InitEmpty C.stdStringInitEmpty
@@ -52,14 +51,6 @@ func (s *String) Dispose() {}
// -----------------------------------------------------------------------------
func allocString() *String {
ptr := bdwgc.Malloc(unsafe.Sizeof(String{}))
bdwgc.RegisterFinalizer(ptr, func(obj, data c.Pointer) {
(*String)(obj).Dispose()
}, nil, nil, nil)
return (*String)(ptr)
}
// NewString creates a C++ std::string object.
func NewString(v string) *String {
ret := allocString()