<p>I got really excited about <a href="/u/peterhellberg">/u/peterhellberg</a>'s post and I may have 'overcommitted' 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 (...\"friends\",\"and\",\"family\"]]}]@e& \xC8") - subsequential calls to the same method would randomly return the correct string, and differently formatted incorrect strings. Granted, I can 'trim' the string, but that does not solve the problem. I've only been experimenting with go for a week now and this is my first experiment with FFi.</p>
<p>I'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'll be able to land that f*ing rocket back on the barge!!! :P</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传