BitArray unboxing

Is casting to this struct enough?

typedef struct {
   jl_array_t *chunks;
   int64_t len;
   jl_value_t *dims;
} jl_bit_array_t;

Like, I tried this

typedef struct {
    jl_array_t *chunks;
    int64_t len;
    jl_value_t *dims;
} jl_bit_array_t;

jl_bit_array_t *ret = (jl_bit_array_t*) jl_eval_string(".!([true false; true true; false false])");

int64_t len = ret->len;
uint64_t *zData = (uint64_t*) jl_array_data(ret->chunks);
jl_value_t *dimensions = ret->dims;
printf("dims: %s type \n",jl_typeof_str(ret->dims));

len and chunks are correctly aligned and the data is correct, but dims, whatever I do with it, it results in segfault.
In the above code also, jl_typeof_str resulted in segfault.

No, it’s a bits tuple, so it corresponds to a C array, not pointer.

Also note that the fields are not part of the API of BitArray, it can be changed at any time.

If it’s a C array, how to find the length of the C array?

I didn’t get what fields are here.

Edit:
I was able to get the Tuple, the array ends with a 0. Using that I found out the length of the array. Is there a better and cleaner way?

You need to know it. You can know it from the julia type.

The struct you try to declare.

No it doesn’t always.

1 Like