When using the the special C package there are a few functions that convert from Go types to C types and vice versa. When porting code that uses C it's annoying not having an equivalent to these functions. Especially, GoString and CString which convert a C string to a Go string and vice versa. Even ebitengine had to have it's own implementation and writing these over and over is begging for mistakes. Purego already uses it's own internal versions.
I purpose adding these two functions to purego with the following signatures.
// Cstring converts a Go string to a null-terminated C string.
// The C string is allocated in the C heap using malloc.
// It is the caller's responsibility to arrange for it to be
// freed, such as by calling free.
func CString(string) *byte
// GoString converts a null-terminated C string and copies it into
// a Go allocated string.
func GoString(*byte) string
I believe these are the most used functions so should be added first. If there is strong demand later for the other ones a new issue can be created.
When using the the special C package there are a few functions that convert from Go types to C types and vice versa. When porting code that uses C it's annoying not having an equivalent to these functions. Especially,
GoStringandCStringwhich convert a C string to a Go string and vice versa. Even ebitengine had to have it's own implementation and writing these over and over is begging for mistakes. Purego already uses it's own internal versions.I purpose adding these two functions to purego with the following signatures.
I believe these are the most used functions so should be added first. If there is strong demand later for the other ones a new issue can be created.