diff options
Diffstat (limited to 'src/bindings')
37 files changed, 1278 insertions, 384 deletions
diff --git a/src/bindings/cxx/eina_cxx/eina_log.hh b/src/bindings/cxx/eina_cxx/eina_log.hh index c287b7bd2d..d59af25e59 100644 --- a/src/bindings/cxx/eina_cxx/eina_log.hh +++ b/src/bindings/cxx/eina_cxx/eina_log.hh @@ -210,7 +210,7 @@ inline void _log(std::stringstream const& stream, int domain, ::Eina_Log_Level l for( bool run = ::eina_log_domain_level_check((DOMAIN), LEVEL); run;) \ for(std::stringstream stream; run ; \ ::efl::eina::_log(std::move(stream), (DOMAIN), LEVEL \ - , __FILE__, __FUNCTION__, __LINE__), run = false) \ + , __FILE__, __func__, __LINE__), run = false) \ stream /** diff --git a/src/bindings/cxx/eina_cxx/eina_ptrlist.hh b/src/bindings/cxx/eina_cxx/eina_ptrlist.hh index 2c2416c06e..f0ba2454f9 100644 --- a/src/bindings/cxx/eina_cxx/eina_ptrlist.hh +++ b/src/bindings/cxx/eina_cxx/eina_ptrlist.hh @@ -53,7 +53,7 @@ struct _ptr_list_iterator_base typedef std::ptrdiff_t difference_type; typedef std::bidirectional_iterator_tag iterator_category; - _ptr_list_iterator_base() : _list(0) {} + _ptr_list_iterator_base() : _list(nullptr), _node(nullptr) {} _ptr_list_iterator_base(Eina_List* list, Eina_List* node) : _list(list), _node(node) {} diff --git a/src/bindings/cxx/eina_cxx/eina_variant.hh b/src/bindings/cxx/eina_cxx/eina_variant.hh index a337f2e211..112549020f 100644 --- a/src/bindings/cxx/eina_cxx/eina_variant.hh +++ b/src/bindings/cxx/eina_cxx/eina_variant.hh @@ -24,9 +24,21 @@ #include <iosfwd> #include <eina_aligned_union.hh> +#include <eina_tuple.hh> namespace efl { namespace eina { +template <typename... Args> +struct variant; + +template <typename...Args> +struct variant_size : std::tuple_size<std::tuple<Args...>>::type +{ +}; + +template <typename V> +struct variant_as_tuple; + namespace _impl { template <typename T, typename U, typename...Others> @@ -51,7 +63,57 @@ template <typename T, typename U, typename...Args> struct find : find_impl<0u, T, U, Args...> {}; +template <std::size_t NT, std::size_t NV, typename TupleVariant, typename TypesFound> +struct visit_impl_meta_args +{ + typedef std::integral_constant<std::size_t, NT> current_type_index; + typedef std::integral_constant<std::size_t, NV> current_variant_index; + typedef TupleVariant variants; + // typedef typename std::tuple_element<NV, variants>::type current_variant; + // typedef typename variant_as_tuple<current_variant>::type current_variant_types; + // typedef typename std::tuple_element<NT, current_variant_types>::type current_type; + typedef TypesFound types_found; +}; + +template <typename T> struct current_variant_types +{ + typedef typename std::tuple_element<T::current_variant_index::value, typename T::variants>::type current_variant; + typedef typename variant_as_tuple<current_variant>::type type; +}; } + +// template <typename FoundTypes, std::size_t N, typename...Tuples> +// struct call_n_visitor; + +// template <typename FoundTypes, std::size_t N, typename Tuple, typename...Tuples> +// struct call_n_visitor<FoundTypes, N, Tuple, Tuples...> +// { + + /* + template <typename F> + static typename F::result_type call(int type, void* buffer, F f) + { + if(type == N) + { + using std::tuple_element; + typedef typename tuple_element<N, Tuple>::type type; + type* o = static_cast<type*>(buffer); + return f(*o); + } + else + return call_visitor<N+1, L, Tuple>::call(type, buffer, f); + } + */ + +// template <typename FoundTypes, std::size_t L, typename Tuple> +// struct call_n_visitor<FoundTypes, L, L, Tuple> +// { +// template <typename F, typename...Variants> +// static typename F::result_type call(int, void const*, F, Variants&&... variants) +// { +// std::abort(); +// } +// }; template <std::size_t N, std::size_t L, typename Tuple> struct call_visitor @@ -306,6 +368,11 @@ struct variant { return call_visitor<0u, sizeof...(Args), std::tuple<Args...>>::call(type, static_cast<void*>(&buffer), f); } + + constexpr std::size_t index() const + { + return type; + } private: template <typename T> @@ -332,6 +399,103 @@ private: * Member variable for holding the contained value. */ buffer_type buffer; + + template <typename V> + friend struct variant_as_tuple; + + // template <std::size_t NT, std::size_t NV, typename F, typename Tuple, typename Types, typename TupleVariant, std::size_t...I> + // friend typename F::result_type visit_impl2 + // (std::false_type, std::false_type + // , _impl::visit_impl_meta_args<NT, NV, Tuple, Types>, F&& f, TupleVariant&& variants, index_sequence<I...>); + + // template <std::size_t NT, std::size_t NV, typename F, typename Tuple, typename Types, typename TupleVariant, std::size_t...I> + // friend typename F::result_type visit_impl2 + // (std::true_type, std::false_type + // , _impl::visit_impl_meta_args<NT, NV, Tuple, Types>, F&& f, TupleVariant&& variants, index_sequence<I...>); + // template <std::size_t NT, std::size_t NV, typename F, typename Tuple, typename Types, typename TupleVariant, std::size_t...I> + // friend typename F::result_type visit_impl2 + // (std::false_type, std::true_type + // , _impl::visit_impl_meta_args<NT, NV, Tuple, Types>, F&& f, TupleVariant&& variants, index_sequence<I...>); + + // // template <std::size_t NT, std::size_t NV, typename F, typename Tuple, typename Types, typename TupleVariant> + // // friend typename F::result_type visit_impl2 + // // (std::true_type, std::false_type + // // , _impl::visit_impl_meta_args<NT, NV, Tuple, Types>, F&& f, TupleVariant&& variants) + // // { + // // } + + // // template <typename F, typename...AllVariants, typename...Variants> + // // friend typename F::result_type call + // // (std::true_type, int, F &&, Variants&&... variants) + // // { + // // std::abort(); + // // } + + // // template <typename F, typename Variant, typename...Variants> + // // friend typename F::result_type call (F&&f, Variant&& variant, Variants&&... variants) + // // { + // // return call (std::integral_constant<bool, (N == variant_size<Variant>::value)>{} + // // , variant.type, std::forward<F>(f), std::forward<Variant>(variant), std::forward<Variants>(variants)...); + // // } + + // // template <typename F, typename Variant, typename...Variants> + // // friend typename F::result_type call (F&&f, Variant&& variant, Variants&&... variants) + // // { + // // return call (std::integral_constant<bool, (N == variant_size<Variant>::value)>{} + // // , variant.type, std::forward<F>(f), std::forward<Variant>(variant), std::forward<Variants>(variants)...); + // // } + + // template <typename F, typename...Variants> + // friend typename F::result_type visit_impl (F&& f, Variants&&... variants); +}; + + +template <typename...VArgs> +struct variant_as_tuple<variant<VArgs...>> +{ + typedef std::tuple<VArgs...> type; +}; + +template <typename...VArgs> +struct variant_as_tuple<const variant<VArgs...>> +{ + typedef std::tuple<VArgs...> type; +}; + +template <typename...VArgs> +struct variant_as_tuple<volatile variant<VArgs...>> +{ + typedef std::tuple<VArgs...> type; +}; + +template <typename...VArgs> +struct variant_as_tuple<const volatile variant<VArgs...>> +{ + typedef std::tuple<VArgs...> type; +}; + +template <typename...VArgs> +struct variant_as_tuple<variant<VArgs...>&> +{ + typedef std::tuple<VArgs...> type; +}; + +template <typename...VArgs> +struct variant_as_tuple<const variant<VArgs...>&> +{ + typedef std::tuple<VArgs...> type; +}; + +template <typename...VArgs> +struct variant_as_tuple<volatile variant<VArgs...>&> +{ + typedef std::tuple<VArgs...> type; +}; + +template <typename...VArgs> +struct variant_as_tuple<const volatile variant<VArgs...>&> +{ + typedef std::tuple<VArgs...> type; }; template <typename...Args> @@ -372,7 +536,80 @@ T const& get(variant<Args...>const& variant, typename std::enable_if<_impl::is_o else throw std::logic_error(""); } - + +template <std::size_t NT, std::size_t NV, typename F, typename Tuple, typename Types, typename TupleVariant, std::size_t...I> + typename F::result_type visit_impl2 + (std::false_type, std::true_type + , _impl::visit_impl_meta_args<NT, NV, Tuple, Types>, F&& f, TupleVariant&& variants + , eina::index_sequence<I...>) + { + return f (eina::get<typename std::tuple_element<I, Types>::type>(std::get<I>(variants))...); + } + + template <std::size_t NT, std::size_t NV, typename F, typename Tuple, typename Types, typename TupleVariant, std::size_t...I> + typename F::result_type visit_impl2 + (std::true_type, std::false_type + , _impl::visit_impl_meta_args<NT, NV, Tuple, Types>, F&&, TupleVariant&&, eina::index_sequence<I...>) + { + std::abort(); + } + + + template <std::size_t NT, std::size_t NV, typename F, typename Tuple, typename Types, typename TupleVariant + , std::size_t...I> + typename F::result_type visit_impl2 (std::false_type, std::false_type + , _impl::visit_impl_meta_args<NT, NV, Tuple, Types>, F&& f, TupleVariant&& variants + , index_sequence<I...>) + { + using std::tuple_element; + typedef _impl::visit_impl_meta_args<NT, NV, Tuple, Types> meta_args; + if(std::get<NV>(variants).index() == NT) + { + typedef typename _impl::current_variant_types<meta_args>::type variant_types; + typedef typename tuple_element<NT, variant_types>::type type; + std::integral_constant<bool, (std::tuple_size<Tuple>::value == NV+1)> is_true {}; + return visit_impl2( std::false_type{} + , is_true + , _impl::visit_impl_meta_args<0u, NV+1, Tuple, typename _mpl::push_back<Types, type>::type>{} + , std::forward<F>(f), std::forward<TupleVariant>(variants) + , make_index_sequence<std::tuple_size<TupleVariant>::value>{}); + } + else + { + typedef typename _impl::current_variant_types<meta_args>::type variant_types; + return visit_impl2 (std::integral_constant<bool, (std::tuple_size<variant_types>::value == NT+1)>{} + , std::false_type{} + , _impl::visit_impl_meta_args<NT+1, NV, Tuple, Types>{}, std::forward<F>(f), std::forward<TupleVariant>(variants) + , make_index_sequence<std::tuple_size<TupleVariant>::value>{}); + } + } + + template <std::size_t NT, std::size_t NV, typename F, typename Tuple, typename Types, typename TupleVariant> + typename F::result_type visit_impl_aux (std::false_type fals, std::false_type + , _impl::visit_impl_meta_args<NT, NV, Tuple, Types> args, F&& f, TupleVariant&& variants) + { + return visit_impl2 (fals, fals, args, std::forward<F>(f), std::forward<TupleVariant>(variants) + , make_index_sequence<std::tuple_size<TupleVariant>::value>{}); + } + + template <typename F, typename...Variants> + typename F::result_type visit_impl (F&& f, Variants&&... variants) + { + return visit_impl_aux + (std::false_type{} + , std::false_type{} + , _impl::visit_impl_meta_args + <0u, 0u + , std::tuple<typename std::remove_cv<Variants>::type...>, std::tuple<>>{}, std::forward<F>(f), std::forward_as_tuple(std::forward<Variants>(variants)...)); + } + +template <typename F, typename...Variants> +auto visit (F&& function, Variants&& ... variants) -> typename F::result_type +{ + return visit_impl (std::forward<F>(function), std::forward<Variants>(variants)...); +} + } } #endif + diff --git a/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh b/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh index 633d377b0b..3f4521fe66 100644 --- a/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh +++ b/src/bindings/cxx/eo_cxx/eo_cxx_interop.hh @@ -53,6 +53,10 @@ template <> struct in_traits<efl::eina::strbuf> { typedef efl::eina::strbuf type; }; template <> struct in_traits<efl::eina::strbuf const> { typedef efl::eina::strbuf const type; }; +template <> +struct in_traits<efl::eina::strbuf_view> { typedef efl::eina::strbuf_view type; }; +template <> +struct in_traits<efl::eina::strbuf_view const> { typedef efl::eina::strbuf_view const type; }; template <typename T> struct in_traits<T&> { typedef T& type; }; template <typename T> @@ -550,10 +554,22 @@ inline const char* convert_to_c_impl(efl::eina::stringshare x, tag<const char*, { return eina_stringshare_ref(x.c_str()); } +inline Eina_Strbuf const* convert_to_c_impl(efl::eina::strbuf& x, tag<Eina_Strbuf const*, efl::eina::strbuf, false>) +{ + return x.native_handle(); +} inline Eina_Strbuf* convert_to_c_impl(efl::eina::strbuf& x, tag<Eina_Strbuf*, efl::eina::strbuf, false>) { return x.native_handle(); } +inline Eina_Strbuf const* convert_to_c_impl(efl::eina::strbuf_view const& x, tag<Eina_Strbuf const*, efl::eina::strbuf_view, false>) +{ + return x.native_handle(); +} +inline Eina_Strbuf* convert_to_c_impl(efl::eina::strbuf_view const& x, tag<Eina_Strbuf*, efl::eina::strbuf_view, false>) +{ + return const_cast<Eina_Strbuf*>(x.native_handle()); +} template <typename T, typename U, typename Deleter> T* convert_to_c_impl(std::unique_ptr<U, Deleter>& v, tag<T*, std::unique_ptr<U, Deleter>>) { @@ -732,6 +748,19 @@ T convert_to_return(U* value, tag<T, U*>, typename std::enable_if<is_range<T>::v // const should be to the type if value is const return T{const_cast<typename std::remove_const<U>::type*>(value)}; } +inline eina::strbuf convert_to_return(Eina_Strbuf* value, tag<Eina_Strbuf*, efl::eina::strbuf>) +{ + eina::strbuf_wrapper t{value}; + return t; +} +inline eina::strbuf_view convert_to_return(Eina_Strbuf* value, tag<Eina_Strbuf*, efl::eina::strbuf_view>) +{ + return {value}; +} +inline eina::strbuf_view convert_to_return(Eina_Strbuf const* value, tag<Eina_Strbuf const*, efl::eina::strbuf_view>) +{ + return {value}; +} inline eina::stringshare convert_to_return(const Eina_Stringshare* value, tag<const char*, efl::eina::stringshare>) { return efl::eina::stringshare(value); diff --git a/src/bindings/luajit/.gitignore b/src/bindings/lua/.gitignore index 31b688b99b..31b688b99b 100644 --- a/src/bindings/luajit/.gitignore +++ b/src/bindings/lua/.gitignore diff --git a/src/bindings/luajit/eina/accessor.lua b/src/bindings/lua/eina/accessor.lua index 55afa62427..d2068fc8b5 100644 --- a/src/bindings/luajit/eina/accessor.lua +++ b/src/bindings/lua/eina/accessor.lua @@ -46,12 +46,12 @@ ffi.metatype("Eina_Accessor", { unlock = function(self) return eina.eina_accessor_unlock(self) ~= 0 end, clone = function(self) local v = eina.eina_accessor_clone(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, container_get = function(self) local v = eina.eina_accessor_container_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end } @@ -64,7 +64,7 @@ local dgetmt = debug.getmetatable M.Accessor = util.Readonly_Object:clone { __ctor = function(self, selfmt, acc) -- prevent null stuff - if acc == nil then acc = nil end + if acc == ffi.nullptr then acc = nil end if acc then ffi.gc(acc, acc.free) end selfmt.__eq = function(self, other) return selfmt.__accessor == dgetmt(other).__accessor diff --git a/src/bindings/luajit/eina/counter.lua b/src/bindings/lua/eina/counter.lua index b0b9829ad4..6a9ba33284 100644 --- a/src/bindings/luajit/eina/counter.lua +++ b/src/bindings/lua/eina/counter.lua @@ -51,7 +51,7 @@ M.Counter = ffi.metatype("Eina_Counter", { dump = function(self) local v = eina.eina_counter_dump(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end local r = ffi.string(v) C.free(v) return r diff --git a/src/bindings/luajit/eina/file.lua b/src/bindings/lua/eina/file.lua index 675b810a17..f9fcf2350c 100644 --- a/src/bindings/luajit/eina/file.lua +++ b/src/bindings/lua/eina/file.lua @@ -4,6 +4,8 @@ local ffi = require("ffi") local C = ffi.C +local tonum = ffi.tonumber or tonumber + local iterator = require("eina.iterator") require("eina.xattr") @@ -210,8 +212,8 @@ local direct_info_iterator_next = function(self) if not v then return nil end local s = ffi.cast("Eina_File_Direct_Info*", v) local path = ffi.string(s.path, s.path_length) - local ns = tonumber(s.name_start) - local nl = tonumber(s.name_length) + local ns = tonum(s.name_start) + local nl = tonum(s.name_length) local tp = file_type_map[s.type] return Direct_Info(path, ns, nl, tp), self:container_get() end @@ -236,7 +238,7 @@ M.direct_ls = function(dir) return Direct_Ls_Iterator(dir) end M.path_sanitize = function(path) local v = eina.eina_file_path_sanitize(path) - if v == nil then return nil end + if v == ffi.nullptr then return nil end local r = ffi.string(v) C.free(v) return r @@ -301,7 +303,7 @@ local Line_Iterator = Iterator:clone { local v = Iterator.next(self) if not v then return nil end v = ffi.cast(v, "Eina_File_Line*") - return ffi.string(v.start, v.length), tonumber(v.index) + return ffi.string(v.start, v.length), tonum(v.index) end } @@ -342,11 +344,11 @@ M.File = ffi.metatype("Eina_File", { end, size_get = function(self) - return tonumber(eina.eina_file_size_get(self)) + return tonum(eina.eina_file_size_get(self)) end, mtime_get = function(self) - return tonumber(eina.eina_file_mtime_get(self)) + return tonum(eina.eina_file_mtime_get(self)) end, filename_get = function(self) @@ -358,7 +360,7 @@ M.File = ffi.metatype("Eina_File", { map_all = function(self, rule, raw) local v = ffi.cast("char*", eina.eina_file_map_all(self, rule or 0)) - if v == nil then return nil end + if v == ffi.nullptr then return nil end if not raw then local r = ffi.string(v) self:map_free(v) @@ -370,7 +372,7 @@ M.File = ffi.metatype("Eina_File", { map_new = function(self, rule, offset, length, raw) local v = ffi.cast("char*", eina.eina_file_map_new(self, rule or 0, offset or 0, length)) - if v == nil then return nil end + if v == ffi.nullptr then return nil end if not raw then local r = ffi.string(v, length) self:map_free(v) diff --git a/src/bindings/luajit/eina/hamster.lua b/src/bindings/lua/eina/hamster.lua index e8f5e7434f..2e93086e82 100644 --- a/src/bindings/luajit/eina/hamster.lua +++ b/src/bindings/lua/eina/hamster.lua @@ -3,6 +3,8 @@ local ffi = require("ffi") +local tonum = ffi.tonumber or tonumber + ffi.cdef [[ int eina_hamster_count(void); ]] @@ -25,7 +27,7 @@ end cutil.init_module(init, shutdown) M.count = function() - return tonumber(eina.eina_hamster_count()) + return tonum(eina.eina_hamster_count()) end return M diff --git a/src/bindings/luajit/eina/iterator.lua b/src/bindings/lua/eina/iterator.lua index dc5d0da8b2..196a968500 100644 --- a/src/bindings/luajit/eina/iterator.lua +++ b/src/bindings/lua/eina/iterator.lua @@ -43,7 +43,7 @@ ffi.metatype("Eina_Iterator", { unlock = function(self) return eina.eina_iterator_unlock(self) ~= 0 end, container_get = function(self) local v = eina.eina_iterator_container_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end } @@ -56,7 +56,7 @@ local dgetmt = debug.getmetatable M.Iterator = util.Readonly_Object:clone { __ctor = function(self, selfmt, iter) -- prevent null stuff - if iter == nil then iter = nil end + if iter == ffi.nullptr then iter = nil end if iter then ffi.gc(iter, iter.free) end selfmt.__eq = function(self, other) return selfmt.__iterator == dgetmt(other).__iterator diff --git a/src/bindings/luajit/eina/list.lua b/src/bindings/lua/eina/list.lua index aebfa348c1..4c0bc6bd17 100644 --- a/src/bindings/luajit/eina/list.lua +++ b/src/bindings/lua/eina/list.lua @@ -83,7 +83,9 @@ local dgetmt = debug.getmetatable local List_Iterator = Iterator:clone { __ctor = function(self, selfmt, list) - if list == nil then return Iterator.__ctor(self, selfmt, nil) end + if not list or list == ffi.nullptr then + return Iterator.__ctor(self, selfmt, nil) + end selfmt.__list = list return Iterator.__ctor(self, selfmt, eina.eina_list_iterator_new(dgetmt(list).__list)) @@ -98,7 +100,9 @@ local List_Iterator = Iterator:clone { local List_Reverse_Iterator = Iterator:clone { __ctor = function(self, selfmt, list) - if list == nil then return Iterator.__ctor(self, selfmt, nil) end + if not list or list == ffi.nullptr then + return Iterator.__ctor(self, selfmt, nil) + end selfmt.__list = list return Iterator.__ctor(self, selfmt, eina.eina_list_iterator_reversed_new(dgetmt(list).__list)) @@ -115,7 +119,9 @@ local Accessor = accessor.Accessor local List_Accessor = Accessor:clone { __ctor = function(self, selfmt, list) - if list == nil then return Accessor.__ctor(self, selfmt, nil) end + if not list or list == ffi.nullptr then + return Accessor.__ctor(self, selfmt, nil) + end selfmt.__list = list return Accessor.__ctor(self, selfmt, eina.eina_list_accessor_new(dgetmt(list).__list)) @@ -141,37 +147,37 @@ local List = ffi.metatype("Eina_List", { data_get = function(self, ptr) if ptr ~= nil then return ptr end local v = get_list_t(self).data - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, nth = function(self, n) local v = eina.eina_list_nth(self, n - 1) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return self:data_get(v) end, nth_list = function(self, n) local v = eina.eina_list_nth_list(self, n - 1) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, last = function(self) local v = get_list_t(self).accounting.last - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, next = function(self) local v = get_list_t(self).next - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, prev = function(self) local v = get_list_t(self).prev - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end } @@ -183,7 +189,7 @@ local List_Base = util.Readonly_Object:clone { list = ffi.gc(list, freefunc) selfmt.__free = freefunc end - if list == nil then return end + if not list or list == ffi.nullptr then return end selfmt.__eq = function(self, other) return selfmt.__list == dgetmt(other).__list end @@ -194,62 +200,62 @@ local List_Base = util.Readonly_Object:clone { free = function(self) self = dgetmt(self) local ffunc, l = self.__free, self.__list - if not ffunc or l == nil then return end + if not ffunc or not l or l == ffi.nullptr then return end ffunc(ffi.gc(self.__list, nil)) end, count = function(self) self = dgetmt(self) local l = self.__list - if l == nil then return 0 end + if not l or l == ffi.nullptr then return 0 end return #l end, nth = function(self, n) self = dgetmt(self) local l = self.__list - if l == nil then return nil end + if not l or l == ffi.nullptr then return nil end return l:nth() end, nth_list = function(self, n) self = dgetmt(self) local l = self.__list - if l == nil then return nil end + if not l or l == ffi.nullptr then return nil end return self.__index(l:nth_list()) end, last = function(self, n) self = dgetmt(self) local l = self.__list - if l == nil then return nil end + if not l or l == ffi.nullptr then return nil end return self.__index(l:last()) end, next = function(self, n) self = dgetmt(self) local l = self.__list - if l == nil then return nil end + if not l or l == ffi.nullptr then return nil end return self.__index(l:next()) end, prev = function(self, n) self = dgetmt(self) local l = self.__list - if l == nil then return nil end + if not l or l == ffi.nullptr then return nil end return self.__index(l:prev()) end, data_get = function(self, ptr) self = dgetmt(self) local l = self.__list - if l == nil then return nil end + if not l or l == ffi.nullptr then return nil end return l:data_get(ptr) end, to_array = function(self) local l = dgetmt(self).__list - if l == nil then return {}, 0 end + if not l or l == ffi.nullptr then return {}, 0 end local n = 0 local r = {} while l ~= nil do @@ -293,7 +299,7 @@ M.Ptr_List = List_Base:clone { M.String_List = List_Base:clone { data_get = function(self, ptr) ptr = List_Base.data_get(self, ptr) - if ptr == nil then return nil end + if not ptr or ptr == ffi.nullptr then return nil end return ffi.string(ptr) end } diff --git a/src/bindings/luajit/eina/log.lua b/src/bindings/lua/eina/log.lua index d2b1180b96..d2b1180b96 100644 --- a/src/bindings/luajit/eina/log.lua +++ b/src/bindings/lua/eina/log.lua diff --git a/src/bindings/luajit/eina/rectangle.lua b/src/bindings/lua/eina/rectangle.lua index d9988b7f2b..d9988b7f2b 100644 --- a/src/bindings/luajit/eina/rectangle.lua +++ b/src/bindings/lua/eina/rectangle.lua diff --git a/src/bindings/luajit/eina/tiler.lua b/src/bindings/lua/eina/tiler.lua index 15f4a10771..15f4a10771 100644 --- a/src/bindings/luajit/eina/tiler.lua +++ b/src/bindings/lua/eina/tiler.lua diff --git a/src/bindings/luajit/eina/xattr.lua b/src/bindings/lua/eina/xattr.lua index 192d39b85f..bac2d85bd8 100644 --- a/src/bindings/luajit/eina/xattr.lua +++ b/src/bindings/lua/eina/xattr.lua @@ -4,6 +4,8 @@ local ffi = require("ffi") local C = ffi.C +local tonum = ffi.tonumber or tonumber + local iterator = require("eina.iterator") ffi.cdef [[ @@ -98,7 +100,7 @@ end M.get = function(file, attribute) local size = ffi.new("size_t[1]") local v = eina.eina_xattr_get(file, attribute, size) - if v == nil then return nil end + if v == ffi.nullptr then return nil end local r = ffi.string(v, size[0]) C.free(v) return r @@ -126,7 +128,7 @@ end M.string_get = function(file, attribute) local v = eina.eina_xattr_string_get(file, attribute) - if v == nil then return nil end + if v == ffi.nullptr then return nil end local r = ffi.string(v) C.free(v) return r @@ -140,7 +142,7 @@ M.double_get = function(file, attribute) local v = ffi.new("double[1]") local r = eina.eina_xattr_double_get(file, attribute, v) if r == 0 then return false end - return true, tonumber(v[0]) + return true, tonum(v[0]) end M.int_set = function(file, attribute, value, flags) @@ -151,7 +153,7 @@ M.int_get = function(file, attribute) local v = ffi.new("int[1]") local r = eina.eina_xattr_int_get(file, attribute, v) if r == 0 then return false end - return true, tonumber(v[0]) + return true, tonum(v[0]) end return M diff --git a/src/bindings/luajit/eo.lua b/src/bindings/lua/eo.lua index bebe733853..ff19afc595 100644 --- a/src/bindings/luajit/eo.lua +++ b/src/bindings/lua/eo.lua @@ -109,11 +109,13 @@ ffi.cdef [[ extern const Eo_Event_Description _EO_BASE_EVENT_DEL; ]] +local tonum = ffi.tonumber or tonumber + local addr_d = ffi.typeof("union { double d; const Eo *p; }") local eo_obj_addr_get = function(x) local v = addr_d() v.p = x - return tonumber(v.d) + return tonum(v.d) end local cutil = require("cutil") @@ -143,7 +145,7 @@ local eo_event_cb_fun = function(data, obj, desc, einfo) local addr = eo_obj_addr_get(obj) local cbs = eo_callbacks[addr] assert(cbs) - local cidx = tonumber(ffi.cast("intptr_t", data)) + local cidx = tonum(ffi.cast("intptr_t", data)) local fun = cbs[cidx] assert(fun) return fun() ~= false @@ -337,7 +339,7 @@ end local get_obj_mt = function(obj) local cl = eo.eo_class_get(obj) - if cl == nil then return nil end + if cl == ffi.nullptr then return nil end return classes[eo_obj_addr_get(cl)] end @@ -416,7 +418,7 @@ ffi.metatype("Eo", { -- handles property getting with no keys and also properties with keys __index = function(self, key) local mt = get_obj_mt(self) - if mt == nil then return nil end + if not mt then return nil end local pt = mt.__properties local pp = pt[key] if not pp then @@ -444,7 +446,7 @@ ffi.metatype("Eo", { -- handles property setting with no keys __newindex = function(self, key, val) local mt = get_obj_mt(self) - if mt == nil then return nil end + if not mt then return nil end local pt = mt.__properties local pp = pt[key] if not pp then diff --git a/src/bindings/luajit/eolian.lua b/src/bindings/lua/eolian.lua index 93499df6a5..687d824243 100644 --- a/src/bindings/luajit/eolian.lua +++ b/src/bindings/lua/eolian.lua @@ -2,7 +2,6 @@ -- For use with Elua local ffi = require("ffi") -local bit = require("bit") ffi.cdef [[ void eina_stringshare_del(const char *str); @@ -275,9 +274,13 @@ ffi.cdef [[ typedef struct _Eolian_Doc_Token { Eolian_Doc_Token_Type type; - const char *text, *text_end; + const char *text; + const char *text_end; } Eolian_Doc_Token; + void *malloc(size_t sz); + void free(void *ptr); + int eolian_init(void); int eolian_shutdown(void); unsigned short eolian_file_format_version_get(void); @@ -443,7 +446,7 @@ ffi.cdef [[ const Eolian_Function *eolian_typedecl_function_pointer_get(const Eolian_Typedecl *tp); - Eolian_Value_t eolian_expression_eval(const Eolian_Expression *expr, Eolian_Expression_Mask m); + Eina_Bool eolian_expression_eval_fill(const Eolian_Expression *expr, Eolian_Expression_Mask m, Eolian_Value_t *val); const char *eolian_expression_value_to_literal(const Eolian_Value *v); const char *eolian_expression_serialize(const Eolian_Expression *expr); Eolian_Expression_Type eolian_expression_type_get(const Eolian_Expression *expr); @@ -452,7 +455,7 @@ ffi.cdef [[ const Eolian_Expression *eolian_expression_binary_rhs_get(const Eolian_Expression *expr); Eolian_Unary_Operator eolian_expression_unary_operator_get(const Eolian_Expression *expr); const Eolian_Expression *eolian_expression_unary_expression_get(const Eolian_Expression *expr); - Eolian_Value_t eolian_expression_value_get(const Eolian_Expression *expr); + Eina_Bool eolian_expression_value_get_fill(const Eolian_Expression *expr, Eolian_Value_t *val); const Eolian_Documentation *eolian_constant_documentation_get(const Eolian_Constant *var); const Eolian_Type *eolian_constant_type_get(const Eolian_Constant *var); const Eolian_Expression *eolian_constant_value_get(const Eolian_Constant *var); @@ -475,6 +478,8 @@ ffi.cdef [[ local cutil = require("cutil") local util = require("util") +local tonum = ffi.tonumber or tonumber + local iterator = require("eina.iterator") local Ptr_Iterator = iterator.Ptr_Iterator @@ -551,28 +556,28 @@ local object_idx, wrap_object = gen_wrap { end, type_get = function(self) - return tonumber(eolian.eolian_object_type_get(cast_obj(self))) + return tonum(eolian.eolian_object_type_get(cast_obj(self))) end, unit_get = function(self) local v = eolian.eolian_object_unit_get(cast_obj(self)) - if v == nil then + if v == ffi.nullptr then return nil end return v end, line_get = function(self) - return tonumber(eolian.eolian_object_line_get(cast_obj(self))) + return tonum(eolian.eolian_object_line_get(cast_obj(self))) end, column_get = function(self) - return tonumber(eolian.eolian_object_column_get(cast_obj(self))) + return tonum(eolian.eolian_object_column_get(cast_obj(self))) end, file_get = function(self) local v = eolian.eolian_object_file_get(cast_obj(self)) - if v == nil then + if v == ffi.nullptr then return nil end return ffi.string(v) @@ -580,7 +585,7 @@ local object_idx, wrap_object = gen_wrap { name_get = function(self) local v = eolian.eolian_object_name_get(cast_obj(self)) - if v == nil then + if v == ffi.nullptr then return nil end return ffi.string(v) @@ -588,7 +593,7 @@ local object_idx, wrap_object = gen_wrap { c_name_get = function(self) local v = eolian.eolian_object_c_name_get(cast_obj(self)) - if v == nil then + if v == ffi.nullptr then return nil end return ffi.string(v) @@ -596,7 +601,7 @@ local object_idx, wrap_object = gen_wrap { short_name_get = function(self) local v = eolian.eolian_object_short_name_get(cast_obj(self)) - if v == nil then + if v == ffi.nullptr then return nil end return ffi.string(v) @@ -617,7 +622,7 @@ ffi.metatype("Eolian_Object", { __index = object_idx }) local unit_idx, wrap_unit = gen_wrap { state_get = function(self) local v = eolian.eolian_unit_state_get(cast_unit(self)) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -628,23 +633,23 @@ local unit_idx, wrap_unit = gen_wrap { file_get = function(self) local v = eolian.eolian_unit_file_get(cast_unit(self)) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi.string(v) end, file_path_get = function(self) local v = eolian.eolian_unit_file_path_get(cast_unit(self)) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi.string(v) end, version_get = function(self) - return tonumber(eolian.eolian_unit_version_get(cast_unit(self))) + return tonum(eolian.eolian_unit_version_get(cast_unit(self))) end, object_by_name_get = function(self, name) local v = eolian.eolian_unit_object_by_name_get(cast_unit(self), name) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -655,7 +660,7 @@ local unit_idx, wrap_unit = gen_wrap { class_by_name_get = function(self, cname) local v = eolian.eolian_unit_class_by_name_get(cast_unit(self), cname) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -666,13 +671,13 @@ local unit_idx, wrap_unit = gen_wrap { constant_by_name_get = function(self, name) local v = eolian.eolian_unit_constant_by_name_get(cast_unit(self), name) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, error_by_name_get = function(self, name) local v = eolian.eolian_unit_error_by_name_get(cast_unit(self), name) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -688,19 +693,19 @@ local unit_idx, wrap_unit = gen_wrap { alias_by_name_get = function(self, name) local v = eolian.eolian_unit_alias_by_name_get(cast_unit(self), name) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, struct_by_name_get = function(self, name) local v = eolian.eolian_unit_struct_by_name_get(cast_unit(self), name) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, enum_by_name_get = function(self, name) local v = eolian.eolian_unit_enum_by_name_get(cast_unit(self), name) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -726,7 +731,7 @@ local panic_cbs = {} local error_cbs = {} local obj_to_idx = function(obj) - return tonumber(ffi.cast("size_t", obj)) + return tonum(ffi.cast("size_t", obj)) end local panic_cb, err_cb @@ -769,7 +774,7 @@ ffi.metatype("Eolian_State", { file_parse = function(self, fname) local v = eolian.eolian_state_file_parse(self, fname) - if v == nil then + if v == ffi.nullptr then return nil end return v @@ -777,7 +782,7 @@ ffi.metatype("Eolian_State", { file_path_parse = function(self, fpath) local v = eolian.eolian_state_file_path_parse(self, fpath) - if v == nil then + if v == ffi.nullptr then return nil end return v @@ -817,7 +822,7 @@ ffi.metatype("Eolian_State", { unit_by_file_get = function(self, fname) local v = eolian.eolian_state_unit_by_file_get(state, fname) - if v == nil then + if v == ffi.nullptr then return nil end return v @@ -835,7 +840,7 @@ ffi.metatype("Eolian_State", { class_by_file_get = function(self, fname) local v = eolian.eolian_state_class_by_file_get(self, fname) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -961,13 +966,13 @@ ffi.metatype("Eolian_Struct_Type_Field", { __index = wrap_object { documentation_get = function(self) local v = eolian.eolian_typedecl_struct_field_documentation_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, type_get = function(self) local v = eolian.eolian_typedecl_struct_field_type_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -985,19 +990,19 @@ ffi.metatype("Eolian_Enum_Type_Field", { __index = wrap_object { c_name_get = function(self) local v = eolian.eolian_typedecl_enum_field_c_constant_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi_stringshare(v) end, documentation_get = function(self) local v = eolian.eolian_typedecl_enum_field_documentation_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, value_get = function(self, force) local v = eolian.eolian_typedecl_enum_field_value_get(self, force and 1 or 0) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end } @@ -1006,7 +1011,7 @@ ffi.metatype("Eolian_Enum_Type_Field", { M.Typedecl = ffi.metatype("Eolian_Typedecl", { __index = wrap_object { type_get = function(self) - return tonumber(eolian.eolian_typedecl_type_get(self)) + return tonum(eolian.eolian_typedecl_type_get(self)) end, struct_fields_get = function(self) @@ -1016,7 +1021,7 @@ M.Typedecl = ffi.metatype("Eolian_Typedecl", { struct_field_get = function(self, name) local v = eolian.eolian_typedecl_struct_field_get(self, name) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1027,31 +1032,31 @@ M.Typedecl = ffi.metatype("Eolian_Typedecl", { enum_field_get = function(self, field) local v = eolian.eolian_typedecl_enum_field_get(self, field) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, enum_legacy_prefix_get = function(self) local v = eolian.eolian_typedecl_enum_legacy_prefix_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi.string(v) end, documentation_get = function(self, name) local v = eolian.eolian_typedecl_documentation_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, base_type_get = function(self) local v = eolian.eolian_typedecl_base_type_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, aliased_base_get = function(self) local v = eolian.eolian_typedecl_aliased_byse_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1061,19 +1066,19 @@ M.Typedecl = ffi.metatype("Eolian_Typedecl", { c_type_get = function(self) local v = eolian.eolian_typedecl_c_type_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi_stringshare(v) end, free_func_get = function(self) local v = eolian.eolian_typedecl_free_func_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi.string(v) end, function_pointer_get = function(self) local v = eolian.eolian_typedecl_function_pointer_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end } @@ -1082,46 +1087,46 @@ M.Typedecl = ffi.metatype("Eolian_Typedecl", { M.Type = ffi.metatype("Eolian_Type", { __index = wrap_object { type_get = function(self) - return tonumber(eolian.eolian_type_type_get(self)) + return tonum(eolian.eolian_type_type_get(self)) end, builtin_type_get = function(self) - return tonumber(eolian.eolian_type_builtin_type_get(self)) + return tonum(eolian.eolian_type_builtin_type_get(self)) end, base_type_get = function(self) local v = eolian.eolian_type_base_type_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, next_type_get = function(self) local v = eolian.eolian_type_next_type_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, typedecl_get = function(self) local v = eolian.eolian_type_typedecl_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, aliased_base_get = function(self) local v = eolian.eolian_type_aliased_byse_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, class_get = function(self) local v = eolian.eolian_type_class_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, error_get = function(self) local v = eolian.eolian_type_error_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1139,7 +1144,7 @@ M.Type = ffi.metatype("Eolian_Type", { c_type_get = function(self) local v = eolian.eolian_type_c_type_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi_stringshare(v) end } @@ -1157,22 +1162,22 @@ M.function_type = { M.Function = ffi.metatype("Eolian_Function", { __index = wrap_object { type_get = function(self) - return tonumber(eolian.eolian_function_type_get(self)) + return tonum(eolian.eolian_function_type_get(self)) end, scope_get = function(self, ftype) - return tonumber(eolian.eolian_function_scope_get(self, ftype)) + return tonum(eolian.eolian_function_scope_get(self, ftype)) end, full_c_name_get = function(self, ftype) local v = eolian.eolian_function_full_c_name_get(self, ftype) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi_stringshare(v) end, implement_get = function(self) local v = eolian.eolian_function_implement_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1205,19 +1210,19 @@ M.Function = ffi.metatype("Eolian_Function", { return_type_get = function(self, ftype) local v = eolian.eolian_function_return_type_get(self, ftype) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, return_default_value_get = function(self, ftype) local v = eolian.eolian_function_return_default_value_get(self, ftype) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, return_documentation_get = function(self, ftype) local v = eolian.eolian_function_return_documentation_get(self, ftype) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1240,7 +1245,7 @@ M.Function = ffi.metatype("Eolian_Function", { class_get = function(self) local v = eolian.eolian_function_class_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end } @@ -1256,24 +1261,24 @@ M.parameter_dir = { ffi.metatype("Eolian_Function_Parameter", { __index = wrap_object { direction_get = function(self) - return tonumber(eolian.eolian_parameter_direction_get(self)) + return tonum(eolian.eolian_parameter_direction_get(self)) end, type_get = function(self) local v = eolian.eolian_parameter_type_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, default_value_get = function(self) local v = eolian.eolian_parameter_default_value_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, documentation_get = function(self) local v = eolian.eolian_parameter_documentation_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1295,26 +1300,26 @@ ffi.metatype("Eolian_Implement", { __index = wrap_object { class_get = function(self) local v = eolian.eolian_implement_class_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, implementing_class_get = function(self) local v = eolian.eolian_implement_implementing_class_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, function_get = function(self) local tp = ffi.new("Eolian_Function_Type[1]") local v = eolian.eolian_implement_function_get(self, tp) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v, tp[0] end, documentation_get = function(self, ftype) local v = eolian.eolian_implement_documentation_get(self, ftype) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1344,13 +1349,13 @@ ffi.metatype("Eolian_Constructor", { __index = wrap_object { class_get = function(self) local v = eolian.eolian_constructor_class_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, function_get = function(self) local v = eolian.eolian_constructor_function_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1364,29 +1369,29 @@ ffi.metatype("Eolian_Event", { __index = wrap_object { type_get = function(self) local v = eolian.eolian_event_type_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, class_get = function(self) local v = eolian.eolian_event_class_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, documentation_get = function(self) local v = eolian.eolian_event_documentation_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, scope_get = function(self) - return tonumber(eolian.eolian_event_scope_get(self)) + return tonum(eolian.eolian_event_scope_get(self)) end, c_macro_get = function(self) local v = eolian.eolian_event_c_macro_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi_stringshare(v) end, @@ -1404,13 +1409,13 @@ ffi.metatype("Eolian_Part", { __index = wrap_object { class_get = function(self) local v = eolian.eolian_part_class_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, documentation_get = function(self) local v = eolian.eolian_part_documentation_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end } @@ -1427,18 +1432,18 @@ M.class_type = { M.Class = ffi.metatype("Eolian_Class", { __index = wrap_object { type_get = function(self) - return tonumber(eolian.eolian_class_type_get(self)) + return tonum(eolian.eolian_class_type_get(self)) end, documentation_get = function(self) local v = eolian.eolian_class_documentation_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, c_prefix_get = function(self) local v = eolian.eolian_class_c_prefix_get(self) - if v == nil then + if v == ffi.nullptr then local buf = self:namespaces_get() buf[#buf + 1] = self:short_name_get() return table.concat(buf, "_"):lower() @@ -1448,7 +1453,7 @@ M.Class = ffi.metatype("Eolian_Class", { event_c_prefix_get = function(self) local v = eolian.eolian_class_event_c_prefix_get(self) - if v == nil then + if v == ffi.nullptr then return self:c_prefix_get() end return ffi.string(v) @@ -1456,13 +1461,13 @@ M.Class = ffi.metatype("Eolian_Class", { data_type_get = function(self) local v = eolian.eolian_class_data_type_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi.string(v) end, parent_get = function(self) local v = eolian.eolian_class_parent_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1484,7 +1489,7 @@ M.Class = ffi.metatype("Eolian_Class", { function_by_name_get = function(self, fname, ftype) local v = eolian.eolian_class_function_by_name_get(self, fname, ftype) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1505,7 +1510,7 @@ M.Class = ffi.metatype("Eolian_Class", { event_by_name_get = function(self, name) local v = eolian.eolian_class_event_by_name_get(self, name) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1524,19 +1529,19 @@ M.Class = ffi.metatype("Eolian_Class", { c_get_function_name_get = function(self) local v = eolian.eolian_class_c_get_function_name_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi_stringshare(v) end, c_macro_get = function(self) local v = eolian.eolian_class_c_macro_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi_stringshare(v) end, c_data_type_get = function(self) local v = eolian.eolian_class_c_data_type_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi_stringshare(v) end } @@ -1564,32 +1569,31 @@ M.expression_type = { local etype = M.expression_type M.expression_mask = { - SINT = bit.lshift(1, 0), - UINT = bit.lshift(1, 1), - FLOAT = bit.lshift(1, 2), - BOOL = bit.lshift(1, 3), - STRING = bit.lshift(1, 4), - CHAR = bit.lshift(1, 5), - NULL = bit.lshift(1, 6) + SINT = 2 ^ 0, + UINT = 2 ^ 1, + FLOAT = 2 ^ 2, + BOOL = 2 ^ 3, + STRING = 2 ^ 4, + CHAR = 2 ^ 5, + NULL = 2 ^ 6 } local emask = M.expression_mask -emask.INT = bit.bor(emask.SINT , emask.UINT ) -emask.SIGNED = bit.bor(emask.SINT , emask.FLOAT) -emask.NUMBER = bit.bor(emask.INT , emask.FLOAT) -emask.ALL = bit.bor(emask.NUMBER, emask.BOOL, - emask.STRING, emask.CHAR, emask.NULL) +emask.INT = emask.SINT + emask.UINT +emask.SIGNED = emask.SINT + emask.FLOAT +emask.NUMBER = emask.INT + emask.FLOAT +emask.ALL = emask.NUMBER + emask.BOOL + emask.STRING + emask.CHAR + emask.NULL local value_con = { - [etype.INT ] = function(v) return tonumber(v.value.i ) end, - [etype.UINT ] = function(v) return tonumber(v.value.u ) end, + [etype.INT ] = function(v) return tonum(v.value.i ) end, + [etype.UINT ] = function(v) return tonum(v.value.u ) end, [etype.LONG ] = function(v) return v.value.l end, [etype.ULONG ] = function(v) return v.value.ul end, [etype.LLONG ] = function(v) return v.value.ll end, [etype.ULLONG] = function(v) return v.value.ull end, - [etype.FLOAT ] = function(v) return tonumber(v.value.f ) end, - [etype.DOUBLE] = function(v) return tonumber(v.value.d ) end, + [etype.FLOAT ] = function(v) return tonum(v.value.f ) end, + [etype.DOUBLE] = function(v) return tonum(v.value.d ) end, [etype.STRING] = function(v) return ffi.string(v.value.s ) end, [etype.CHAR ] = function(v) return string.char(v.value.c) end, [etype.NULL ] = function(v) return nil end, @@ -1599,19 +1603,19 @@ local value_con = { M.Value = ffi.metatype("Eolian_Value", { __index = { get_type = function(self) - return tonumber(ffi.cast("Eolian_Value_t*", self).type) + return tonum(ffi.cast("Eolian_Value_t*", self).type) end, get_value = function(self) local tp = self:get_type() - local fun = value_con[tonumber(tp)] + local fun = value_con[tonum(tp)] if not fun then return nil end return fun() end, to_literal = function(self) local v = eolian.eolian_expression_value_to_literal(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi_stringshare(v) end } @@ -1657,51 +1661,63 @@ M.Expression = ffi.metatype("Eolian_Expression", { __index = wrap_object { eval = function(self, mask) mask = mask or emask.ALL - local v = eolian.eolian_expression_eval(self, mask) - if v == nil then return nil end - return ffi.cast("Eolian_Value*", v) + local vsz = ffi.sizeof("Eolian_Value_t") + local p = ffi.cast("Eolian_Value_t *", ffi.C.malloc(vsz)) + if p == ffi.nullptr then return nil end + local v = eolian.eolian_expression_eval_fill(self, mask, p) + if v == 0 then + ffi.C.free(p) + return nil + end + return ffi.gc(ffi.cast("Eolian_Value *", p), ffi.C.free) end, serialize = function(self) local v = eolian.eolian_expression_serialize(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi_stringshare(v) end, type_get = function(self) - return tonumber(eolian.eolian_expression_type_get(self)) + return tonum(eolian.eolian_expression_type_get(self)) end, binary_operator_get = function(self) - return tonumber(eolian.eolian_expression_binary_operator_get(self)) + return tonum(eolian.eolian_expression_binary_operator_get(self)) end, binary_lhs_get = function(self) local v = eolian.eolian_expression_binary_lhs_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, binary_rhs_get = function(self) local v = eolian.eolian_expression_binary_rhs_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, unary_operator_get = function(self) - return tonumber(eolian.eolian_expression_unary_operator_get(self)) + return tonum(eolian.eolian_expression_unary_operator_get(self)) end, unary_expression_get = function(self) local v = eolian.eolian_expression_unary_expression_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, value_get = function(self) - local v = eolian.eolian_expression_value_get(self) - if v == nil then return nil end - return ffi.cast("Eolian_Value*", v) + local vsz = ffi.sizeof("Eolian_Value_t") + local p = ffi.cast("Eolian_Value_t *", ffi.C.malloc(vsz)) + if p == ffi.nullptr then return nil end + local v = eolian.eolian_expression_value_get_fill(self, p) + if v == 0 then + ffi.C.free(p) + return nil + end + return ffi.gc(ffi.cast("Eolian_Value *", p), ffi.C.free) end } }) @@ -1710,19 +1726,19 @@ M.Constant = ffi.metatype("Eolian_Constant", { __index = wrap_object { documentation_get = function(self) local v = eolian.eolian_constant_documentation_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, type_get = function(self) local v = eolian.eolian_constant_type_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, value_get = function(self) local v = eolian.eolian_constant_value_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, @@ -1736,13 +1752,13 @@ M.Error = ffi.metatype("Eolian_Error", { __index = wrap_object { documentation_get = function(self) local v = eolian.eolian_error_documentation_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return v end, message_get = function(self) local v = eolian.eolian_error_message_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi.string(v) end, @@ -1756,19 +1772,19 @@ M.Documentation = ffi.metatype("Eolian_Documentation", { __index = wrap_object { summary_get = function(self) local v = eolian.eolian_documentation_summary_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi.string(v) end, description_get = function(self) local v = eolian.eolian_documentation_description_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi.string(v) end, since_get = function(self) local v = eolian.eolian_documentation_since_get(self) - if v == nil then return nil end + if v == ffi.nullptr then return nil end return ffi.string(v) end } @@ -1807,7 +1823,7 @@ end M.documentation_tokenize = function(doc, ret) local ret = eolian.eolian_documentation_tokenize(doc, ret) - if ret == nil then + if ret == ffi.nullptr then return nil end return ffi.string(ret) @@ -1822,12 +1838,12 @@ end M.Eolian_Doc_Token = ffi.metatype("Eolian_Doc_Token", { __index = { type_get = function(self) - return tonumber(eolian.eolian_doc_token_type_get(self)) + return tonum(eolian.eolian_doc_token_type_get(self)) end, text_get = function(self) local str = eolian.eolian_doc_token_text_get(self) - if str == nil then + if str == ffi.nullptr then return nil end local ret = ffi.string(str) @@ -1837,7 +1853,7 @@ M.Eolian_Doc_Token = ffi.metatype("Eolian_Doc_Token", { ref_resolve = function(self, state) local stor = ffi.new("const Eolian_Object *[2]") - local tp = tonumber(eolian.eolian_doc_token_ref_resolve(self, state, stor, stor + 1)) + local tp = tonum(eolian.eolian_doc_token_ref_resolve(self, state, stor, stor + 1)) local reft = M.object_type if tp == reft.CLASS then return tp, ffi.cast("const Eolian_Class *", stor[0]) diff --git a/src/bindings/luajit/meson.build b/src/bindings/lua/meson.build index a1dd6463ea..a1dd6463ea 100644 --- a/src/bindings/luajit/meson.build +++ b/src/bindings/lua/meson.build diff --git a/src/bindings/meson.build b/src/bindings/meson.build index b59e084d8a..d7d7cba8be 100644 --- a/src/bindings/meson.build +++ b/src/bindings/meson.build @@ -1,6 +1,6 @@ bindings = get_option('bindings') -bindings_order = ['luajit', 'cxx', 'mono'] +bindings_order = ['lua', 'cxx', 'mono'] if (get_option('dotnet') and not bindings.contains('mono')) message('dotnet support requires the C# bindings') @@ -18,6 +18,10 @@ if (bindings.contains('cxx') == false and bindings.contains('mono')) ) endif +if bindings.contains('lua') and not have_elua + error('Elua is necessary for Lua bindings') +endif + foreach binding : bindings_order if bindings.contains(binding) subdir(join_paths( binding)) diff --git a/src/bindings/mono/ca.ruleset.in b/src/bindings/mono/ca.ruleset.in new file mode 100644 index 0000000000..0f5be8816c --- /dev/null +++ b/src/bindings/mono/ca.ruleset.in @@ -0,0 +1,334 @@ +<?xml version="1.0" encoding="utf-8"?> +<RuleSet Name="CustomRulset" Description="Custom Rulset" ToolsVersion="14.0"> + <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed"> + <!-- Do not declare static members on Generic Types --> + @CA1000@ + <!-- Consider making Raise an event --> + @CA1030@ + <!-- Catch generic exception --> + @CA1031@ + <!-- Add extra exception constructors --> + @CA1032@ + <!-- Do not nest NativeTypes --> + @CA1034@ + <!-- IComparable must implement other comparison operators --> + @CA1036@ + <!-- Avoid empty interface --> + @CA1040@ + <!-- Use Integral Or String Argument For Indexers --> + @CA1043@ + <!-- Consider making property with getter --> + @CA1044@ + <!-- Visible instance fields --> + @CA1051@ + <!-- Static holder can be static --> + @CA1052@ + <!-- Using parameters before checking for null --> + @CA1062@ + <!-- Remove IDisposable as Object already has it --> + @CA1063@ + <!-- Exceptions must be public --> + @CA1064@ + <!-- Do not raise exception in unexpected locations --> + @CA1065@ + <!-- String localization --> + @CA1303@ + <!-- Specify IFormatProvider --> + @CA1305@ + <!-- Specify Stringcomparison --> + @CA1307@ + <!-- PInvoke should not be visible --> + @CA1401@ + <!-- Use nameof --> + @CA1507@ + <!-- Parameter underscore --> + @CA1707@ + <!-- Attribute classes must have the Attribute Suffix --> + @CA1710@ + <!-- Replace generic parameter with T --> + @CA1715@ + <!-- Parameter End conflicts with VB --> + @CA1716@ + <!-- Enum field must be plural --> + @CA1717@ + <!-- Variable has type name --> + @CA1720@ + <!-- Property with same name as getter --> + @CA1721@ + <!-- Type name must not match namespace --> + @CA1724@ + <!-- Unused parameter. Lots of warnings regarding Dispose(disposing) --> + @CA1801@ + <!-- Do not ignore function result --> + @CA1806@ + <!-- Remove static constructors --> + @CA1810@ + <!-- Realized classes are never instantiated --> + @CA1812@ + <!-- Override equal and operator equal on Value Types--> + @CA1815@ + <!-- Dispose must call SuppressFinalizers --> + @CA1816@ + <!-- Member can be static --> + @CA1822@ + <!-- Consider zero length array allocation --> + @CA1825@ + <!-- Count() is used where Any() could be used instead to improve performance --> + @CA1827@ + <!-- Use Count instead of Count() --> + @CA1829@ + <!-- Call dispose before going out of scope --> + @CA2000@ + <!-- Call ConfigureWait--> + @CA2007@ + <!-- PInvoke should specify string marshalling --> + @CA2101@ + <!-- Rethrow loses stack info --> + @CA2200@ + <!-- Declare static fields when they are declared and remove static constructor --> + @CA2207@ + <!-- Instantiate exception params correctly --> + @CA2208@ + <!-- Dot not call overrideable methods in constructors --> + @CA2214@ + <!-- Replace implicit operator --> + @CA2225@ + <!-- Change 'XXXXX' to be read-only by removing the property setter --> + @CA2227@ + + + + </Rules> + <Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers"> + <!-- Ignore docs --> + @SA0001@ + + <!-- 10** Spacing rules --> + @SA1000@ + @SA1001@ + @SA1002@ + @SA1003@ + <!-- Documentation must start with single space --> + @SA1004@ + @SA1005@ + @SA1006@ + @SA1007@ + @SA1008@ + @SA1009@ + @SA1010@ + @SA1011@ + @SA1012@ + @SA1013@ + @SA1014@ + @SA1015@ + @SA1016@ + @SA1017@ + @SA1018@ + @SA1019@ + @SA1020@ + @SA1021@ + @SA1022@ + @SA1023@ + @SA1024@ + @SA1025@ + @SA1026@ + @SA1027@ + @SA1028@ + + <!-- Readability --> + @SA1100@ + @SA1101@ + @SA1102@ + @SA1103@ + @SA1104@ + @SA1105@ + @SA1106@ + @SA1107@ + @SA1108@ + @SA1109@ + @SA1110@ + @SA1111@ + @SA1112@ + @SA1113@ + @SA1114@ + @SA1115@ + @SA1116@ + @SA1117@ + @SA1118@ + @SA1119@ + @SA1120@ + @SA1121@ + @SA1122@ + @SA1123@ + @SA1124@ + @SA1125@ + @SA1126@ + @SA1127@ + @SA1128@ + @SA1129@ + @SA1130@ + @SA1131@ + @SA1132@ + @SA1133@ + @SA1134@ + @SA1135@ + @SA1136@ + @SA1137@ + @SA1138@ + @SA1139@ + + <!-- 12** Ordering --> + <!-- FIXME Check if this somehow affects docfx output --> + @SA1200@ + @SA1201@ + @SA1202@ + @SA1203@ + @SA1204@ + @SA1205@ + @SA1206@ + @SA1207@ + @SA1208@ + @SA1209@ + @SA1210@ + @SA1211@ + @SA1212@ + @SA1213@ + @SA1214@ + @SA1215@ + @SA1216@ + @SA1217@ + + <!-- 13** Naming Rules --> + <!-- Element start with upper case --> + @SA1300@ + @SA1301@ + <!-- Interface start with I --> + @SA1302@ + <!-- Upper/lower score rules --> + @SA1303@ + @SA1304@ + @SA1305@ + @SA1306@ + @SA1307@ + <!-- Variable field prefixes --> + @SA1308@ + @SA1309@ + @SA1310@ + @SA1311@ + @SA1312@ + @SA1313@ + @SA1314@ + + <!-- 14** Maintainability --> + <!-- Access modifier --> + @SA1400@ + <!-- Field must be private --> + @SA1401@ + <!-- File Must contain single class or namespace --> + @SA1402@ + @SA1403@ + <!-- CodeAnalysis suppress does not have justification --> + @SA1404@ + <!-- Debug.Assert/Fail must provide a message --> + @SA1405@ + @SA1406@ + <!-- Arithmetic/Conditional expression must declare precedence --> + @SA1407@ + @SA1408@ + <!-- Remove unecessary code --> + @SA1409@ + <!-- Delegate/Attribute parentheses --> + @SA1410@ + @SA1411@ + <!-- Utf8 file --> + @SA1412@ + <!-- Trailing commas multiline initializer --> + @SA1413@ + + <!-- 15** Layout Rules --> + @SA1500@ + @SA1501@ + @SA1502@ + @SA1503@ + @SA1504@ + @SA1505@ + @SA1506@ + @SA1507@ + @SA1508@ + @SA1509@ + @SA1510@ + @SA1511@ + @SA1512@ + @SA1513@ + @SA1514@ + @SA1515@ + @SA1516@ + @SA1517@ + @SA1518@ + @SA1519@ + @SA1520@ + + <!-- 16** Documentation rules --> + <!-- Things must be documented --> + @SA1600@ + @SA1601@ + @SA1602@ + <!-- Valid xml in docs --> + @SA1603@ + @SA1604@ + @SA1605@ + @SA1606@ + @SA1607@ + @SA1608@ + @SA1609@ + @SA1610@ + @SA1611@ + @SA1612@ + @SA1613@ + @SA1614@ + @SA1615@ + @SA1616@ + @SA1617@ + @SA1618@ + @SA1619@ + @SA1620@ + @SA1621@ + @SA1622@ + @SA1623@ + @SA1624@ + @SA1625@ + @SA1626@ + @SA1627@ + @SA1628@ + @SA1629@ + @SA1630@ + @SA1631@ + @SA1632@ + <!-- File headers --> + @SA1633@ + @SA1634@ + @SA1635@ + @SA1636@ + @SA1637@ + @SA1638@ + @SA1639@ + @SA1640@ + @SA1641@ + <!-- Constructor/Destructor --> + @SA1642@ + @SA1643@ + <!-- File header --> + @SA1644@ + <!-- Miscellaneous doc --> + @SA1645@ + @SA1646@ + @SA1647@ + @SA1648@ + <!-- Filename must match file type --> + @SA1649@ + <!-- Spelling --> + @SA1650@ + <!-- Placeholder --> + @SA1651@ + </Rules> +</RuleSet> diff --git a/src/bindings/mono/efl_mono.dll.config.in b/src/bindings/mono/efl_mono.dll.config.in index 25d216b1a0..2800c971d5 100644 --- a/src/bindings/mono/efl_mono.dll.config.in +++ b/src/bindings/mono/efl_mono.dll.config.in @@ -23,4 +23,5 @@ <dllmap dll="evas" target="@EVAS@"/> <dllmap dll="eldbus" target="@ELDBUS@"/> <dllmap dll="elementary" target="@ELEMENTARY@"/> + <dllmap dll="eflcustomexportsmono" target="@EFLCUSTOMEXPORTSMONO@"/> </configuration> diff --git a/src/bindings/mono/efl_mono/GenericModel.cs b/src/bindings/mono/efl_mono/GenericModel.cs index faa2a2f099..c23eeb64ab 100644 --- a/src/bindings/mono/efl_mono/GenericModel.cs +++ b/src/bindings/mono/efl_mono/GenericModel.cs @@ -33,26 +33,19 @@ public class GenericModel<T> : Efl.Object, Efl.IModel /// <summary>The list of properties available in the wrapped model.</summary> public IEnumerable<System.String> Properties { - get { return GetProperties(); } + get { return model.Properties; } } /// <summary>The number of children in the wrapped model.</summary> public uint ChildrenCount { - get { return GetChildrenCount(); } - } - - /// <summary>The list of properties available in the wrapped model.</summary> - /// <returns>The list of properties in the model.</returns> - public IEnumerable<System.String> GetProperties() - { - return model.GetProperties(); + get { return model.ChildrenCount; } } /// <summary>Gets the value of the given property in the wrapped model.</summary> /// <param name="property">The property of the model.</param> /// <returns>The value of the property.</returns> - public Eina.Value GetProperty(System.String property) + public Eina.Value GetProperty( System.String property) { return model.GetProperty(property); } @@ -62,22 +55,15 @@ public class GenericModel<T> : Efl.Object, Efl.IModel /// <param name="value">The value of the property.</param> /// <returns>An <see cref="Eina.Future" /> that resolves when the property has /// been set or reports an error if it could not be set.</returns> - public Eina.Future SetProperty(System.String property, Eina.Value value) + public Eina.Future SetProperty( System.String property, Eina.Value value) { return model.SetProperty(property, value); } - /// <summary>Returns the number of children in the wrapped model.</summary> - /// <returns>The number of children.</returns> - public uint GetChildrenCount() - { - return model.GetChildrenCount(); - } - /// <summary>Returns an <see cref="Eina.Future" /> that will resolve when the property is ready to be read.</summary> /// <param name="property">The property of the model.</param> /// <returns>An <see cref="Eina.Future" /> that resolves when the property is ready.</returns> - public Eina.Future GetPropertyReady(System.String property) + public Eina.Future GetPropertyReady( System.String property) { return model.GetPropertyReady(property); } @@ -87,7 +73,7 @@ public class GenericModel<T> : Efl.Object, Efl.IModel /// <param name="count">The size of the range.</param> /// <returns>An <see cref="Eina.Future" /> that resolves to an /// <see cref="Eina.Array<T>" /> of children models.</returns> - public Eina.Future GetChildrenSlice(uint start, uint count) + public Eina.Future GetChildrenSlice( uint start, uint count) { return model.GetChildrenSlice(start, count); } @@ -141,7 +127,7 @@ public class GenericModel<T> : Efl.Object, Efl.IModel /// <param name="token">The token for the task's cancellation.</param> /// <returns>Task that resolves when the property has been set or could not /// be set.</returns> - public System.Threading.Tasks.Task<Eina.Value> SetPropertyAsync(System.String property, Eina.Value value, System.Threading.CancellationToken token=default(System.Threading.CancellationToken)) + public System.Threading.Tasks.Task<Eina.Value> SetPropertyAsync( System.String property, Eina.Value value, System.Threading.CancellationToken token=default(System.Threading.CancellationToken)) { return model.SetPropertyAsync(property, value, token); } @@ -151,7 +137,7 @@ public class GenericModel<T> : Efl.Object, Efl.IModel /// <param name="token">The token for the task's cancellation.</param> /// <returns>Task that resolves when the given property is ready to be /// read.</returns> - public System.Threading.Tasks.Task<Eina.Value> GetPropertyReadyAsync(System.String property, System.Threading.CancellationToken token=default(System.Threading.CancellationToken)) + public System.Threading.Tasks.Task<Eina.Value> GetPropertyReadyAsync( System.String property, System.Threading.CancellationToken token=default(System.Threading.CancellationToken)) { return model.GetPropertyReadyAsync(property, token); } @@ -162,11 +148,33 @@ public class GenericModel<T> : Efl.Object, Efl.IModel /// <param name="token">Token to notify the async operation of external request to cancel.</param> /// <returns>Task that resolves when the desired <see cref="Eina.Array<T>" /> of /// children models is ready.</returns> - public System.Threading.Tasks.Task<Eina.Value> GetChildrenSliceAsync(uint start, uint count, System.Threading.CancellationToken token=default(System.Threading.CancellationToken)) + public System.Threading.Tasks.Task<Eina.Value> GetChildrenSliceAsync( uint start, uint count, System.Threading.CancellationToken token=default(System.Threading.CancellationToken)) { return model.GetChildrenSliceAsync(start, count, token); } + /// <summary>Get children as specified by iterator. + /// + /// Provided index have to be between 0 and <see cref="Efl.IModel.ChildrenCount"/>. + /// + /// This function might rely on <see cref="Efl.IModel.GetChildrenSlice"/> as a fallback.<br/>Since EFL 1.23.</summary> + /// <param name="indices">Indices of the requested children.</param> + /// <returns>Array of children</returns> + public Eina.Future GetChildrenIndex(IEnumerable<uint> indices) + { + return model.GetChildrenIndex(indices); + } + + /// <summary>Async wrapper for <see cref="GetChildrenIndex" />. + /// </summary> + /// <param name="indices">Indices of the requested children.</param> + /// <param name="token">Token to notify the async operation of external request to cancel.</param> + /// <returns>An async task wrapping the result of the operation.</returns> + public System.Threading.Tasks.Task<Eina.Value> GetChildrenIndexAsync(IEnumerable<uint> indices, System.Threading.CancellationToken token = default(System.Threading.CancellationToken)) + { + return model.GetChildrenIndexAsync(indices, token); + } + /// <summary>Event triggered when properties on the wrapped model changes.</summary> public event EventHandler<Efl.ModelPropertiesChangedEventArgs> PropertiesChangedEvent { diff --git a/src/bindings/mono/efl_mono/efl_csharp_application.cs b/src/bindings/mono/efl_mono/efl_csharp_application.cs index 8493abd6ab..1cf5d0d07b 100644 --- a/src/bindings/mono/efl_mono/efl_csharp_application.cs +++ b/src/bindings/mono/efl_mono/efl_csharp_application.cs @@ -198,17 +198,17 @@ public abstract class Application { Init(components); Efl.App app = Efl.App.AppMain; - var command_line = new Eina.Array<Eina.Stringshare>(); +#if EFL_BETA + var command_line = new List<Eina.Stringshare>(); //command_line.Add(List.ConvertAll(Environment.GetCommandLineArgs(), s => (Eina.Stringshare)s)); //command_line.AddRange(Environment.GetCommandLineArgs()); -#if EFL_BETA app.SetCommandArray(command_line); #endif app.ArgumentsEvent += (object sender, LoopArgumentsEventArgs evt) => { - if (evt.arg.Initialization) + if (evt.Arg.Initialization) { - var evtArgv = evt.arg.Argv; + var evtArgv = evt.Arg.Argv; int n = evtArgv.Count; var argv = new string[n]; for (int i = 0; i < n; ++i) @@ -219,7 +219,7 @@ public abstract class Application OnInitialize(argv); } - OnArguments(evt.arg); + OnArguments(evt.Arg); }; app.PauseEvent += (object sender, EventArgs e) => { @@ -234,7 +234,6 @@ public abstract class Application OnTerminate(); }; app.Begin(); - command_line.Dispose(); Shutdown(); } } diff --git a/src/bindings/mono/efl_mono/efl_libs.cs.in b/src/bindings/mono/efl_mono/efl_libs.cs.in index fcf5b18183..af811d494a 100644 --- a/src/bindings/mono/efl_mono/efl_libs.cs.in +++ b/src/bindings/mono/efl_mono/efl_libs.cs.in @@ -33,7 +33,7 @@ internal class Libs { internal const string CustomExports = "@CUSTOM_EXPORTS_MONO_DL_MONO@"; - internal const string Libdl = "libdl.so"; + internal const string Libdl = "@LIBDL_DL_MONO@"; internal const string Kernel32 = "kernel32.dll"; internal static readonly Efl.Eo.NativeModule EflModule = new Efl.Eo.NativeModule(Efl); diff --git a/src/bindings/mono/efl_mono/meson.build b/src/bindings/mono/efl_mono/meson.build index 165b6d55bd..5ca6f116d6 100644 --- a/src/bindings/mono/efl_mono/meson.build +++ b/src/bindings/mono/efl_mono/meson.build @@ -16,6 +16,11 @@ efl_libs = configuration_data() efl_libs.set('EFL_MONO_LIBRARY_MAP', map) efl_libs.set('CUSTOM_EXPORTS_MONO_DL_MONO', 'eflcustomexportsmono') efl_libs.set('EVIL_DL_MONO', 'dl') +if sys_osx + efl_libs.set('LIBDL_DL_MONO', 'dl.dylib') +else + efl_libs.set('LIBDL_DL_MONO', 'libdl.so') +endif foreach mono_libs : mono_sublibs key = mono_libs[0].to_upper()+'_DL_MONO' diff --git a/src/bindings/mono/efl_sharp.csproj.in b/src/bindings/mono/efl_sharp.csproj.in index ce6a9e463c..e03be33950 100644 --- a/src/bindings/mono/efl_sharp.csproj.in +++ b/src/bindings/mono/efl_sharp.csproj.in @@ -12,11 +12,6 @@ <PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> </PropertyGroup> - <PropertyGroup> - <DocumentationFile>$(AssemblyName).xml</DocumentationFile> - <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - </PropertyGroup> - <!-- <PropertyGroup Condition="'$(BuildType)'=='Beta'"> --> <!-- <DefineConstants>EFL_BETA</DefineConstants> --> <!-- </PropertyGroup> --> @@ -41,4 +36,13 @@ <Compile Include="./*.cs" /> </ItemGroup> + <!-- Code style configuration --> + <ItemGroup> + <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6" /> + <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" /> + </ItemGroup> + <PropertyGroup> + <CodeAnalysisRuleSet>@CA_RULESET@</CodeAnalysisRuleSet> + </PropertyGroup> + </Project> diff --git a/src/bindings/mono/eina_mono/eina_common.cs b/src/bindings/mono/eina_mono/eina_common.cs index a4f2ff4c5f..014e77d020 100644 --- a/src/bindings/mono/eina_mono/eina_common.cs +++ b/src/bindings/mono/eina_mono/eina_common.cs @@ -55,6 +55,9 @@ internal static partial class NativeCustomExportFunctions efl_mono_native_free_addr_get(); [DllImport(efl.Libs.CustomExports)] public static extern IntPtr efl_mono_native_efl_unref_addr_get(); + + [DllImport(efl.Libs.Eina)] public static extern IntPtr + eina_slstr_copy_new(string str); } /// <summary>Wrapper around native memory DllImport'd functions. @@ -94,6 +97,11 @@ public static class MemoryNative return NativeCustomExportFunctions.efl_mono_native_strdup(str); } + public static IntPtr SlstrCopyNew(string str) + { + return NativeCustomExportFunctions.eina_slstr_copy_new(str); + } + /// <summary> /// Retrieves an instance of a string for use in program. /// <para>Since EFL 1.23.</para> diff --git a/src/bindings/mono/eina_mono/eina_container_common.cs b/src/bindings/mono/eina_mono/eina_container_common.cs index 192469a033..a07153e51a 100644 --- a/src/bindings/mono/eina_mono/eina_container_common.cs +++ b/src/bindings/mono/eina_mono/eina_container_common.cs @@ -1003,22 +1003,6 @@ internal static class TraitFunctions private static IDictionary<System.Type, object> register = new Dictionary<System.Type, object>(); - private static System.Type AsEflInstantiableType(System.Type type) - { - if (!IsEflObject(type)) - { - return null; - } - - if (type.IsInterface) - { - string fullName = type.FullName + "Concrete"; - return type.Assembly.GetType(fullName); // That was our best guess... - } - - return type; // Not interface, so it should be a concrete. - } - public static object RegisterTypeTraits<T>() { Eina.Log.Debug($"Finding TypeTraits for {typeof(T).Name}"); @@ -1026,14 +1010,6 @@ internal static class TraitFunctions var type = typeof(T); if (IsEflObject(type)) { - System.Type concrete = AsEflInstantiableType(type); - if (concrete == null || !type.IsAssignableFrom(concrete)) - { - throw new Exception("Failed to get a suitable concrete class for this type."); - } - - // No need to pass concrete as the traits class will use reflection to get the actually most - // derived type returned. traits = new EflObjectElementTraits<T>(); } else if (IsString(type)) diff --git a/src/bindings/mono/eina_mono/eina_error.cs b/src/bindings/mono/eina_mono/eina_error.cs index 1300e796ab..004792fdb7 100644 --- a/src/bindings/mono/eina_mono/eina_error.cs +++ b/src/bindings/mono/eina_mono/eina_error.cs @@ -59,11 +59,27 @@ public struct Error : IComparable<Error>, IEquatable<Error> /// <para>Since EFL 1.23.</para> /// </summary> public static readonly Error ENOENT = new Error(2); + + /// <summary> + /// Return architecture independent ECANCELED error code. + /// Returns 125 for Linux, 89 for OSX and 105 for Windows. + /// <para>Since EFL 1.25.</para> + /// </summary> + private static int IndependentECANCELED() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + return new Error(125); + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + return new Error(89); + else // Windows + return new Error(105); + } + /// <summary> /// Cancelled error identifier. /// <para>Since EFL 1.23.</para> /// </summary> - public static readonly Error ECANCELED = new Error(125); + public static readonly Error ECANCELED = IndependentECANCELED(); /// <summary> /// Constructor. diff --git a/src/bindings/mono/eina_mono/eina_slice.cs b/src/bindings/mono/eina_mono/eina_slice.cs index 912ddea3bd..0b9311e48c 100644 --- a/src/bindings/mono/eina_mono/eina_slice.cs +++ b/src/bindings/mono/eina_mono/eina_slice.cs @@ -232,7 +232,9 @@ public struct RwSlice : ISliceBase, IEquatable<RwSlice> } -public static class Eina_SliceUtils +namespace Eina +{ +public static class SliceExtensions { public static byte[] GetBytes(this Eina.ISliceBase slc) { @@ -243,3 +245,4 @@ public static class Eina_SliceUtils return mArray; } } +} diff --git a/src/bindings/mono/eina_mono/eina_stringshare.cs b/src/bindings/mono/eina_mono/eina_stringshare.cs index 58656fe8ca..741817294d 100644 --- a/src/bindings/mono/eina_mono/eina_stringshare.cs +++ b/src/bindings/mono/eina_mono/eina_stringshare.cs @@ -69,7 +69,7 @@ public class Stringshare : IEquatable<Stringshare>, IEquatable<string> /// <summary> /// Main constructor. Wrap the given string. /// Have private acess to avoid wrapping a null reference, - /// use convertion or the factory method to create a new instance. + /// use conversion or the factory method to create a new instance. /// <para>Since EFL 1.23.</para> /// <see cref="Create(string)"/> /// <see cref="implicit operator Stringshare(string)"/> @@ -108,7 +108,7 @@ public class Stringshare : IEquatable<Stringshare>, IEquatable<string> } /// <summary> - /// Implicit convertion to string. + /// Implicit conversion to string. /// </summary> public static implicit operator string(Stringshare ss) { @@ -121,12 +121,12 @@ public class Stringshare : IEquatable<Stringshare>, IEquatable<string> } /// <summary> - /// Implicit convertion from string to Stringshare. + /// Implicit conversion from string to Stringshare. /// <para>Since EFL 1.23.</para> /// </summary> /// <remarks> /// Note that this method can be used to create an instance of this class, - /// either via an explicit cast or an implicit convertion. + /// either via an explicit cast or an implicit conversion. /// <seealso cref="Create(string)"/> /// </remarks> public static implicit operator Stringshare(string s) @@ -145,7 +145,7 @@ public class Stringshare : IEquatable<Stringshare>, IEquatable<string> /// </summary> /// <remarks> /// Note that this method can be used to create an instance of this class, - /// either via an explicit cast or an implicit convertion. + /// either via an explicit cast or an implicit conversion. /// <seealso cref="Create(string)"/> /// </remarks> public static Stringshare FromString(string s) => s; diff --git a/src/bindings/mono/eina_mono/eina_value.cs b/src/bindings/mono/eina_mono/eina_value.cs index 46d1ff02b5..538374f3f8 100644 --- a/src/bindings/mono/eina_mono/eina_value.cs +++ b/src/bindings/mono/eina_mono/eina_value.cs @@ -260,6 +260,58 @@ static internal class UnsafeNativeMethods [DllImport(efl.Libs.CustomExports)] [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_string(IntPtr handle, uint p, string data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_ptr(IntPtr handle, uint p, IntPtr data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_char(IntPtr handle, uint p, sbyte data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_uchar(IntPtr handle, uint p, byte data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_short(IntPtr handle, uint p, short data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_ushort(IntPtr handle, uint p, ushort data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_int(IntPtr handle, uint p, int data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_uint(IntPtr handle, uint p, uint data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_long(IntPtr handle, uint p, long data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_ulong(IntPtr handle, uint p, ulong data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_float(IntPtr handle, uint p, float data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_container_insert_wrapper_double(IntPtr handle, uint p, double data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] + internal static extern bool eina_value_list_insert_wrapper(IntPtr handle, uint p, IntPtr data); + + [DllImport(efl.Libs.CustomExports)] + [return: MarshalAsAttribute(UnmanagedType.U1)] internal static extern bool eina_value_container_get_wrapper(IntPtr handle, int index, out IntPtr output); [DllImport(efl.Libs.CustomExports)] @@ -3425,6 +3477,98 @@ public class Value : IDisposable, IComparable<Value>, IEquatable<Value> return false; } + /// <summary>Insert new values to this container at a given position. + /// + /// <para>Since EFL 1.23.</para> + /// </summary> + /// <param name="o">The new value to be inserted.</param> + /// <param name="p">The position to insert the new value.</param> + /// <returns><c>true</c> if the value was successfully insert.</returns> + public bool Insert(object o, uint p) + { + Contract.Requires(o != null, nameof(o)); + ContainerSanityChecks(); + + switch (GetValueSubType()) + { + case ValueType.SByte: + { + sbyte b = Convert.ToSByte(o, CultureInfo.CurrentCulture); + return eina_value_container_insert_wrapper_char(this.Handle, p, b); + } + + case ValueType.Byte: + { + byte b = Convert.ToByte(o, CultureInfo.CurrentCulture); + return eina_value_container_insert_wrapper_uchar(this.Handle, p, b); + } + + case ValueType.Short: + { + short b = Convert.ToInt16(o, CultureInfo.CurrentCulture); + return eina_value_container_insert_wrapper_short(this.Handle, p, b); + } + + case ValueType.UShort: + { + ushort b = Convert.ToUInt16(o, CultureInfo.CurrentCulture); + return eina_value_container_insert_wrapper_ushort(this.Handle, p, b); + } + + case ValueType.Int32: + { + int x = Convert.ToInt32(o, CultureInfo.CurrentCulture); + return eina_value_container_insert_wrapper_int(this.Handle, p, x); + } + + case ValueType.UInt32: + { + uint x = Convert.ToUInt32(o, CultureInfo.CurrentCulture); + return eina_value_container_insert_wrapper_uint(this.Handle, p, x); + } + + case ValueType.Long: + case ValueType.Int64: + { + long x = Convert.ToInt64(o, CultureInfo.CurrentCulture); + return eina_value_container_insert_wrapper_long(this.Handle, p, x); + } + + case ValueType.ULong: + case ValueType.UInt64: + { + ulong x = Convert.ToUInt64(o, CultureInfo.CurrentCulture); + return eina_value_container_insert_wrapper_ulong(this.Handle, p, x); + } + + case ValueType.Float: + { + float x = Convert.ToSingle(o, CultureInfo.CurrentCulture); + return eina_value_container_insert_wrapper_float(this.Handle, p, x); + } + + case ValueType.Double: + { + double x = Convert.ToDouble(o, CultureInfo.CurrentCulture); + return eina_value_container_insert_wrapper_double(this.Handle, p, x); + } + + case ValueType.String: + { + string x = Convert.ToString(o, CultureInfo.CurrentCulture); + return eina_value_container_insert_wrapper_string(this.Handle, p, x); + } + case ValueType.Object: + { + var x = (Efl.Object) o; + return eina_value_container_insert_wrapper_ptr(this.Handle, p, x.NativeHandle); + } + } + + return false; + } + + /// <summary>Indexer for this container. /// /// <para>Since EFL 1.23.</para> diff --git a/src/bindings/mono/eo_mono/EoWrapper.cs b/src/bindings/mono/eo_mono/EoWrapper.cs index 99e60b1d2b..e4ff8669e6 100644 --- a/src/bindings/mono/eo_mono/EoWrapper.cs +++ b/src/bindings/mono/eo_mono/EoWrapper.cs @@ -227,7 +227,7 @@ public abstract class EoWrapper : IWrapper, IDisposable public void Del() { // FIXME Implement this - ((Efl.Object)this).SetParent(null); + ((Efl.Object)this).Parent = null; Dispose(); } @@ -328,7 +328,7 @@ public abstract class EoWrapper : IWrapper, IDisposable internal Efl.EventCb GetInternalEventCallback<T>(EventHandler<T> handler, Func<IntPtr, T> createArgsInstance) where T:EventArgs { - return (IntPtr data, ref Efl.Event.NativeStruct evt) => + return (IntPtr data, ref Efl.Event evt) => { var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target; if (obj != null) @@ -348,7 +348,7 @@ public abstract class EoWrapper : IWrapper, IDisposable internal Efl.EventCb GetInternalEventCallback(EventHandler handler) { - return (IntPtr data, ref Efl.Event.NativeStruct evt) => + return (IntPtr data, ref Efl.Event evt) => { var obj = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data).Target; if (obj != null) @@ -383,13 +383,13 @@ public abstract class EoWrapper : IWrapper, IDisposable } } - private static void OwnershipUniqueCallback(IntPtr data, ref Efl.Event.NativeStruct evt) + private static void OwnershipUniqueCallback(IntPtr data, ref Efl.Event evt) { var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data); ws.MakeUnique(); } - private static void OwnershipSharedCallback(IntPtr data, ref Efl.Event.NativeStruct evt) + private static void OwnershipSharedCallback(IntPtr data, ref Efl.Event evt) { var ws = Efl.Eo.Globals.WrapperSupervisorPtrToManaged(data); ws.MakeShared(); diff --git a/src/bindings/mono/eo_mono/NativeModule_Unix.cs b/src/bindings/mono/eo_mono/NativeModule_Unix.cs index 67409e02d1..b4dfeb8aea 100644 --- a/src/bindings/mono/eo_mono/NativeModule_Unix.cs +++ b/src/bindings/mono/eo_mono/NativeModule_Unix.cs @@ -56,6 +56,12 @@ internal partial class NativeModule ///<item> ///<description><c>libfilename.so</c></description> ///</item> + ///<item> + ///<description><c>filename.dylib</c></description> + ///</item> + ///<item> + ///<description><c>libfilename.dylib</c></description> + ///</item> ///</list> ///</summary> ///<param name="filename">The name to search for.</param> @@ -73,6 +79,16 @@ internal partial class NativeModule if (r == IntPtr.Zero) { r = dlopen("lib" + filename + ".so", RTLD_NOW | RTLD_GLOBAL); + if (r == IntPtr.Zero) + { + r = dlopen(filename + ".dylib", RTLD_NOW | RTLD_GLOBAL); + if (r == IntPtr.Zero) + { + r = dlopen("lib" + filename + ".dylib", RTLD_NOW | RTLD_GLOBAL); + } + } + + } } } diff --git a/src/bindings/mono/eo_mono/iwrapper.cs b/src/bindings/mono/eo_mono/iwrapper.cs index 2a8ebf0620..626777f7d5 100644 --- a/src/bindings/mono/eo_mono/iwrapper.cs +++ b/src/bindings/mono/eo_mono/iwrapper.cs @@ -875,33 +875,107 @@ internal static class Globals return ret; } - internal static IEnumerable<T> ListToIEnumerable<T>(IntPtr list) + internal static IList<T> NativeListToIList<T>(IntPtr nativeList) { - if (list == IntPtr.Zero) - throw new ArgumentException("list is null", nameof(list)); + if (nativeList == IntPtr.Zero) + throw new ArgumentException("nativeList is null", nameof(nativeList)); IntPtr l; - - for (l = list; l != IntPtr.Zero; l = Eina.ListNativeFunctions.eina_list_next_custom_export_mono(l)) + List<T> list = new List<T>(); + for (l = nativeList; l != IntPtr.Zero; l = Eina.ListNativeFunctions.eina_list_next_custom_export_mono(l)) { - yield return Eina.TraitFunctions.NativeToManaged<T>(Eina.ListNativeFunctions.eina_list_data_get_custom_export_mono(l)); + list.Add(Eina.TraitFunctions.NativeToManaged<T>(Eina.ListNativeFunctions.eina_list_data_get_custom_export_mono(l))); } + return list; } - internal static IntPtr IEnumerableToList<T>(IEnumerable<T> enumerable) + internal static IntPtr IListToNativeList<T>(IList<T> list, bool isMoved) { - if (enumerable == null) - throw new ArgumentException("enumerable is null", nameof(enumerable)); + if (list == null) + throw new ArgumentException("list is null", nameof(list)); - IntPtr list = IntPtr.Zero; - foreach (T data in enumerable) + // If we are a wrapper around an existing Eina.List, we can just forward + // it and avoid unnecessary copying in non-owning transfers. + var wrappedList = list as Eina.List<T>; + + if (wrappedList != null && !isMoved) + { + return wrappedList.Handle; + } + + IntPtr nativeList = IntPtr.Zero; + foreach (T data in list) + { + nativeList = Eina.ListNativeFunctions.eina_list_append(nativeList, Eina.TraitFunctions.ManagedToNativeAlloc(data)); //FIXME: need to free + } + + if (!isMoved) { - list = Eina.ListNativeFunctions.eina_list_append(list, Eina.TraitFunctions.ManagedToNativeAlloc(data)); + // FIXME Need to free ret and unpin pinnedArray in the future. } + + return nativeList; + } + + internal static IList<T> NativeArrayToIList<T>(IntPtr nativeArray) + { + if (nativeArray == IntPtr.Zero) + throw new ArgumentException("nativeArray is null", nameof(nativeArray)); + + List<T> list = new List<T>(); + UpdateListFromNativeArray(list, nativeArray); + // FIXME need to free `list` if the returned list is not @moved return list; } + internal static IntPtr IListToNativeArray<T>(IList<T> list, bool isMoved) + { + if (list == null) + throw new ArgumentException("list is null", nameof(list)); + + // If we are a wrapper around an existing Eina.Array, we can just forward + // it and avoid unnecessary copying in non-owning transfers. + var wrappedArray = list as Eina.Array<T>; + + if (wrappedArray != null && !isMoved) + { + return wrappedArray.Handle; + } + + IntPtr nativeArray = Eina.ArrayNativeFunctions.eina_array_new(4); + foreach (T data in list) + { + Eina.ArrayNativeFunctions.eina_array_push_custom_export_mono(nativeArray, Eina.TraitFunctions.ManagedToNativeAlloc(data)); //FIXME: need to free + } + + if (!isMoved) + { + // FIXME Need to free ret and unpin pinnedArray in the future. + } + + return nativeArray; + } + + internal static void UpdateListFromNativeArray<T>(IList<T> list, IntPtr nativeArray) + { + // Do not update if list Handle is same to nativeArray. They already updated in native code. + var wrappedArray = list as Eina.Array<T>; + if (wrappedArray != null && wrappedArray.Handle == nativeArray) + return; + + list.Clear(); + if (nativeArray == IntPtr.Zero) + { + return; + } + + uint count = Eina.ArrayNativeFunctions.eina_array_count_custom_export_mono(nativeArray); + for (uint i = 0; i < count; i++) + { + list.Add(Eina.TraitFunctions.NativeToManaged<T>(Eina.ArrayNativeFunctions.eina_array_data_get_custom_export_mono(nativeArray, i))); + } + } } // Globals @@ -1147,14 +1221,12 @@ internal static class ClassRegister if (objectType.IsInterface) { - // Try to get the *Concrete class - var assembly = objectType.Assembly; - objectType = assembly.GetType(objectType.FullName + "Concrete"); - - if (objectType == null) - { + // Try to get the *NativeMethods class + var nativeMethods = (Efl.Eo.NativeClass)System.Attribute.GetCustomAttributes(objectType)?.FirstOrDefault(attr => attr is Efl.Eo.NativeClass); + if (nativeMethods == null) return IntPtr.Zero; - } + + return nativeMethods.GetEflClass(); } var method = objectType.GetMethod("GetEflClassStatic", @@ -1436,6 +1508,45 @@ class StringPassOwnershipMarshaler : ICustomMarshaler static private StringPassOwnershipMarshaler marshaler; } + +class StringOutMarshaler: ICustomMarshaler +{ + public object MarshalNativeToManaged(IntPtr pNativeData) + { + return Eina.StringConversion.NativeUtf8ToManagedString(pNativeData); + } + + public IntPtr MarshalManagedToNative(object managedObj) + { + return Eina.MemoryNative.SlstrCopyNew((string)managedObj); + } + + public void CleanUpNativeData(IntPtr pNativeData) + { + } + + public void CleanUpManagedData(object managedObj) + { + } + + public int GetNativeDataSize() + { + return -1; + } + + internal static ICustomMarshaler GetInstance(string cookie) + { + if (marshaler == null) + { + marshaler = new StringOutMarshaler(); + } + + return marshaler; + } + + static private StringOutMarshaler marshaler; +} + class StringKeepOwnershipMarshaler: ICustomMarshaler { public object MarshalNativeToManaged(IntPtr pNativeData) diff --git a/src/bindings/mono/eo_mono/workaround.cs b/src/bindings/mono/eo_mono/workaround.cs index 0afe95807b..81aa32499e 100644 --- a/src/bindings/mono/eo_mono/workaround.cs +++ b/src/bindings/mono/eo_mono/workaround.cs @@ -173,17 +173,24 @@ internal struct EventDescription [Efl.Eo.BindingEntity] internal struct Event { + /// <summary>Internal wrapper for field Object</summary> + private System.IntPtr obj; + /// <summary>Internal wrapper for field Desc</summary> + private System.IntPtr desc; + /// <summary>Internal wrapper for field Info</summary> + private System.IntPtr info; + /// <summary> /// The object the callback was called on. /// <para>Since EFL 1.22.</para> /// </summary> - public Efl.Object Object; + public Efl.Object Object { get => (Efl.Object) Efl.Eo.Globals.CreateWrapperFor(obj); } /// <summary> /// The event description. /// <para>Since EFL 1.22.</para> /// </summary> - public Efl.EventDescription Desc; + public Efl.EventDescription Desc { get => Eina.PrimitiveConversion.PointerToManaged<Efl.EventDescription>(desc); } /// <summary> /// Extra event information passed by the event caller. @@ -192,7 +199,7 @@ internal struct Event /// 2) Structs, built-in types and containers are passed as const pointers, with one level of indirection. /// <para>Since EFL 1.22.</para> /// </summary> - public System.IntPtr Info; + public System.IntPtr Info { get => info; } /// <summary>Constructor for Event.</summary> public Event( @@ -200,123 +207,21 @@ internal struct Event Efl.EventDescription desc = default(Efl.EventDescription), System.IntPtr info = default(System.IntPtr)) { - this.Object = obj; - this.Desc = desc; - this.Info = info; + this.obj = obj?.NativeHandle ?? System.IntPtr.Zero; + this.desc = Eina.PrimitiveConversion.ManagedToPointerAlloc(desc); + this.info = info; } /// <summary>Implicit conversion to the managed representation from a native pointer.</summary> /// <param name="ptr">Native pointer to be converted.</param> public static implicit operator Event(IntPtr ptr) { - var tmp = (Event.NativeStruct) Marshal.PtrToStructure(ptr, typeof(Event.NativeStruct)); + var tmp = (Event) Marshal.PtrToStructure(ptr, typeof(Event)); return tmp; } - - /// <summary>Internal wrapper for struct Event.</summary> - [StructLayout(LayoutKind.Sequential)] - public struct NativeStruct - { - /// <summary>Internal wrapper for field Object</summary> - public System.IntPtr Object; - - /// <summary>Internal wrapper for field Desc</summary> - public System.IntPtr Desc; - - /// <summary>Internal wrapper for field Info</summary> - public System.IntPtr Info; - - /// <summary>Implicit conversion to the internal/marshalling representation.</summary> - /// <param name="externalStruct">Managed struct to be converted.</param> - /// <returns>Native representation of the managed struct.</returns> - public static implicit operator Event.NativeStruct(Event externalStruct) - { - var internalStruct = new Event.NativeStruct(); - internalStruct.Object = externalStruct.Object?.NativeHandle ?? System.IntPtr.Zero; - internalStruct.Desc = Eina.PrimitiveConversion.ManagedToPointerAlloc(externalStruct.Desc); - internalStruct.Info = externalStruct.Info; - return internalStruct; - } - - /// <summary>Implicit conversion to the managed representation.</summary> - /// <param name="internalStruct">Native struct to be converted.</param> - /// <returns>Managed representation of the native struct.</returns> - public static implicit operator Event(Event.NativeStruct internalStruct) - { - var externalStruct = new Event(); - externalStruct.Object = (Efl.Object) Efl.Eo.Globals.CreateWrapperFor(internalStruct.Object); - externalStruct.Desc = Eina.PrimitiveConversion.PointerToManaged<Efl.EventDescription>(internalStruct.Desc); - externalStruct.Info = internalStruct.Info; - return externalStruct; - } - } } -internal delegate void EventCb(System.IntPtr data, ref Event.NativeStruct evt); +internal delegate void EventCb(System.IntPtr data, ref Event evt); internal delegate void FreeWrapperSupervisorCb(System.IntPtr obj); -namespace Access -{ - -public struct ActionData : IEquatable<ActionData> -{ - public IntPtr name; - public IntPtr action; - public IntPtr param; - public IntPtr func; - - - /// <summary> - /// Gets a hash for <see cref="ActionData" />. - /// <para>Since EFL 1.24.</para> - /// </summary> - /// <returns>A hash code.</returns> - public override int GetHashCode() - => name.GetHashCode() ^ action.GetHashCode() - ^ param.GetHashCode() ^ func.GetHashCode(); - - /// <summary>Returns whether this <see cref="ActionData" /> - /// is equal to the given <see cref="object" />. - /// <para>Since EFL 1.24.</para> - /// </summary> - /// <param name="other">The <see cref="object" /> to be compared to.</param> - /// <returns><c>true</c> if is equal to <c>other</c>.</returns> - public override bool Equals(object other) - => (!(other is ActionData)) ? false - : Equals((ActionData)other); - - - /// <summary>Returns whether this <see cref="ActionData" /> is equal - /// to the given <see cref="ActionData" />. - /// <para>Since EFL 1.24.</para> - /// </summary> - /// <param name="other">The <see cref="ActionData" /> to be compared to.</param> - /// <returns><c>true</c> if is equal to <c>other</c>.</returns> - public bool Equals(ActionData other) - => (name == other.name) && (action == other.action) - && (param == other.param) && (func == other.func); - - /// <summary>Returns whether <c>lhs</c> is equal to <c>rhs</c>. - /// <para>Since EFL 1.24.</para> - /// </summary> - /// <param name="lhs">The left hand side of the operator.</param> - /// <param name="rhs">The right hand side of the operator.</param> - /// <returns><c>true</c> if <c>lhs</c> is equal - /// to <c>rhs</c>.</returns> - public static bool operator==(ActionData lhs, ActionData rhs) - => lhs.Equals(rhs); - - /// <summary>Returns whether <c>lhs</c> is not equal to <c>rhs</c>. - /// <para>Since EFL 1.24.</para> - /// </summary> - /// <param name="lhs">The left hand side of the operator.</param> - /// <param name="rhs">The right hand side of the operator.</param> - /// <returns><c>true</c> if <c>lhs</c> is not equal - /// to <c>rhs</c>.</returns> - public static bool operator!=(ActionData lhs, ActionData rhs) - => !(lhs == rhs); -} - -} // namespace Access - } // namespace Efl diff --git a/src/bindings/mono/meson.build b/src/bindings/mono/meson.build index f98aa5eeae..74f2d06de7 100644 --- a/src/bindings/mono/meson.build +++ b/src/bindings/mono/meson.build @@ -122,10 +122,12 @@ efl_mono_conf_data.set('EO', eo_lib.full_path()) efl_mono_conf_data.set('EVAS', evas_lib.full_path()) efl_mono_conf_data.set('ELDBUS', eldbus_lib.full_path()) efl_mono_conf_data.set('ELEMENTARY', elementary_lib.full_path()) +efl_mono_conf_data.set('EFLCUSTOMEXPORTSMONO', efl_mono_lib.full_path()) efl_mono_dll_config = configure_file(input : 'efl_mono.dll.config.in', - output : 'efl_mono.dll.config', - configuration : efl_mono_conf_data) + output : 'efl_mono.dll.config', + configuration : efl_mono_conf_data) + extra_cs_args = runtime_assemblies @@ -137,8 +139,69 @@ efl_mono_install_dir = join_paths(dir_lib, 'efl-mono-'+version_major) efl_mono_xml_doc = join_paths(meson.current_build_dir(), 'efl_mono.xml') if (get_option('dotnet')) + styles = ['CA1000', 'CA1030', 'CA1031', 'CA1032', 'CA1034', 'CA1036', 'CA1040', + 'CA1043', 'CA1044', 'CA1051', 'CA1052', 'CA1062', 'CA1063', 'CA1064', + 'CA1065', 'CA1303', 'CA1305', 'CA1307', 'CA1401', 'CA1507', 'CA1707', + 'CA1710', 'CA1715', 'CA1716', 'CA1717', 'CA1720', 'CA1721', 'CA1724', + 'CA1801', 'CA1806', 'CA1810', 'CA1812', 'CA1815', 'CA1816', 'CA1822', + 'CA1825', 'CA1827', 'CA1829', 'CA2000', 'CA2007', 'CA2101', 'CA2200', + 'CA2207', 'CA2208', 'CA2214', 'CA2225', 'CA2227', 'SA0001', 'SA1000', + 'SA1001', 'SA1002', 'SA1003', 'SA1004', 'SA1005', + 'SA1006', 'SA1007', 'SA1008', 'SA1009', 'SA1010', 'SA1011', 'SA1012', + 'SA1013', 'SA1014', 'SA1015', 'SA1016', 'SA1017', 'SA1018', 'SA1019', + 'SA1020', 'SA1021', 'SA1022', 'SA1023', 'SA1024', 'SA1025', 'SA1026', + 'SA1027', 'SA1028', 'SA1100', 'SA1101', 'SA1102', 'SA1103', 'SA1104', + 'SA1105', 'SA1106', 'SA1107', 'SA1108', 'SA1109', 'SA1110', 'SA1111', + 'SA1112', 'SA1113', 'SA1114', 'SA1115', 'SA1116', 'SA1117', 'SA1118', + 'SA1119', 'SA1120', 'SA1121', 'SA1122', 'SA1123', 'SA1124', 'SA1125', + 'SA1126', 'SA1127', 'SA1128', 'SA1129', 'SA1130', 'SA1131', 'SA1132', + 'SA1133', 'SA1134', 'SA1135', 'SA1136', 'SA1137', 'SA1138', 'SA1139', + 'SA1200', 'SA1201', 'SA1202', 'SA1203', 'SA1204', 'SA1205', 'SA1206', + 'SA1207', 'SA1208', 'SA1209', 'SA1210', 'SA1211', 'SA1212', 'SA1213', + 'SA1214', 'SA1215', 'SA1216', 'SA1217', 'SA1300', 'SA1301', 'SA1302', + 'SA1303', 'SA1304', 'SA1305', 'SA1306', 'SA1307', 'SA1308', 'SA1309', + 'SA1310', 'SA1311', 'SA1312', 'SA1313', 'SA1314', 'SA1400', 'SA1401', + 'SA1402', 'SA1403', 'SA1404', 'SA1405', 'SA1406', 'SA1407', 'SA1408', + 'SA1409', 'SA1410', 'SA1411', 'SA1412', 'SA1413', 'SA1500', 'SA1501', + 'SA1502', 'SA1503', 'SA1504', 'SA1505', 'SA1506', 'SA1507', 'SA1508', + 'SA1509', 'SA1510', 'SA1511', 'SA1512', 'SA1513', 'SA1514', 'SA1515', + 'SA1516', 'SA1517', 'SA1518', 'SA1519', 'SA1520', 'SA1600', 'SA1601', + 'SA1602', 'SA1603', 'SA1604', 'SA1605', 'SA1606', 'SA1607', 'SA1608', + 'SA1609', 'SA1610', 'SA1611', 'SA1612', 'SA1613', 'SA1614', 'SA1615', + 'SA1616', 'SA1617', 'SA1618', 'SA1619', 'SA1620', 'SA1621', 'SA1622', + 'SA1623', 'SA1624', 'SA1625', 'SA1626', 'SA1627', 'SA1628', 'SA1629', + 'SA1630', 'SA1631', 'SA1632', 'SA1633', 'SA1634', 'SA1635', 'SA1636', + 'SA1637', 'SA1638', 'SA1639', 'SA1640', 'SA1641', 'SA1642', 'SA1643', + 'SA1644', 'SA1645', 'SA1646', 'SA1647', 'SA1648', 'SA1649', 'SA1650', + 'SA1651'] + + efl_stylecop_data = configuration_data() + watched_styles = [] + severity_styles = get_option('dotnet-stylecop-severity') + if get_option('dotnet-stylecop') == '*' + watched_styles = styles + elif get_option('dotnet-stylecop') != '' + s = get_option('dotnet-stylecop').to_upper().split(',') + foreach cc : s + if cc.startswith('CA') or cc.startswith('SA') + watched_styles += cc + endif + endforeach + endif + + foreach s : styles + if s in watched_styles + efl_stylecop_data.set('@0@'.format(s), '<Rule Id="@0@" Action="@1@"/>'.format(s, severity_styles)) + else + efl_stylecop_data.set('@0@'.format(s), '<Rule Id="@0@" Action="None"/>'.format(s)) + endif + endforeach + + ca_ruleset = configure_file(input : 'ca.ruleset.in', + output : 'ca.ruleset', + configuration : efl_stylecop_data) + dotnet = find_program('dotnet') - warning('Dotnet support is still experimental.') lib_csproj_conf_data = configuration_data() @@ -160,6 +223,7 @@ if (get_option('dotnet')) lib_csproj_conf_data.set('NETSTANDARD_VERSION', dotnet_standard_version) lib_csproj_conf_data.set('BINDING_SRC', meson.current_source_dir()) + lib_csproj_conf_data.set('CA_RULESET', join_paths(meson.build_root(), '@0@'.format(ca_ruleset))) lib_csproj_conf_data.set('EFL_VERSION', meson.project_version()) if get_option('mono-beta') @@ -173,7 +237,7 @@ if (get_option('dotnet')) configuration: lib_csproj_conf_data) efl_mono = custom_target('efl_mono', - input: mono_generator_target + mono_files + [efl_src] + [lib_csproj], + input: mono_generator_target + mono_files + [efl_src] + [lib_csproj] + [ca_ruleset], output: 'efl_sharp.dll', build_by_default: true, command: [dotnet, |