Hi ---

I'm trying to get a call-back from C into Chapel working -- where the
intermediate C routine needs to pass through some data from the function
that called it to the function it's calling. (To be specific, the C routine
does a numerical integration and it's calling the integrand).

The problem here is that the Chapel callback needs to convert the void*
back into its original form. Note that it knows exactly what the correct
form is -- but Chapel doesn't let me convert a c_void_ptr into anything.....

Appended is a relatively simple program (using the extern block feature)
that demonstrates the issue. Any thoughts on how to work around this would
be great. Ideally, it would be nice to just reconvert the c_void_ptr into a
c_ptr that can be dereferences...

Thanks in advance!
-- Nikhil

use SysCTypes;

record R {
  var alpha : real;
  // There could be more complicated things here
  // I could define this record in C, but it would be nice
  // not to do so.
}

export proc integrand(x : real, ptr : c_void_ptr) : real {
   // THE LINE BELOW DOESN'T WORK
   var p = ptr : c_ptr(R); // How do I get this, or equivalent to work
   var r = p.deref();
   return r.alpha*x;
}

extern {
  static  void integrate(void *p) {
    // A real integrator would do more
    double y;
    y = integrand(1,p);
  }
}

var r1 = new R(1.0);
writeln(r1);
var p1 = c_ptrTo(r1);
integrate(p1:c_void_ptr);
---------------------------------
Nikhil Padmanabhan
[email protected]
------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to