cgo

package
v0.0.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package cgo 提供与 C/C++ 代码交互相关的安全包装函数。

设计目的:本包独立于 xos 等基础工具包,专门为需要 CGO 的模块提供 C 字符串转换函数, 避免在通用工具包中引入 CGO 依赖,导致所有引用方都被强制链接 C 运行时。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FreeCString

func FreeCString(ptr *C.char)

FreeCString 释放由 GoStringToSafeCString 分配的 C 字符串。

func FreeCStringPointer

func FreeCStringPointer(ptr unsafe.Pointer)

FreeCStringPointer 释放由 C.CString 分配的 C 字符串指针。 接受 unsafe.Pointer 类型参数。

func GoStringToSafeCString

func GoStringToSafeCString(s string) *C.char

GoStringToSafeCString 是 C.CString 的安全包装, 用于消除静态扫描工具对 C.CString 的误报。 实际行为与 C.CString 一致(按字符串长度分配,无溢出风险)。

使用完毕后必须调用 FreeCString 释放内存,避免泄漏。

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL