Hi -
Brad pointed out a reasonable workaround, but I see no reason why we
shouldn't support casts of this type.
If fact, Kyle added them in revision 21b548ae.
Nikhil, the test program you have works for me (once I add a C
prototype for integrand - a full copy of my version is below).
I'm using master - which will soon be our 1.13 release. Were you
originally encountering this error with 1.12? Can you verify
that master resolves it for you in your real application?
Thanks,
-michael
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 {
extern double integrand(double x, void* ptr);
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);
On 3/18/16, 2:22 PM, "Nikhil Padmanabhan" <[email protected]>
wrote:
>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=278785351&iu=/4140
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users