Skip to content

Commit

Permalink
Export jl_alloc_array_nd, re-add and export convenience wrappers (#…
Browse files Browse the repository at this point in the history
…52248)

This is used in an example here in the docs
https://docs.julialang.org/en/v1.11-dev/manual/embedding/#Multidimensional-Arrays
and needed to adapt to the removed `jl_alloc_array_2d` (#51319).
  • Loading branch information
benlorenz authored Dec 4, 2023
1 parent e280387 commit f761860
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ JL_DLLEXPORT jl_array_t *jl_alloc_array_1d(jl_value_t *atype, size_t nr)
return new_array(atype, 1, &nr);
}

JL_DLLEXPORT jl_array_t *jl_alloc_array_2d(jl_value_t *atype, size_t nr, size_t nc)
{
size_t dims[2] = {nr, nc};
return new_array(atype, 2, &dims[0]);
}

JL_DLLEXPORT jl_array_t *jl_alloc_array_3d(jl_value_t *atype, size_t nr, size_t nc, size_t z)
{
size_t dims[3] = {nr, nc, z};
return new_array(atype, 3, &dims[0]);
}

JL_DLLEXPORT jl_array_t *jl_alloc_array_nd(jl_value_t *atype, size_t *dims, size_t ndims)
{
return new_array(atype, ndims, dims);
Expand Down
3 changes: 3 additions & 0 deletions src/jl_exported_funcs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
XX(jl_adopt_thread) \
XX(jl_alignment) \
XX(jl_alloc_array_1d) \
XX(jl_alloc_array_2d) \
XX(jl_alloc_array_3d) \
XX(jl_alloc_array_nd) \
XX(jl_alloc_string) \
XX(jl_alloc_svec) \
XX(jl_alloc_svec_uninit) \
Expand Down
3 changes: 3 additions & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,9 @@ JL_DLLEXPORT jl_array_t *jl_ptr_to_array(jl_value_t *atype, void *data,
jl_value_t *dims, int own_buffer);

JL_DLLEXPORT jl_array_t *jl_alloc_array_1d(jl_value_t *atype, size_t nr);
JL_DLLEXPORT jl_array_t *jl_alloc_array_2d(jl_value_t *atype, size_t nr, size_t nc);
JL_DLLEXPORT jl_array_t *jl_alloc_array_3d(jl_value_t *atype, size_t nr, size_t nc, size_t z);
JL_DLLEXPORT jl_array_t *jl_alloc_array_nd(jl_value_t *atype, size_t *dims, size_t ndims);
JL_DLLEXPORT jl_array_t *jl_pchar_to_array(const char *str, size_t len);
JL_DLLEXPORT jl_value_t *jl_pchar_to_string(const char *str, size_t len);
JL_DLLEXPORT jl_value_t *jl_cstr_to_string(const char *str);
Expand Down

0 comments on commit f761860

Please sign in to comment.