diff --git a/include/jlcxx/array.hpp b/include/jlcxx/array.hpp index 0891384..55c32e2 100644 --- a/include/jlcxx/array.hpp +++ b/include/jlcxx/array.hpp @@ -7,6 +7,16 @@ namespace jlcxx { +/// wrapper for julia jl_array_data for different julia versions +template +T* jlcxx_array_data(jl_array_t* arr) { +#if (JULIA_VERSION_MAJOR * 100 + JULIA_VERSION_MINOR) >= 111 + return jl_array_data(arr, T); +#else + return static_cast(jl_array_data(arr)); +#endif +} + template struct ValueExtractor { @@ -121,9 +131,8 @@ class Array void push_back(VT&& val) { JL_GC_PUSH1(&m_array); - const size_t pos = jl_array_len(m_array); - jl_array_grow_end(m_array, 1); - jl_arrayset(m_array, box(val), pos); + jl_value_t* jval = box(val); + jl_array_ptr_1d_push(m_array, jval); JL_GC_POP(); } @@ -165,7 +174,6 @@ template class ArrayRef { public: - using julia_t = typename detail::ArrayElementType::type; ArrayRef(jl_array_t* arr) : m_array(arr) @@ -191,22 +199,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 +225,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