You are missing a gc root for x when you allocate y. I can't say if that is
the only issue, since you seem to be unboxing a jl_array_t* using
jl_unbox_voidpointer
On Fri, Nov 21, 2014 at 1:51 PM David Smith <david.sm...@gmail.com> wrote:

> The following code works as posted, but when I increase N to 10000000, I
> get a segfault. I don't see why that would break anything, as the size_t
> type should be large enough to handle that.
>
> Can someone point me in the right direction?
>
> Thanks!
>
>
> #include <julia.h>
> #include <stdio.h>
>
> int main()
> {
>     size_t N = 1000000;
>     jl_init(NULL);
>     JL_SET_STACK_BASE;
>     jl_value_t* array_type = jl_apply_array_type( jl_float64_type, 1 );
>     jl_array_t* x = jl_alloc_array_1d(array_type, N);
>     jl_array_t* y = jl_alloc_array_1d(array_type, N);
>     JL_GC_PUSH2(&x, &y);
>     double* xData = jl_array_data(x);
>     double* yData = jl_array_data(y);
>     for (size_t i=0; i<jl_array_len(x); i++){
>         xData[i] = i;
>         yData[i] = i;
>     }
>     jl_eval_string("myfft(x,y) = fft(complex(x,y))");
>     jl_function_t *func = jl_get_function(jl_current_module, "myfft");
>     jl_value_t* jlret = jl_call2(func, (jl_value_t*) x, (jl_value_t*)y);
>     double *ret = jl_unbox_voidpointer(jlret);
>     for(size_t i=0; i<10; i++)
>         printf("(%f,%f) = %f + %fi\n", xData[i], yData[i], ret[2*i],
> ret[2*i+1]);
>     JL_GC_POP();
>     return 0;
> }
>

Reply via email to