diff --git a/include/jlcxx/array.hpp b/include/jlcxx/array.hpp index 0891384..3dbc118 100644 --- a/include/jlcxx/array.hpp +++ b/include/jlcxx/array.hpp @@ -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(val)); +#else jl_arrayset(m_array, box(val), pos); +#endif JL_GC_POP(); } @@ -165,9 +169,19 @@ template class ArrayRef { public: - using julia_t = typename detail::ArrayElementType::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(jl_array_data(arr)); +#endif + } + +public: ArrayRef(jl_array_t* arr) : m_array(arr) { assert(wrapped() != nullptr); @@ -191,22 +205,22 @@ class ArrayRef iterator begin() { - return iterator(static_cast(jl_array_data(wrapped()))); + return iterator(jlcxx_array_data(wrapped())); } const_iterator begin() const { - return const_iterator(static_cast(jl_array_data(wrapped()))); + return const_iterator(jlcxx_array_data(wrapped())); } iterator end() { - return iterator(static_cast(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(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) @@ -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(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