Skip to content

Commit

Permalink
Partial v0.6 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
barche committed Jan 27, 2017
1 parent 1a738b2 commit daf011d
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
10 changes: 5 additions & 5 deletions deps/src/cxx_wrap/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ class Array
public:
Array(const size_t n = 0)
{
jl_value_t* array_type = jl_apply_array_type(static_type_mapping<ValueT>::julia_type(), 1);
jl_value_t* array_type = apply_array_type(static_type_mapping<ValueT>::julia_type(), 1);
m_array = jl_alloc_array_1d(array_type, n);
}

Array(jl_datatype_t* applied_type, const size_t n = 0)
{
jl_value_t* array_type = jl_apply_array_type(applied_type, 1);
jl_value_t* array_type = apply_array_type(applied_type, 1);
m_array = jl_alloc_array_1d(array_type, n);
}

Expand Down Expand Up @@ -233,7 +233,7 @@ template<typename T, int Dim> struct IsValueType<ArrayRef<T,Dim>> : std::true_ty
template<typename T, int Dim> struct static_type_mapping<ArrayRef<T, Dim>>
{
typedef jl_array_t* type;
static jl_datatype_t* julia_type() { return (jl_datatype_t*)jl_apply_array_type(static_type_mapping<T>::julia_type(), Dim); }
static jl_datatype_t* julia_type() { return (jl_datatype_t*)apply_array_type(static_type_mapping<T>::julia_type(), Dim); }
};

template<typename ValueT, int Dim>
Expand Down Expand Up @@ -343,8 +343,8 @@ template<> struct static_type_mapping<JuliaMatrix>
jl_value_t* boxed_2 = jl_box_long(2);
jl_value_t* arr_t = nullptr;
JL_GC_PUSH2(&boxed_2, &arr_t);
arr_t = jl_apply_type((jl_value_t*)jl_array_type, jl_svec2(this_tvar, jl_box_long(2)));
jl_datatype_t* result = (jl_datatype_t*)jl_apply_type((jl_value_t*)jl_type_type,
arr_t = apply_type((jl_value_t*)jl_array_type, jl_svec2(this_tvar, jl_box_long(2)));
jl_datatype_t* result = (jl_datatype_t*)apply_type((jl_value_t*)jl_type_type,
jl_svec1(arr_t));
JL_GC_POP();
return result;
Expand Down
2 changes: 1 addition & 1 deletion deps/src/cxx_wrap/c_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ CXX_WRAP_EXPORT jl_array_t* get_module_functions(void* void_registry)
{
assert(void_registry != nullptr);
const ModuleRegistry& registry = *reinterpret_cast<ModuleRegistry*>(void_registry);
Array<jl_value_t*> module_array((jl_datatype_t*)jl_apply_array_type(g_cppfunctioninfo_type,1));
Array<jl_value_t*> module_array((jl_datatype_t*)apply_array_type(g_cppfunctioninfo_type,1));
JL_GC_PUSH1(module_array.gc_pointer());
registry.for_each_module([&](Module& module)
{
Expand Down
4 changes: 2 additions & 2 deletions deps/src/cxx_wrap/containers/const_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct InstantiateParametricType<ConstPtr<T>>
// Register the Julia type if not already instantiated
if(!static_type_mapping<ConstPtr<T>>::has_julia_type())
{
jl_datatype_t* dt = (jl_datatype_t*)jl_apply_type((jl_value_t*)julia_type("ConstPtr"), jl_svec1(static_type_mapping<T>::julia_type()));
jl_datatype_t* dt = (jl_datatype_t*)apply_type((jl_value_t*)julia_type("ConstPtr"), jl_svec1(static_type_mapping<T>::julia_type()));
set_julia_type<ConstPtr<T>>(dt);
protect_from_gc(dt);
}
Expand Down Expand Up @@ -143,7 +143,7 @@ struct InstantiateParametricType<ConstArray<T,N>>
jl_datatype_t* pdt = julia_type("ConstArray");
jl_value_t* boxed_n = box(N);
JL_GC_PUSH1(&boxed_n);
jl_datatype_t* app_dt = (jl_datatype_t*)jl_apply_type((jl_value_t*)pdt, jl_svec2(julia_type<T>(), boxed_n));
jl_datatype_t* app_dt = (jl_datatype_t*)apply_type((jl_value_t*)pdt, jl_svec2(julia_type<T>(), boxed_n));
protect_from_gc(app_dt);
set_julia_type<ConstArray<T,N>>(app_dt);
TypeWrapper<ConstArray<T,N>> wrapped(m, app_dt);
Expand Down
4 changes: 2 additions & 2 deletions deps/src/cxx_wrap/containers/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ struct static_type_mapping<NTuple<N,T>>
static jl_datatype_t* julia_type()
{
#if JULIA_VERSION_MAJOR == 0 && JULIA_VERSION_MINOR < 5
return (jl_datatype_t*)jl_apply_type((jl_value_t*)jl_ntuple_type, jl_svec2(static_type_mapping<N>::julia_type(), static_type_mapping<T>::julia_type()));
return (jl_datatype_t*)apply_type((jl_value_t*)jl_ntuple_type, jl_svec2(static_type_mapping<N>::julia_type(), static_type_mapping<T>::julia_type()));
#else
return (jl_datatype_t*)jl_apply_tuple_type(jl_svec1(jl_apply_type((jl_value_t*)jl_vararg_type, jl_svec2(static_type_mapping<T>::julia_type(), static_type_mapping<N>::julia_type()))));
return (jl_datatype_t*)jl_apply_tuple_type(jl_svec1(apply_type((jl_value_t*)jl_vararg_type, jl_svec2(static_type_mapping<T>::julia_type(), static_type_mapping<N>::julia_type()))));
#endif
}
};
Expand Down
6 changes: 5 additions & 1 deletion deps/src/cxx_wrap/cxx_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CXX_WRAP_EXPORT jl_array_t* gc_protected()
if (m_arr == nullptr)
{
#if JULIA_VERSION_MAJOR == 0 && JULIA_VERSION_MINOR > 4
jl_value_t* array_type = jl_apply_array_type(jl_any_type, 1);
jl_value_t* array_type = apply_array_type(jl_any_type, 1);
m_arr = jl_alloc_array_1d(array_type, 0);
#else
m_arr = jl_alloc_cell_1d(0);
Expand Down Expand Up @@ -63,7 +63,11 @@ CXX_WRAP_EXPORT jl_datatype_t* julia_type(const std::string& name, const std::st
}

jl_value_t* gval = jl_get_global(mod, jl_symbol(name.c_str()));
#if JULIA_VERSION_MAJOR == 0 && JULIA_VERSION_MINOR < 6
if(gval != nullptr && jl_is_datatype(gval))
#else
if(gval != nullptr && (jl_is_datatype(gval) || jl_is_unionall(gval)))
#endif
{
return (jl_datatype_t*)gval;
}
Expand Down
8 changes: 4 additions & 4 deletions deps/src/cxx_wrap/cxx_wrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ namespace detail
template<typename T>
void add_smart_pointer_types(jl_datatype_t* dt, Module& mod)
{
jl_datatype_t* sp_dt = (jl_datatype_t*)jl_apply_type(jl_get_global(get_cxxwrap_module(), jl_symbol("SharedPtr")), jl_svec1(static_type_mapping<T>::julia_type()));
jl_datatype_t* sp_dt = (jl_datatype_t*)apply_type(jl_get_global(get_cxxwrap_module(), jl_symbol("SharedPtr")), jl_svec1(static_type_mapping<T>::julia_type()));
set_julia_type<std::shared_ptr<T>>(sp_dt);
jl_datatype_t* up_dt = (jl_datatype_t*)jl_apply_type(jl_get_global(get_cxxwrap_module(), jl_symbol("UniquePtr")), jl_svec1(static_type_mapping<T>::julia_type()));
jl_datatype_t* up_dt = (jl_datatype_t*)apply_type(jl_get_global(get_cxxwrap_module(), jl_symbol("UniquePtr")), jl_svec1(static_type_mapping<T>::julia_type()));
set_julia_type<std::unique_ptr<T>>(up_dt);

mod.method("get", [](const std::shared_ptr<T>& ptr)
Expand Down Expand Up @@ -690,7 +690,7 @@ class TypeWrapper
{
static_assert(parameter_list<AppliedT>::nb_parameters != 0, "No parameters found when applying type. Specialize cxx_wrap::BuildParameterList for your combination of type and non-type parameters.");
static_assert(parameter_list<AppliedT>::nb_parameters >= parameter_list<T>::nb_parameters, "Parametric type applied to wrong number of parameters.");
jl_datatype_t* app_dt = (jl_datatype_t*)jl_apply_type((jl_value_t*)m_dt, parameter_list<AppliedT>()(parameter_list<T>::nb_parameters));
jl_datatype_t* app_dt = (jl_datatype_t*)apply_type((jl_value_t*)m_dt, parameter_list<AppliedT>()(parameter_list<T>::nb_parameters));

set_julia_type<AppliedT>(app_dt);
m_module.add_default_constructor<AppliedT>(DefaultConstructible<AppliedT>(), app_dt);
Expand Down Expand Up @@ -742,7 +742,7 @@ TypeWrapper<T> Module::add_type_internal(const std::string& name, jl_datatype_t*

if(is_parametric && jl_nparams(super) == jl_svec_len(parameters))
{
super = (jl_datatype_t*)jl_apply_type((jl_value_t*)super, parameters);
super = (jl_datatype_t*)apply_type((jl_value_t*)super, parameters);
}

// Create the datatype
Expand Down
39 changes: 30 additions & 9 deletions deps/src/cxx_wrap/type_conversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ inline std::string symbol_name(jl_sym_t* symbol)
#endif
}

/// Backwards-compatible apply_type
inline jl_value_t* apply_type(jl_value_t* tc, jl_svec_t* params)
{
#if JULIA_VERSION_MAJOR == 0 && JULIA_VERSION_MINOR < 6
return jl_apply_type(tc, params);
#else
return jl_apply_type(tc, jl_svec_data(params), jl_svec_len(params));
#endif
}

/// Backwards-compatible apply_array_type
template<typename T>
inline jl_value_t* apply_array_type(T* type, std::size_t dim)
{
#if JULIA_VERSION_MAJOR == 0 && JULIA_VERSION_MINOR < 6
return jl_apply_array_type((jl_datatype_t*)type, dim);
#else
return jl_apply_array_type((jl_value_t*)type, dim);
#endif
}

/// Check if we have a string
inline bool is_julia_string(jl_value_t* v)
{
Expand Down Expand Up @@ -368,7 +389,7 @@ template<typename T>
struct static_type_mapping<SingletonType<T>>
{
typedef jl_datatype_t* type;
static jl_datatype_t* julia_type() { return (jl_datatype_t*)jl_apply_type((jl_value_t*)jl_type_type, jl_svec1(static_type_mapping<T>::julia_type())); }
static jl_datatype_t* julia_type() { return (jl_datatype_t*)apply_type((jl_value_t*)jl_type_type, jl_svec1(static_type_mapping<T>::julia_type())); }
};


Expand Down Expand Up @@ -441,37 +462,37 @@ template<> struct static_type_mapping<float>
template<> struct static_type_mapping<int32_t*>
{
typedef jl_array_t* type;
static jl_datatype_t* julia_type() { return (jl_datatype_t*)jl_apply_array_type(jl_int32_type, 1); }
static jl_datatype_t* julia_type() { return (jl_datatype_t*)apply_array_type(jl_int32_type, 1); }
};

template<> struct static_type_mapping<int64_t*>
{
typedef jl_array_t* type;
static jl_datatype_t* julia_type() { return (jl_datatype_t*)jl_apply_array_type(jl_int64_type, 1); }
static jl_datatype_t* julia_type() { return (jl_datatype_t*)apply_array_type(jl_int64_type, 1); }
};

template<> struct static_type_mapping<char*>
{
typedef jl_array_t* type;
static jl_datatype_t* julia_type() { return (jl_datatype_t*)jl_apply_array_type(jl_uint8_type, 1); }
static jl_datatype_t* julia_type() { return (jl_datatype_t*)apply_array_type(jl_uint8_type, 1); }
};

template<> struct static_type_mapping<unsigned char*>
{
typedef jl_array_t* type;
static jl_datatype_t* julia_type() { return (jl_datatype_t*)jl_apply_array_type(jl_uint8_type, 1); }
static jl_datatype_t* julia_type() { return (jl_datatype_t*)apply_array_type(jl_uint8_type, 1); }
};

template<> struct static_type_mapping<float*>
{
typedef jl_array_t* type;
static jl_datatype_t* julia_type() { return (jl_datatype_t*)jl_apply_array_type(jl_float32_type, 1); }
static jl_datatype_t* julia_type() { return (jl_datatype_t*)apply_array_type(jl_float32_type, 1); }
};

template<> struct static_type_mapping<double*>
{
typedef jl_array_t* type;
static jl_datatype_t* julia_type() { return (jl_datatype_t*)jl_apply_array_type(jl_float64_type, 1); }
static jl_datatype_t* julia_type() { return (jl_datatype_t*)apply_array_type(jl_float64_type, 1); }
};

template<> struct static_type_mapping<short>
Expand Down Expand Up @@ -1231,7 +1252,7 @@ template<typename NumberT> struct IsBits<StrictlyTypedNumber<NumberT>> : std::tr
template<typename NumberT> struct static_type_mapping<StrictlyTypedNumber<NumberT>>
{
typedef NumberT type;
static jl_datatype_t* julia_type() { return (jl_datatype_t*)jl_apply_type((jl_value_t*)::cxx_wrap::julia_type("StrictlyTypedNumber"), jl_svec1(static_type_mapping<NumberT>::julia_type())); }
static jl_datatype_t* julia_type() { return (jl_datatype_t*)apply_type((jl_value_t*)::cxx_wrap::julia_type("StrictlyTypedNumber"), jl_svec1(static_type_mapping<NumberT>::julia_type())); }
};

template<typename NumberT>
Expand All @@ -1247,7 +1268,7 @@ struct ConvertToCpp<StrictlyTypedNumber<NumberT>, false, false, true>
template<typename T> struct static_type_mapping<T&, typename std::enable_if<IsFundamental<T>::value>::type>
{
typedef T* type;
static jl_datatype_t* julia_type() { return (jl_datatype_t*)jl_apply_type((jl_value_t*)::cxx_wrap::julia_type("Ref"), jl_svec1(static_type_mapping<T>::julia_type())); }
static jl_datatype_t* julia_type() { return (jl_datatype_t*)apply_type((jl_value_t*)::cxx_wrap::julia_type("Ref"), jl_svec1(static_type_mapping<T>::julia_type())); }
};

}
Expand Down

0 comments on commit daf011d

Please sign in to comment.