separted the IO handlers to the source code handler and user stream handlers
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-11-05 16:58:45 +09:00
parent bcfe69feda
commit 94a44f1fd7
9 changed files with 312 additions and 213 deletions

View File

@ -5,17 +5,17 @@ package hcl
#include <hcl-utl.h>
#include <stdlib.h> // for C.freem
extern int hcl_go_read_handler (hcl_t hcl, hcl_iocmd_t cmd, void* arg);
extern int hcl_go_scan_handler (hcl_t hcl, hcl_iocmd_t cmd, void* arg);
extern int hcl_go_print_handler (hcl_t hcl, hcl_iocmd_t cmd, void* arg);
extern int hcl_go_read_handler (hcl_t hcl, hcl_io_cmd_t cmd, void* arg);
extern int hcl_go_scan_handler (hcl_t hcl, hcl_io_cmd_t cmd, void* arg);
extern int hcl_go_print_handler (hcl_t hcl, hcl_io_cmd_t cmd, void* arg);
int hcl_read_handler_for_go (hcl_t hcl, hcl_iocmd_t cmd, void* arg) {
int hcl_read_handler_for_go (hcl_t hcl, hcl_io_cmd_t cmd, void* arg) {
return hcl_go_read_handler(hcl, cmd, arg);
}
int hcl_scan_handler_for_go (hcl_t hcl, hcl_iocmd_t cmd, void* arg) {
int hcl_scan_handler_for_go (hcl_t hcl, hcl_io_cmd_t cmd, void* arg) {
return hcl_go_scan_handler(hcl, cmd, arg);
}
int hcl_print_handler_for_go (hcl_t hcl, hcl_iocmd_t cmd, void* arg) {
int hcl_print_handler_for_go (hcl_t hcl, hcl_io_cmd_t cmd, void* arg) {
return hcl_go_print_handler(hcl, cmd, arg);
}
*/
@ -181,23 +181,42 @@ func (hcl *HCL) AddBuiltinPrims() error {
return nil
}
func (hcl *HCL) AttachIO(r IOReadImpl, s IOScanImpl, p IOPrintImpl) error {
func (hcl *HCL) AttachSCIO(r IOReadImpl) error {
var x C.int
var io IOImplSet
var or IOReadImpl
io = hcl.io
or = hcl.io.r
hcl.io.r = r
x = C.hcl_attachscio(hcl.c, C.hcl_io_impl_t(C.hcl_read_handler_for_go))
if x <= -1 {
// restore the io handler set due to attachment failure
hcl.io.r = or
return fmt.Errorf("unable to attach source input stream handler - %s", hcl.get_errmsg())
}
return nil
}
func (hcl *HCL) AttachUDIO(s IOScanImpl, p IOPrintImpl) error {
var x C.int
var os IOScanImpl
var op IOPrintImpl
os = hcl.io.s
op = hcl.io.p
hcl.io.s = s
hcl.io.p = p
x = C.hcl_attachio(hcl.c,
C.hcl_ioimpl_t(C.hcl_read_handler_for_go),
C.hcl_ioimpl_t(C.hcl_scan_handler_for_go),
C.hcl_ioimpl_t(C.hcl_print_handler_for_go))
x = C.hcl_attachudio(hcl.c,
C.hcl_io_impl_t(C.hcl_scan_handler_for_go),
C.hcl_io_impl_t(C.hcl_print_handler_for_go))
if x <= -1 {
hcl.io = io // restore the io handler set due to attachment failure
return fmt.Errorf("unable to attach I/O handlers - %s", hcl.get_errmsg())
//restore the io handlers set due to attachment failure
hcl.io.s = os
hcl.io.p = op
return fmt.Errorf("unable to attach user data stream handlers - %s", hcl.get_errmsg())
}
return nil
}