Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
on-keyday committed Apr 23, 2024
1 parent 639b72a commit 2a46067
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 16 deletions.
15 changes: 14 additions & 1 deletion src/tool/s2jgo/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,22 @@ func (a *argHolder) makeArg(args []string) (argc uintptr, argv uintptr) {
return
}

func Load(path string) (*Src2JSON, error) {
s, err := load(path)
if err != nil {
return nil, err
}
return &Src2JSON{s}, nil

}

type Src2JSON struct {
*src2JSON
}

func (s *Src2JSON) Call(args []string, cap Capability) (*Result, error) {
var stdout, stderr []byte
err := s.CallIOCallback(args, cap, func(data []byte, isStdErr bool) {
err := s.src2JSON.CallIOCallback(args, cap, func(data []byte, isStdErr bool) {
if isStdErr {
stderr = append(stderr, data...)
} else {
Expand Down
14 changes: 7 additions & 7 deletions src/tool/s2jgo/s2j_dlopen.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build (linux || darwin || freebsd || openbsd || netbsd || dragonfly || solaris || android)
//go:build linux || darwin || freebsd || openbsd || netbsd || dragonfly || solaris || android

package s2jgo

Expand Down Expand Up @@ -35,12 +35,12 @@ func Available() bool {
return true
}

type Src2JSON struct {
type src2JSON struct {
dll unsafe.Pointer
proc unsafe.Pointer
}

func Load(path string) (*Src2JSON, error) {
func load(path string) (*src2JSON, error) {
if !filepath.IsAbs(path) {
return nil, errors.New("s2j_path must be absolute path")
}
Expand All @@ -51,19 +51,19 @@ func Load(path string) (*Src2JSON, error) {
proc := C.dlsym(dll, C.CString("libs2j_call"))
if proc == nil {
C.dlclose(dll)
return nil, fmt.Errorf("failed to find Src2JSON in %s", path)
return nil, fmt.Errorf("failed to find libs2j_call in %s", path)
}
s2j := &Src2JSON{
s2j := &src2JSON{
dll: unsafe.Pointer(dll),
proc: unsafe.Pointer(proc),
}
runtime.SetFinalizer(s2j, func(dll *Src2JSON) {
runtime.SetFinalizer(s2j, func(dll *src2JSON) {
C.dlclose(dll.dll)
})
return s2j, nil
}

func (s *Src2JSON) CallIOCallback(args []string, cap Capability, cb func(data []byte, isStdErr bool)) error {
func (s *src2JSON) CallIOCallback(args []string, cap Capability, cb func(data []byte, isStdErr bool)) error {
if len(args) == 0 {
return errors.New("args must not be empty")
}
Expand Down
8 changes: 4 additions & 4 deletions src/tool/s2jgo/s2j_stub.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !windows && !linux && !darwin && !freebsd && !openbsd && !netbsd && !dragonfly && !solaris
//go:build !windows && !linux && !darwin && !freebsd && !openbsd && !netbsd && !dragonfly && !solaris && !android

package s2jgo

Expand All @@ -8,12 +8,12 @@ func Available() bool {
return false
}

type Src2JSON struct{}
type src2JSON struct{}

func Load(s2j_path string) (*Src2JSON, error) {
func load(_ string) (*src2JSON, error) {
return nil, errors.New("not implemented")
}

func (s *Src2JSON) CallIOCallback(args []string, cap Capability, cb func(data []byte, isStdErr bool)) error {
func (s *src2JSON) CallIOCallback(args []string, cap Capability, cb func(data []byte, isStdErr bool)) error {
return errors.New("not implemented")
}
8 changes: 4 additions & 4 deletions src/tool/s2jgo/s2j_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func Available() bool {
return true
}

type Src2JSON struct {
type src2JSON struct {
dll *windows.DLL
libs2j_call *windows.Proc
}

func Load(s2j_path string) (_ *Src2JSON, err error) {
func load(s2j_path string) (_ *src2JSON, err error) {
if !filepath.IsAbs(s2j_path) {
return nil, errors.New("s2j_path must be absolute path")
}
Expand Down Expand Up @@ -53,13 +53,13 @@ func Load(s2j_path string) (_ *Src2JSON, err error) {
runtime.SetFinalizer(dll, func(dll *windows.DLL) {
dll.Release()
})
return &Src2JSON{
return &src2JSON{
dll: dll,
libs2j_call: proc,
}, nil
}

func (s *Src2JSON) CallIOCallback(args []string, cap Capability, cb func(data []byte, isStdErr bool)) error {
func (s *src2JSON) CallIOCallback(args []string, cap Capability, cb func(data []byte, isStdErr bool)) error {
if len(args) == 0 {
return errors.New("args must not be empty")
}
Expand Down

0 comments on commit 2a46067

Please sign in to comment.