If I don't allocate a new buffer, then I don't need pointer to a pointer?
For example, I
just copy an existing char * iarr to errMsg?
long add(long maxn, double delta, double conf, char *errMsg)
{
long answer;
int i;
char *iarr;
//errMsg = (char *) malloc(6*sizeof(char));
answer = (long)(maxn + delta + conf);
iarr = "Hello!";
for(i=0;i<6;i++) errMsg[i] = (char) iarr[i];
return answer;
}
The document for Fiddle is so limited, wonder where I could find an example
doing
what you said? Now I can just guess and try, guess I use
buf = Fiddle::Pointer.malloc(8)
then pass buf to C function,
then try to convert string from buf returned?
Liz
On Monday, November 23, 2015 at 12:21:27 PM UTC-5, Frederick Cheung wrote:
>
> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk/9d2bcfb8-3612-4faa-92a5-08fe97e02c5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.