Skip to content

Commit

Permalink
Proper choice of ConstArray index type on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
barche committed Aug 20, 2016
1 parent 8bfc96b commit 249a6f5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
35 changes: 29 additions & 6 deletions deps/src/cxx_wrap/containers/const_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,36 @@
namespace cxx_wrap
{

namespace detail
{
template<std::size_t S>
struct IndexTChooser
{
};

template<>
struct IndexTChooser<4>
{
typedef int32_t type;
};

template<>
struct IndexTChooser<8>
{
typedef int64_t type;
};

}

typedef typename detail::IndexTChooser<sizeof(std::ptrdiff_t)>::type index_t;

namespace detail
{
// Helper to make a C++ tuple of longs based on the number of elements
template<long N, typename... TypesT>
template<index_t N, typename... TypesT>
struct LongNTuple
{
typedef typename LongNTuple<N-1, long, TypesT...>::type type;
typedef typename LongNTuple<N-1, index_t, TypesT...>::type type;
};

template<typename... TypesT>
Expand Down Expand Up @@ -51,7 +74,7 @@ struct InstantiateParametricType<ConstPtr<T>>

/// Wrap a pointer, providing the Julia array interface for it
/// The parameter N represents the number of dimensions
template<typename T, long N>
template<typename T, index_t N>
class ConstArray
{
public:
Expand Down Expand Up @@ -90,9 +113,9 @@ ConstArray<T, sizeof...(SizesT)> make_const_array(const T* p, const SizesT... si
return ConstArray<T, sizeof...(SizesT)>(p, sizes...);
}

template<typename T, long N> struct IsImmutable<ConstArray<T,N>> : std::true_type {};
template<typename T, index_t N> struct IsImmutable<ConstArray<T,N>> : std::true_type {};

template<typename T, long N>
template<typename T, index_t N>
struct ConvertToJulia<ConstArray<T,N>, false, true, false>
{
jl_value_t* operator()(const ConstArray<T,N>& arr)
Expand All @@ -109,7 +132,7 @@ struct ConvertToJulia<ConstArray<T,N>, false, true, false>
}
};

template<typename T, long N>
template<typename T, index_t N>
struct InstantiateParametricType<ConstArray<T,N>>
{
int operator()(Module& m) const
Expand Down
2 changes: 1 addition & 1 deletion deps/src/cxx_wrap/containers/containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct static_type_mapping<ConstPtr<TypeVar<I>>>
RegisterHook const_array_reg([]() {
Module m("CxxWrap");
g_constptr_dt = m.add_bits<ConstPtr<TypeVar<1>>>("ConstPtr").dt();
m.add_immutable<Parametric<TypeVar<1>, TypeVar<2>>>("ConstArray", FieldList<ConstPtr<TypeVar<1>>, NTuple<TypeVar<2>, long>>("ptr", "size"), julia_type("CppArray"));
m.add_immutable<Parametric<TypeVar<1>, TypeVar<2>>>("ConstArray", FieldList<ConstPtr<TypeVar<1>>, NTuple<TypeVar<2>, index_t>>("ptr", "size"), julia_type("CppArray"));
m.bind_types(g_cxx_wrap_module);
});

Expand Down

0 comments on commit 249a6f5

Please sign in to comment.