Go例外"信号在cgo执行期间到达"

时间:2014-12-28 22:10:42

标签: windows dll go ffi cgo

在什么情况下,当打电话给 dll 时,发出“信号在cgo执行期间到达”的恐慌?

要调用的代码是 - 基于go zsyscall_windows.go src中的样本:

var (
    // entry names found using dumpbin /exports
    dllSweph = syscall.NewLazyDLL("swedll32.dll")

    _swe_jdut1_to_utc = dllSweph.NewProc("_swe_jdut1_to_utc@36")
    _swe_julday       = dllSweph.NewProc("_swe_julday@24")
)

func swe_julday(year, month, day int32, hour float64, gregflag int32) float64 {
    r, _, errn := syscall.Syscall6(
        _swe_julday.Addr(),
        5,
        uintptr(year),
        uintptr(month),
        uintptr(day),
        uintptr(hour),
        uintptr(gregflag),
        0)

    if r == 0 {
        if errn != 0 {
            panic(error(errn))
        }
    }

    return float64(r)
}

func swe_jdut1_to_utc(tjd_ut float64, gregflag int32, iyear, imonth, iday, ihour, imin *int32, dsec *float64) {
    defer func() {
        if e := recover(); e != nil {
        }
    }()

    syscall.Syscall9(
        _swe_jdut1_to_utc.Addr(),
        8,
        uintptr(tjd_ut),
        uintptr(gregflag),
        uintptr(unsafe.Pointer(iyear)),
        uintptr(unsafe.Pointer(imonth)),
        uintptr(unsafe.Pointer(iday)),
        uintptr(unsafe.Pointer(ihour)),
        uintptr(unsafe.Pointer(imin)),
        uintptr(unsafe.Pointer(dsec)),
        0)
}

现在,当我打电话给swe_julday时,一切似乎都很好;虽然它不是,它给出了错误的答案。当swe_jdut1_to_utc被调用时,我得到:

Exception 0xc0000005 0x1 0x42e5e5 0x3235ce40
PC=0x3235ce40
signal arrived during cgo execution

.../sweph.swe_jdut1_to_utc(0x40000000, 0x4150b979, 0x1, 0x1207bf24, 0x1207bf28, 0x1207bf34, 0x1207bf30, 0x1207bf2c, 0x1207bf38)
...(trace info)

eax     0x0
ebx     0x1207be94
ecx     0x1207bf38
edx     0x42e5e5
edi     0xcfeac
esi     0x0
ebp     0xcfe5c
esp     0xcfdd8
eip     0x3235ce40
eflags  0x10246
cs      0x23
fs      0x53
gs      0x2b
exit status 2

exit status 1

环境:

Windows 8 x64
go 1.4    x86
gcc       x86

我不知道是否真的需要gcc才能调用dll,但我已经安装了它,因为错误大约是cgo。所有命令都在路径中。使用管理权限进行编译时出现相同的错误。

正在调用的C函数是:

void swe_jdut1_to_utc (double tjd_ut, int32 gregflag, int32 *iyear, int32 *imonth, int32 *iday, int32 *ihour, int32 *imin, double *dsec)

在该dll(& works)中导入并调用此函数的C#函数是:

[DllImport("swedll32.dll", EntryPoint = "swe_jdut1_to_utc")]
public static extern void swe_jdut1_to_utc(
    double tjd_ut,
    int gregflag,
    ref Int32 iyear, ref Int32 imonth, ref Int32 iday,
    ref Int32 ihour, ref Int32 imin, ref double dsec);

1 个答案:

答案 0 :(得分:1)

我设法构建了使用swe_julday函数的delphi应用程序。不幸的是我可以看到它使用fstp asm指令来检索由swe_julday返回的结果。 Go的syscall.Syscall不支持此功能。你是我们的运气。我认为最好的办法是使用CGO,如果可以用mingw编译器构建你的库。遗憾

亚历