Ruby on Rails Monday, November 23, 2015

On Monday, November 23, 2015 at 3:25:07 PM UTC, Liz Huang wrote:


Thanks!

Strange that I am able to get error message before just using char *, thought
it meant passing string by pointer already.

it does, but if you want to allocate a new buffer and have the caller access that then you need pointer to a pointer
 
I change the argument to char ** errMsg, but in Ruby, when I tried to
convert the pointer to string, I got error message:

[snip]
 
if options.is_a?(::JSON::State)
# Called from JSON.{generate,dump}, forward it to JSON gem's to_json
self.to_json_without_active_support_encoder(options)
else
# to_json is being invoked directly, use ActiveSupport's encoder
ActiveSupport::JSON.encode(self, options)
Do I need to  change anything in ruby file when use a pointer?


Yes. You need to allocate a pointer size bit of memory for the C function (via Fiddle::Pointer). The C function fills that in, you then use the ptr method on Fiddle::Pointer to get the memory allocated by the C function, and create your string from there. (don't forget to free the memory too)

Fred

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f4735ef5-295e-40ac-9955-587e40c7cf0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment