2015-10-01 23:48:33 +00:00
|
|
|
package engine
|
2015-09-17 21:22:07 +00:00
|
|
|
|
|
|
|
// #cgo CFLAGS: -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM
|
2015-10-01 23:48:33 +00:00
|
|
|
// #cgo CFLAGS: -I/usr/include/php/Zend -I../context
|
|
|
|
// #cgo LDFLAGS: -L${SRCDIR}/context -lphp5
|
2015-09-17 21:22:07 +00:00
|
|
|
//
|
|
|
|
// #include "context.h"
|
2015-10-01 23:48:33 +00:00
|
|
|
// #include "engine.h"
|
2015-09-17 21:22:07 +00:00
|
|
|
import "C"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"unsafe"
|
2015-10-01 23:48:33 +00:00
|
|
|
|
2015-10-02 17:07:57 +00:00
|
|
|
"../context"
|
2015-09-17 21:22:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Engine struct {
|
|
|
|
engine *C.struct__php_engine
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *Engine) Destroy() {
|
|
|
|
C.engine_shutdown(e.engine)
|
|
|
|
e = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func New() (*Engine, error) {
|
|
|
|
ptr, err := C.engine_init()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("PHP engine failed to initialize")
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Engine{engine: ptr}, nil
|
|
|
|
}
|
2015-10-01 23:48:33 +00:00
|
|
|
|
|
|
|
//export uwrite
|
|
|
|
func uwrite(ctxptr unsafe.Pointer, buffer unsafe.Pointer, length C.uint) C.int {
|
|
|
|
context := (*context.Context)(ctxptr)
|
|
|
|
|
|
|
|
written, err := context.Write(C.GoBytes(buffer, C.int(length)))
|
|
|
|
if err != nil {
|
|
|
|
return C.int(-1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return C.int(written)
|
|
|
|
}
|