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 7308b40
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions include/jlcxx/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ class Array
JL_GC_PUSH1(&m_array);
const size_t pos = jl_array_len(m_array);
jl_array_grow_end(m_array, 1);
#if (JULIA_VERSION_MAJOR * 100 + JULIA_VERSION_MINOR) >= 111
jl_array_ptr_set(m_array, pos, box<ValueT>(val));
#else
jl_arrayset(m_array, box<ValueT>(val), pos);
#endif
JL_GC_POP();
}

Expand Down Expand Up @@ -165,9 +169,19 @@ template<typename ValueT, int Dim = 1>
class ArrayRef
{
public:

using julia_t = typename detail::ArrayElementType<ValueT>::type;

private:
/// 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:
ArrayRef(jl_array_t* arr) : m_array(arr)
{
assert(wrapped() != nullptr);
Expand All @@ -191,22 +205,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 @@ -217,18 +231,18 @@ class ArrayRef
JL_GC_PUSH1(&arr_ptr);
const size_t pos = size();
jl_array_grow_end(arr_ptr, 1);
jl_arrayset(arr_ptr, box<ValueT>(val), pos);
data()[pos] = val;
JL_GC_POP();
}

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 7308b40

Please sign in to comment.