在什么情况下 Go 在调用 dll 时会出现“signal arrived during cgo execution”之类的 panic?
要调用的代码是——基于go分发的src中的zsyscall_windows.go中的示例:
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)
C# 函数在该 dll 中导入并调用此函数(并且有效)是:
[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);
最佳答案
我设法构建了使用 swe_julday 函数的 delphi 应用程序。不幸的是,我可以看到它使用 fstp asm 指令来检索 swe_julday 返回的结果。 Go 的 syscall.Syscall 不支持此功能。你是我们的幸运。如果可以使用 mingw 编译器构建库,我认为最好的选择是使用 CGO。抱歉
亚历克斯
关于windows - 转到异常 "signal arrived during cgo execution",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27681094/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在学习Rails,并阅读了关于乐观锁的内容。我已将类型为integer的lock_version列添加到我的articles表中。但现在每当我第一次尝试更新记录时,我都会收到StaleObjectError异常。这是我的迁移:classAddLockVersionToArticle当我尝试通过Rails控制台更新文章时:article=Article.first=>#我这样做:article.title="newtitle"article.save我明白了:(0.3ms)begintransaction(0.3ms)UPDATE"articles"SET"title"='dwdwd
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub