Commit a5bc3cef authored by jan.koester's avatar jan.koester
Browse files

Merge branch 'gtk-desktop': C++20 library and libc pieces for Node.js 26 / V8 14

parents 575e100c ff43d343
Loading
Loading
Loading
Loading
+1 −1
Changes for build-chroot.sh: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -147,7 +147,7 @@ declare -A FILES_DIRS=(
# tarball is %{name}-%{version}.tar.gz with that top directory.
declare -A GIT_SOURCES=(
    [libjson-c]="https://github.com/json-c/json-c.git json-c-0.18-20240915"
    [libbrotli]="https://github.com/google/brotli.git v1.1.0"
    [libbrotli]="https://github.com/google/brotli.git v1.2.1"
    [libcmdplus]="$TUXIST_GIT/jan.koester/libcmdplus.git"
    [libuuidp]="$TUXIST_GIT/tuxist/uuidplus.git"
    [libnetplus]="$TUXIST_GIT/jan.koester/libnetplus.git"
+80 −0
Changes for include/cxx/__hash_buckets: 80 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2026, Jan Koester jan.koester@gmx.net
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 * Neither the name of the <organization> nor the
 *      names of its contributors may be used to endorse or promote products
 *      derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/


#pragma once

/* The bucket array of the unordered containers, allocated through the
 * container's allocator (real gap: V8's ZoneUnorderedMap/Set, whose
 * memory must come from the zone). It also carries that allocator: the
 * containers rebind it for their nodes, so swapping the buckets swaps
 * the allocator with the nodes it owns. A vector<P>-shaped subset:
 * size(), operator[], swap(). */

#include <stddef.h>
#include <utility>
#include <memory>

namespace std __attribute__((__visibility__("default"))) {

template<class P, class Alloc>
class __hash_buckets {
public:
    typedef typename allocator_traits<Alloc>::template rebind_alloc<P> allocator_type;
private:
    typedef allocator_traits<allocator_type> _T;
    [[no_unique_address]] allocator_type _a;
    P* _p = nullptr;
    size_t _n = 0;
    void _init(size_t n, P v) {
        _p = _T::allocate(_a, n);
        for (size_t i = 0; i < n; i++) _p[i] = v;
        _n = n;
    }
public:
    __hash_buckets(size_t n, P v) : _a() { _init(n, v); }
    template<class A>
    __hash_buckets(size_t n, P v, const A& a) : _a(a) { _init(n, v); }
    __hash_buckets(const __hash_buckets& o) : _a(_T::select_on_container_copy_construction(o._a)) {
        _init(o._n, P());
        for (size_t i = 0; i < _n; i++) _p[i] = o._p[i];
    }
    __hash_buckets& operator=(const __hash_buckets&) = delete;
    ~__hash_buckets() { if (_p) _T::deallocate(_a, _p, _n); }

    size_t size() const noexcept { return _n; }
    P& operator[](size_t i) noexcept { return _p[i]; }
    const P& operator[](size_t i) const noexcept { return _p[i]; }
    const allocator_type& alloc() const noexcept { return _a; }
    void swap(__hash_buckets& o) noexcept {
        std::swap(_a, o._a);
        std::swap(_p, o._p);
        std::swap(_n, o._n);
    }
};

}
+293 −0
Changes for include/cxx/__iterator_concepts: 293 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2026, Jan Koester jan.koester@gmx.net
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 * Neither the name of the <organization> nor the
 *      names of its contributors may be used to endorse or promote products
 *      derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/


#pragma once

/* The C++20 iterator concepts and associated types ([iterator.concepts],
 * real gap: V8 constrains its templates with std::forward_iterator,
 * std::contiguous_iterator and friends). ITER_CONCEPT(I) is
 * I::iterator_concept when present, else iterator_traits<I>::
 * iterator_category; pointers are contiguous. Simplified where the
 * standard needs common_reference (not provided here):
 * indirectly_readable only checks that the associated types exist. */

#include <stddef.h>
#include <type_traits>
#include <concepts>
#include <__iterator_tags>
#include <__iterator_base>
#include <__identity>

#if defined(__cpp_concepts) && __cpp_concepts >= 201907L

namespace std __attribute__((__visibility__("default"))) {

namespace __itc {
    template<class T> using _with_ref = T&;
    template<class T> concept _can_reference = requires { typename _with_ref<T>; };
    template<class T> concept _dereferenceable = requires(T& t) { { *t } -> _can_reference; };
    template<class T> concept _has_difference_type = requires { typename T::difference_type; };
    template<class T> concept _has_value_type = requires { typename T::value_type; };
    template<class T> concept _has_element_type = requires { typename T::element_type; };
    template<class T> concept _traits_has_difference = requires { typename iterator_traits<T>::difference_type; };
    template<class T> concept _traits_has_value = requires { typename iterator_traits<T>::value_type; };
}

template<class> struct incrementable_traits {};
template<class T> requires is_object_v<T>
struct incrementable_traits<T*> { using difference_type = ptrdiff_t; };
template<class T>
struct incrementable_traits<const T> : incrementable_traits<T> {};
template<__itc::_has_difference_type T>
struct incrementable_traits<T> { using difference_type = typename T::difference_type; };
template<class T>
    requires (!__itc::_has_difference_type<T> &&
              requires(const T& a, const T& b) { { a - b } -> integral; })
struct incrementable_traits<T> {
    using difference_type = make_signed_t<decltype(declval<T>() - declval<T>())>;
};

namespace __itc {
    template<class T> struct _cond_value_type {};
    template<class T> requires is_object_v<T>
    struct _cond_value_type<T> { using value_type = remove_cv_t<T>; };
}
template<class> struct indirectly_readable_traits {};
template<class T>
struct indirectly_readable_traits<T*> : __itc::_cond_value_type<T> {};
template<class I> requires is_array_v<I>
struct indirectly_readable_traits<I> { using value_type = remove_cv_t<remove_extent_t<I>>; };
template<class I>
struct indirectly_readable_traits<const I> : indirectly_readable_traits<I> {};
template<__itc::_has_value_type T> requires (!__itc::_has_element_type<T>)
struct indirectly_readable_traits<T> : __itc::_cond_value_type<typename T::value_type> {};
template<__itc::_has_element_type T> requires (!__itc::_has_value_type<T>)
struct indirectly_readable_traits<T> : __itc::_cond_value_type<typename T::element_type> {};
template<__itc::_has_value_type T> requires __itc::_has_element_type<T>
struct indirectly_readable_traits<T> {};
template<__itc::_has_value_type T>
    requires (__itc::_has_element_type<T> &&
              same_as<remove_cv_t<typename T::element_type>, remove_cv_t<typename T::value_type>>)
struct indirectly_readable_traits<T> : __itc::_cond_value_type<typename T::value_type> {};

namespace __itc {
    template<class I> struct _diff { using type = typename incrementable_traits<I>::difference_type; };
    template<class I> requires (_traits_has_difference<I> &&
                                !is_void_v<typename iterator_traits<I>::difference_type>)
    struct _diff<I> { using type = typename iterator_traits<I>::difference_type; };
    template<class I> struct _value { using type = typename indirectly_readable_traits<I>::value_type; };
    template<class I> requires _traits_has_value<I>
    struct _value<I> { using type = typename iterator_traits<I>::value_type; };
}

template<class I> using iter_difference_t = typename __itc::_diff<remove_cvref_t<I>>::type;
template<class I> using iter_value_t = typename __itc::_value<remove_cvref_t<I>>::type;
template<__itc::_dereferenceable T> using iter_reference_t = decltype(*declval<T&>());

namespace ranges {
namespace __iter_move {
    struct _fn {
        template<class T> requires __itc::_dereferenceable<remove_reference_t<T>>
        constexpr decltype(auto) operator()(T&& t) const noexcept(noexcept(*static_cast<T&&>(t))) {
            if constexpr (is_lvalue_reference_v<decltype(*static_cast<T&&>(t))>)
                return std::move(*static_cast<T&&>(t));
            else
                return *static_cast<T&&>(t);
        }
    };
}
inline namespace __cpo { inline constexpr __iter_move::_fn iter_move{}; }
}

template<__itc::_dereferenceable T>
    requires requires(T& t) { { ranges::iter_move(t) } -> __itc::_can_reference; }
using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<T&>()));

template<class In>
concept indirectly_readable = requires {
    typename iter_value_t<remove_cvref_t<In>>;
    typename iter_reference_t<remove_cvref_t<In>>;
    typename iter_rvalue_reference_t<remove_cvref_t<In>>;
} && requires(const remove_cvref_t<In> in) {
    { *in } -> same_as<iter_reference_t<remove_cvref_t<In>>>;
};

template<indirectly_readable T>
using iter_common_reference_t = common_reference_t<iter_reference_t<T>, iter_value_t<T>&>;

template<class Out, class T>
concept indirectly_writable = requires(Out&& o, T&& t) {
    *o = std::forward<T>(t);
    *std::forward<Out>(o) = std::forward<T>(t);
};

template<class I>
concept weakly_incrementable = movable<I> && requires(I i) {
    typename iter_difference_t<I>;
    requires signed_integral<iter_difference_t<I>>;
    { ++i } -> same_as<I&>;
    i++;
};

template<class I>
concept incrementable = regular<I> && weakly_incrementable<I> && requires(I i) {
    { i++ } -> same_as<I>;
};

template<class I>
concept input_or_output_iterator = requires(I i) { { *i } -> __itc::_can_reference; } &&
    weakly_incrementable<I>;

template<class S, class I>
concept sentinel_for = semiregular<S> && input_or_output_iterator<I> &&
    __weakly_equality_comparable_with<S, I>;

template<class S, class I>
inline constexpr bool disable_sized_sentinel_for = false;

template<class S, class I>
concept sized_sentinel_for = sentinel_for<S, I> &&
    !disable_sized_sentinel_for<remove_cv_t<S>, remove_cv_t<I>> &&
    requires(const I& i, const S& s) {
        { s - i } -> same_as<iter_difference_t<I>>;
        { i - s } -> same_as<iter_difference_t<I>>;
    };

namespace __itc {
    template<class I> concept _has_concept = requires { typename I::iterator_concept; };
    template<class I> struct _concept {};
    template<class I> requires (!is_pointer_v<I> && !_has_concept<I> &&
                                requires { typename iterator_traits<I>::iterator_category; })
    struct _concept<I> { using type = typename iterator_traits<I>::iterator_category; };
    template<class I> requires (!is_pointer_v<I> && _has_concept<I>)
    struct _concept<I> { using type = typename I::iterator_concept; };
    template<class T> struct _concept<T*> { using type = contiguous_iterator_tag; };
    template<class I> using _iter_concept = typename _concept<I>::type;

    template<class P> constexpr auto _to_address(P* p) noexcept { return p; }
    template<class P> constexpr auto _to_address(const P& p) noexcept
        -> decltype(_to_address(p.operator->())) { return _to_address(p.operator->()); }
}

template<class I>
concept input_iterator = input_or_output_iterator<I> && indirectly_readable<I> &&
    requires { typename __itc::_iter_concept<I>; } &&
    derived_from<__itc::_iter_concept<I>, input_iterator_tag>;

template<class I, class T>
concept output_iterator = input_or_output_iterator<I> && indirectly_writable<I, T> &&
    requires(I i, T&& t) { *i++ = std::forward<T>(t); };

template<class I>
concept forward_iterator = input_iterator<I> &&
    derived_from<__itc::_iter_concept<I>, forward_iterator_tag> &&
    incrementable<I> && sentinel_for<I, I>;

template<class I>
concept bidirectional_iterator = forward_iterator<I> &&
    derived_from<__itc::_iter_concept<I>, bidirectional_iterator_tag> &&
    requires(I i) {
        { --i } -> same_as<I&>;
        { i-- } -> same_as<I>;
    };

template<class I>
concept random_access_iterator = bidirectional_iterator<I> &&
    derived_from<__itc::_iter_concept<I>, random_access_iterator_tag> &&
    totally_ordered<I> && sized_sentinel_for<I, I> &&
    requires(I i, const I j, const iter_difference_t<I> n) {
        { i += n } -> same_as<I&>;
        { j + n } -> same_as<I>;
        { n + j } -> same_as<I>;
        { i -= n } -> same_as<I&>;
        { j - n } -> same_as<I>;
        { j[n] } -> same_as<iter_reference_t<I>>;
    };

template<class I>
concept contiguous_iterator = random_access_iterator<I> &&
    derived_from<__itc::_iter_concept<I>, contiguous_iterator_tag> &&
    is_lvalue_reference_v<iter_reference_t<I>> &&
    same_as<iter_value_t<I>, remove_cvref_t<iter_reference_t<I>>> &&
    requires(const I& i) {
        { __itc::_to_address(i) } -> same_as<add_pointer_t<iter_reference_t<I>>>;
    };

/* indirect callable concepts, used by the constrained algorithms */
template<class F, class I>
concept indirectly_unary_invocable = indirectly_readable<I> && copy_constructible<F> &&
    invocable<F&, iter_value_t<I>&> && invocable<F&, iter_reference_t<I>>;
template<class F, class I>
concept indirectly_regular_unary_invocable = indirectly_unary_invocable<F, I>;
template<class F, class I>
concept indirect_unary_predicate = indirectly_readable<I> && copy_constructible<F> &&
    predicate<F&, iter_value_t<I>&> && predicate<F&, iter_reference_t<I>>;
template<class F, class I1, class I2>
concept indirect_binary_predicate = indirectly_readable<I1> && indirectly_readable<I2> &&
    copy_constructible<F> && predicate<F&, iter_reference_t<I1>, iter_reference_t<I2>>;
template<class F, class I1, class I2 = I1>
concept indirect_equivalence_relation = indirectly_readable<I1> && indirectly_readable<I2> &&
    copy_constructible<F> && equivalence_relation<F&, iter_reference_t<I1>, iter_reference_t<I2>>;
template<class F, class I1, class I2 = I1>
concept indirect_strict_weak_order = indirectly_readable<I1> && indirectly_readable<I2> &&
    copy_constructible<F> && strict_weak_order<F&, iter_reference_t<I1>, iter_reference_t<I2>>;

template<class F, class... Is>
    requires (indirectly_readable<Is> && ...) && invocable<F, iter_reference_t<Is>...>
using indirect_result_t = invoke_result_t<F, iter_reference_t<Is>...>;

template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
struct projected {
    using value_type = remove_cvref_t<indirect_result_t<Proj&, I>>;
    indirect_result_t<Proj&, I> operator*() const;
};
template<weakly_incrementable I, class Proj>
struct incrementable_traits<projected<I, Proj>> { using difference_type = iter_difference_t<I>; };

template<class In, class Out>
concept indirectly_movable = indirectly_readable<In> && indirectly_writable<Out, iter_rvalue_reference_t<In>>;
template<class In, class Out>
concept indirectly_copyable = indirectly_readable<In> && indirectly_writable<Out, iter_reference_t<In>>;
template<class I1, class I2 = I1>
concept indirectly_swappable = indirectly_readable<I1> && indirectly_readable<I2> &&
    requires(const I1 i1, const I2 i2) { std::swap(*i1, *i2); };
template<class I1, class I2, class R, class P1 = identity, class P2 = identity>
concept indirectly_comparable = indirect_binary_predicate<R, projected<I1, P1>, projected<I2, P2>>;

/* sentinels */
struct default_sentinel_t {};
inline constexpr default_sentinel_t default_sentinel{};
struct unreachable_sentinel_t {
    template<weakly_incrementable I>
    friend constexpr bool operator==(unreachable_sentinel_t, const I&) noexcept { return false; }
};
inline constexpr unreachable_sentinel_t unreachable_sentinel{};

}

#endif
+61 −0
Changes for include/cxx/__ranges_fwd: 61 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2026, Jan Koester jan.koester@gmx.net
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 * Neither the name of the <organization> nor the
 *      names of its contributors may be used to endorse or promote products
 *      derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/


#pragma once

/* The pieces of <ranges> that views and borrowed ranges elsewhere
 * specialize: enable_borrowed_range, view_base, view_interface (declared)
 * and enable_view. <string_view> and <span> include this to mark
 * themselves views, without <ranges> itself. Written with builtins so it
 * needs no other header. */

#if defined(__cpp_concepts) && __cpp_concepts >= 201907L

namespace std __attribute__((__visibility__("default"))) {
namespace ranges {

template<class T> inline constexpr bool enable_borrowed_range = false;

struct view_base {};

template<class D> requires __is_class(D) && __is_same(D, __remove_cv(D))
class view_interface;

namespace __r {
    template<class T> void _is_vi(const T&, const view_interface<T>&);
    template<class T> concept _derived_from_view_interface = requires(const T& t) { __r::_is_vi(t, t); };
}

template<class T> inline constexpr bool enable_view =
    (__is_base_of(view_base, T) && __is_convertible(const volatile T*, const volatile view_base*)) ||
    __r::_derived_from_view_interface<T>;

}
}

#endif
+85 −14

File changed.

Preview size limit exceeded, changes collapsed.

Loading