From ca847dc7c5dd247e24eb45a83c6bf1cdb5306191 Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Sun, 27 Nov 2022 08:30:53 -0700 Subject: [PATCH] Stripped containing struct from Engine --- ph7.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/ph7.go b/ph7.go index 113f3e3..0d096cf 100644 --- a/ph7.go +++ b/ph7.go @@ -68,25 +68,25 @@ func (e Error) Error() string { return fmt.Sprintf("ph7: %s", e.Code) } -type Engine struct { - ptr *C.ph7 -} +type Engine C.ph7 -func NewEngine() (Engine, error) { - var engine Engine - result := C.ph7_init(&engine.ptr) +// TODO strip off the enclosing struct if possible after wrapping all engine methods. + +func NewEngine() (*Engine, error) { + var cengine *C.ph7 + result := C.ph7_init(&cengine) if result != C.PH7_OK { - return Engine{}, newError(result) + return nil, newError(result) } - return engine, nil + return (*Engine)(cengine), nil } -func (e Engine) ErrLog() (string, error) { +func (e *Engine) ErrLog() (string, error) { var s *C.char var n C.int - err := newError(C.engine_config_err_log(e.ptr, &s, &n)) + err := newError(C.engine_config_err_log((*C.ph7)(e), &s, &n)) if err != nil { return "", err } @@ -94,24 +94,24 @@ func (e Engine) ErrLog() (string, error) { return C.GoStringN(s, n), nil } -func (e Engine) Compile(source []byte, phpOnly bool) (*VM, error) { +func (e *Engine) Compile(source []byte, phpOnly bool) (*VM, error) { csource := C.CBytes(source) defer C.free(csource) var flags C.int if phpOnly { flags |= C.PH7_PHP_ONLY } - var ptr *C.ph7_vm - err := newError(C.ph7_compile_v2(e.ptr, (*C.char)(csource), C.int(len(source)), &ptr, flags)) + var cvm *C.ph7_vm + err := newError(C.ph7_compile_v2((*C.ph7)(e), (*C.char)(csource), C.int(len(source)), &cvm, flags)) if err != nil { return nil, err } - return newVM(ptr), nil + return newVM(cvm), nil } -func (e Engine) Close() error { - return newError(C.ph7_release(e.ptr)) +func (e *Engine) Close() error { + return newError(C.ph7_release((*C.ph7)(e))) } type Value C.ph7_value