Skip to content

Commit

Permalink
julia 1.11: add some workarounds for jl_array changes
Browse files Browse the repository at this point in the history
  • Loading branch information
benlorenz committed Oct 28, 2023
1 parent 4888607 commit d39426a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions include/jlcxx/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
#include "type_conversion.hpp"
#include "tuple.hpp"

#if (JULIA_VERSION_MAJOR * 100 + JULIA_VERSION_MINOR) >= 111
// yes the arguments are really switched
#define jl_arrayset(args, s, i) jl_array_ptr_set(args, i, s)
#endif

namespace jlcxx
{

Expand Down Expand Up @@ -164,6 +169,14 @@ struct ArrayElementType<T,WrappedPtrTrait>
template<typename ValueT, int Dim = 1>
class ArrayRef
{
/// wrapper for julia jl_array_data for different julia versions
static julia_t* jlcxx_array_data(jl_array_t* arr) {
#if (JULIA_VERSION_MAJOR * 100 + JULIA_VERSION_MINOR) >= 111
return jl_array_data(arr, julia_t);
#else
return static_cast<julia_t*>(jl_array_data(arr));
#endif
}
public:

using julia_t = typename detail::ArrayElementType<ValueT>::type;
Expand Down Expand Up @@ -191,22 +204,22 @@ class ArrayRef

iterator begin()
{
return iterator(static_cast<julia_t*>(jl_array_data(wrapped())));
return iterator(jlcxx_array_data(wrapped()));
}

const_iterator begin() const
{
return const_iterator(static_cast<julia_t*>(jl_array_data(wrapped())));
return const_iterator(jlcxx_array_data(wrapped()));
}

iterator end()
{
return iterator(static_cast<julia_t*>(jl_array_data(wrapped())) + jl_array_len(wrapped()));
return iterator(jlcxx_array_data(wrapped()) + jl_array_len(wrapped()));
}

const_iterator end() const
{
return const_iterator(static_cast<julia_t*>(jl_array_data(wrapped())) + jl_array_len(wrapped()));
return const_iterator(jlcxx_array_data(wrapped()) + jl_array_len(wrapped()));
}

void push_back(const ValueT& val)
Expand All @@ -223,12 +236,12 @@ class ArrayRef

const julia_t* data() const
{
return (julia_t*)jl_array_data(wrapped());
return jlcxx_array_data(wrapped());
}

julia_t* data()
{
return (julia_t*)jl_array_data(wrapped());
return jlcxx_array_data(wrapped());
}

std::size_t size() const
Expand Down

0 comments on commit d39426a

Please sign in to comment.