Commit Graph

2741 Commits

Author SHA1 Message Date
Timon Kruiper
b18a7297c5 Kernel: Move ScopedCritical.cpp to Kernel base directory
This file does not contain any architecture specific implementations,
so we can move it to the Kernel base directory. Also update the relevant
include paths.
2022-12-29 19:32:20 -07:00
Sam Atkins
feb0eb9309 AK: Fix constructing ErrorOr from ErrorOr of a related type
Mark other ErrorOr types as friends, and fix a typo in the &&
constructor, so that we can create an ErrorOr<Core::Object> from an
ErrorOr<GUI::Widget>. Also, add some requires() clauses to these
constructors so the error messages are clearer.
2022-12-28 22:34:00 -05:00
Arda Cinar
bbaf86fb46 AK: Add a forgiving_base64_decode helper
According to the specification at
https://infra.spec.whatwg.org/#forgiving-base64
2022-12-28 21:15:02 +01:00
Nico Weber
57126a0d3c AK: Make BigEndian<> and LittleEndian<> work with enum classes 2022-12-28 20:13:12 +00:00
Andreas Kling
c0e3bdd51b AK: Remove ARCH(I386) macro 2022-12-28 11:53:41 +01:00
Liav A
feeb25bcee AK: Remove i686 support 2022-12-28 11:53:41 +01:00
Florian Cramer
af2ffcaba8 AK: Make StringUtils::matches() handle escaping correctly
Previously any backslash and the character following it were ignored.
This commit adds a fall through to match the character following the
backslash without checking whether it is "special".
2022-12-27 07:28:25 +03:30
Nico Weber
8932b28b8a AK: Mark Error::from_ functions as [[nodiscard]]
Prevents mistakes like the one fixed in #16672.
2022-12-26 13:56:13 -05:00
Timothy Flynn
d2a304ae87 AK: Specialize TypeList for Variant types
This allows callers to use the following semantics:

    using MyVariant = Variant<Empty, int>;

    template<typename T>
    size_t size() { return TypeList<T>::size; }

    auto s = size<MyVariant>();

This will be needed for an upcoming IPC change, which will result in us
knowing the Variant type, but not the underlying variadic types that the
Variant holds.
2022-12-26 09:36:16 +01:00
Alec Murphy
da4067a75f AK: Remove tilde from URL::PercentEncodeSet::EncodeURI 2022-12-26 04:51:55 +03:30
Timothy Flynn
4b4b15adb1 AK: Rearrange Error's members to reduce its size by 8 bytes
This shrinks sizeof(Error) from 32 bytes to 24 bytes, which in turn will
shrink sizeof(ErrorOr<T>) by the same amount (in cases where sizeof(T)
is less than sizeof(Error)).
2022-12-22 14:13:56 -05:00
Sam Atkins
29733e65f8 AK+Everywhere: Replace all Bitmap::must_create() uses with ::create()
Well, *someone* has to add some more FIXMEs to keep FIXME Roulette
going. :^)
2022-12-22 15:48:53 +01:00
Sam Atkins
bed5961fc2 AK: Rename Bitmap::try_create() to ::create()
This is step 1 to removing `must_create()`.
2022-12-22 15:48:53 +01:00
Karol Kosek
25fa485dfb AK: Calculate elapsed days in human_readable_time() 2022-12-21 08:41:34 +00:00
Agustin Gianni
9a2ee5a9dd AK: Add DeprecatedString::find_last(StringView)
This adds the the method DeprecatedString::find_last() as wrapper for
StringUtils::find_last for the StringView type.
2022-12-20 11:24:05 +01:00
Jelle Raaijmakers
25f2e4981c AK: Stop using DeprecatedString in Base64 encoding 2022-12-20 10:34:19 +01:00
Jelle Raaijmakers
99c1b634fc AK: Stop using DeprecatedString in UUID 2022-12-20 10:34:19 +01:00
Andreas Kling
f11e6beca8 AK: Use __has_builtin() in Checked.h
Instead of avoiding overflow-checking builtins with AK_COMPILER_CLANG,
we can use the preprocessor's __has_builtin() mechanism to check if
they are available.
2022-12-19 09:29:12 -05:00
Lenny Maiorani
f2336d0144 AK+Everywhere: Move custom deleter capability to OwnPtr
`OwnPtrWithCustomDeleter` was a decorator which provided the ability
to add a custom deleter to `OwnPtr` by wrapping and taking the deleter
as a run-time argument to the constructor. This solution means that no
additional space is needed for the `OwnPtr` because it doesn't need to
store a pointer to the deleter, but comes at the cost of having an
extra type that stores a pointer for every instance.

This logic is moved directly into `OwnPtr` by adding a template
argument that is defaulted to the default deleter for the type. This
means that the type itself stores the pointer to the deleter instead
of every instance and adds some type safety by encoding the deleter in
the type itself instead of taking a run-time argument.
2022-12-17 16:00:08 -05:00
Eli Youngs
950b36f95d AK: Add a try_ensure() method to HashMap 2022-12-16 10:41:56 -07:00
Eli Youngs
a2024cfb69 AK: Support popping an arbitrary element from a HashTable 2022-12-16 10:41:56 -07:00
Timothy Flynn
d28c9ba054 AK: Synchronize explicit instantiations of to_int and to_uint
1. Ensure long and long long are instantiated for to_int.
2. Ensure long and long long are not instantiated for to_uint.
2022-12-16 10:06:26 +01:00
Lucas CHOLLET
34c13eff11 AK: Add OwnPtrWithCustomDeleter
This class is a smart pointer that let you provide a custom deleter to
free the pointer.

It is quite primitive compared to other smart pointers but can still be
useful when interacting with C types that provides a custom `free()`
function.
2022-12-15 13:38:13 +00:00
kleines Filmröllchen
026cc3d4b9 AK: Add Span to Array conversion function 2022-12-15 00:21:00 -07:00
Poseydon42
bdd7531bf5 AK: Create relative path even if prefix is not an ancestor of the path 2022-12-14 15:11:03 +00:00
Ali Mohammad Pur
b367da592c AK: Bring back the AK_DONT_REPLACE_STD #define
This was removed in a910961f37d1da9dafb6385e348266746354cf98 in favour
of the more general USING_AK_GLOBALLY #define, but Ladybird (and
probably other projects) depend on the smaller hammer to include STL
headers and keep the USING_AK_GLOBALLY behaviour, so put it back and
preserve its behaviour.
2022-12-14 12:56:01 +01:00
Ali Mohammad Pur
f96a3c002a Everywhere: Stop shoving things into ::std and mentioning them as such
Note that this still keeps the old behaviour of putting things in std by
default on serenity so the tools can be happy, but if USING_AK_GLOBALLY
is unset, AK behaves like a good citizen and doesn't try to put things
in the ::std namespace.

std::nothrow_t and its friends get to stay because I'm being told that
compilers assume things about them and I can't yeet them into a
different namespace...for now.
2022-12-14 11:44:32 +01:00
Ali Mohammad Pur
72514d6915 AK: Make Types.h not export its functions if !USING_AK_GLOBALLY 2022-12-14 11:44:32 +01:00
kleines Filmröllchen
5b4818df22 AK: Make Variant's index type public
This will allow the IPC system to use the exact required index type,
saving transmission space, once it can send variants.
2022-12-13 10:24:59 -05:00
Ali Mohammad Pur
ad120606fd AK: Fix build with !USING_AK_GLOBALLY
A couple headers expected names to be in the global namespace, qualify
those names to make sure they're resolved even when the names are not
exported.
One header placed its functions in the global namespace, move those to
the AK namespace to make the concepts resolve.
2022-12-13 08:09:56 +03:30
Ali Mohammad Pur
d987ddc0ee AK: Actually don't include <unistd.h> for windows in Platform.h
I got the conditions wrong last time, oops :^)
2022-12-12 17:01:16 +00:00
Arda Cinar
1cdd3bb74f AK: Add a shuffle utility function
This implements a shuffle function in AK/Random.h which works on any
container with size() and curly brace operators. It uses fisher-yates
shuffle.
2022-12-12 16:23:03 +00:00
Lucas CHOLLET
6c83bd8fd4 AK: Introduce the DerivedFrom concept 2022-12-12 16:21:39 +00:00
Ali Mohammad Pur
4aa70a07ca AK: Don't use <random> on windows for ::rand()
This is the same as the libc function, just use the libc function.
2022-12-12 15:05:48 +00:00
Ali Mohammad Pur
06816deb78 AK: Don't try to include <unistd.h> on windows for PAGE_SIZE 2022-12-12 15:05:48 +00:00
kleines Filmröllchen
b81a457de5 AK: Change quicksort comments to standard // style 2022-12-12 15:03:57 +00:00
Marc Luqué
22f472249d AK: Introduce cutoff to insertion sort for Quicksort
Implement insertion sort in AK. The cutoff value 7 is a magic number
here, values [5, 15] should work well. Main idea of the cutoff is to
reduce recursion performed by quicksort to speed up sorting
of small partitions.
2022-12-12 15:03:57 +00:00
kleines Filmröllchen
bbb256e8b5 AK: Introduce Indexable concept
This was dearly missing and can be used in many existing templates.
2022-12-12 15:03:57 +00:00
Ali Mohammad Pur
fc805e8f03 AK: Specialise AK::is() for NNRP<T>
This is used by the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur
18bc88b806 AK: Add an identity implementation of StringView::from_string_literal()
This is required for the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur
e591c604de AK: Add Optional-like value()/has_value() getters to WeakPtr 2022-12-11 20:44:54 +03:30
Ali Mohammad Pur
c373c2deb0 AK: Allow constructing WeakPtr<T> using OptionalNone
The Jakt runtime requires this.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur
96b36203a2 AK: Add Optional::lazy_emplace(Callable)
This makes it possible to emplace using a given function instead of
passing constructor arguments.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur
0ed9fe3864 AK: Allow non-ascii characters to be printed
This keeps the FIXME, as well as the assertion.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur
08fc42002c AK: Format the contents of NNRP<T> if T is formattable 2022-12-11 20:44:54 +03:30
Ali Mohammad Pur
ff038f306a AK: Ignore "alternative" formatting of StringView instead of crashing
Jakt implements this in a different way, but it's a noop for
StringViews anyway.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur
1cc8cdcd23 AK: Add a Error::__jakt_from_string_literal(StringView) factory function
Note that Jakt only allows StringView creation from string literals, so
none of the invariants in the class are broken by this (if used only
from within Jakt).
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur
537924a8d0 AK: Let ErrorOr<T, E> expose its result/error types
`ErrorOr<T, E>::ResultType` can now refer to `T`.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur
c3b4b0e88b AK: Add support for modulo to Checked<T>
This is used by the Jakt runtime.
2022-12-11 20:44:54 +03:30
Ali Mohammad Pur
cc0b970d81 AK: Allow Optional<T> to be constructed by OptionalNone()
This is needed by the Jakt runtime too.
2022-12-11 20:44:54 +03:30