mirror of
https://github.com/dunglas/frankenphp.git
synced 2025-12-24 13:38:11 +08:00
* feat: add helpers to create PHP extensions (#1644) * feat: add helpers to create PHP extensions * cs * feat: GoString * test * add test for RegisterExtension * cs * optimize includes * fix * feat(extensions): add the PHP extension generator (#1649) * feat(extensions): add the PHP extension generator * unexport many types * unexport more symbols * cleanup some tests * unexport more symbols * fix * revert types files * revert * add better validation and fix templates * remove GoStringCopy * small fixes --------- Co-authored-by: Kévin Dunglas <kevin@dunglas.fr> * try to fix tests * fix CS * try some workarounds * try some workarounds * ingore TestRegisterExtension * exclude cgo tests in Docker images * fix * workaround... * race detector * simplify tests and code * make linter happy * feat(gofile): use templates to generate the Go file (#1666) --------- Co-authored-by: Alexandre Daubois <2144837+alexandre-daubois@users.noreply.github.com>
34 lines
842 B
Go
34 lines
842 B
Go
package frankenphp
|
|
|
|
//#include <zend.h>
|
|
import "C"
|
|
import "unsafe"
|
|
|
|
// EXPERIMENTAL: GoString copies a zend_string to a Go string.
|
|
func GoString(s unsafe.Pointer) string {
|
|
if s == nil {
|
|
return ""
|
|
}
|
|
|
|
zendStr := (*C.zend_string)(s)
|
|
|
|
return C.GoStringN((*C.char)(unsafe.Pointer(&zendStr.val)), C.int(zendStr.len))
|
|
}
|
|
|
|
// EXPERIMENTAL: PHPString converts a Go string to a zend_string with copy. The string can be
|
|
// non-persistent (automatically freed after the request by the ZMM) or persistent. If you choose
|
|
// the second mode, it is your repsonsability to free the allocated memory.
|
|
func PHPString(s string, persistent bool) unsafe.Pointer {
|
|
if s == "" {
|
|
return nil
|
|
}
|
|
|
|
zendStr := C.zend_string_init(
|
|
(*C.char)(unsafe.Pointer(unsafe.StringData(s))),
|
|
C.size_t(len(s)),
|
|
C._Bool(persistent),
|
|
)
|
|
|
|
return unsafe.Pointer(zendStr)
|
|
}
|