Ruby, GO and FFi - and I am in trouble! ;( [repost from comments]

blov · · 579 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I got really excited about <a href="/u/peterhellberg">/u/peterhellberg</a>&#39;s post and I may have &#39;overcommitted&#39; myself. </p> <p>This week I rewrote a word-tree parser (at least the part that was taking over 60 seconds in ruby for a large project) in go and attached a few methods to the original ruby class. Things work amazingly, except sometimes I receive back from go a string with extra characters (...\&#34;friends\&#34;,\&#34;and\&#34;,\&#34;family\&#34;]]}]@e&amp; \xC8&#34;) - subsequential calls to the same method would randomly return the correct string, and differently formatted incorrect strings. Granted, I can &#39;trim&#39; the string, but that does not solve the problem. I&#39;ve only been experimenting with go for a week now and this is my first experiment with FFi.</p> <p>I&#39;ve been changing the :pointer / :string as argument of the attached method with different ratio of fail / success ... <a href="https://gist.github.com/etozzato/5cc4c566d5c54e366d18">https://gist.github.com/etozzato/5cc4c566d5c54e366d18</a></p> <hr/>**评论:**<br/><br/>mortonpe: <pre><p>I am not exactly a CGO expert, but is <em>seems</em> that you are returning a GOstring and not a CString. I would imagine that your output should be converted to a *C.char using C.CString(string). </p> <p><a href="https://golang.org/cmd/cgo/">https://golang.org/cmd/cgo/</a></p></pre>mekdigital: <pre><p>This also makes sense! thanks. </p></pre>funny_falcon: <pre><p>try to explicitely add nul-termination byte to a string.</p></pre>mekdigital: <pre><p>I am really hoping that, with this suggestion, we&#39;ll be able to land that f*ing rocket back on the barge!!! :P</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

579 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传