Hi,

I am trying to use Fiddle to call C function in dynamic library, I used to 
be able to
pass a return long variable and an error message, but now only return long 
variable
is returned, can't get the error message, I create a very simple example to 
test,
this is my add.c 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

long add(long maxn, double delta, double conf, char *errMsg)
{
        long answer;

        errMsg = (char *) malloc(6*sizeof(char));
        answer = (long)(maxn + delta + conf);
        errMsg = "Hello!";

        return answer;
}

and add.h

#ifndef add_h
#define add_h

long add(long maxn, double delta, double conf, char *errMsg);

#endif

I created lib_add.so  and  part of my .rb file calling fiddle:

class SamplesizeController < ApplicationController
  require 'fiddle'

.....
  def compute

         str = "there!"
         libm = Fiddle.dlopen('/var/www/myapp/smart/lib/lib_add.so')
         add = Fiddle::Function.new(libm['add'],[Fiddle::TYPE_LONG,
                                   Fiddle::TYPE_DOUBLE,
                                   Fiddle::TYPE_DOUBLE,
                                   Fiddle::TYPE_VOIDP],
                                   Fiddle::TYPE_LONG)

        add.call(session[:nmax], session[:delta], session[:conf], str)
        session[:errmsg] = str.to_s
        redirect_to :action => "results"
    end

....

end

session[:errmsg] can be modified? only return variable can be changed or 
something I did
was wrong? Any advice will be greatly appreciated.

Thanks!
Liz


-- 
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/c92e3d8e-916c-48b2-bed0-88ba58724ae5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to