Commit Graph

2721 Commits

Author SHA1 Message Date
Andreas Kling
79c77debb0 AK: Don't destructively re-encode query strings in the URL parser
We were decoding and then re-encoding the query string in URLs.
This round-trip caused us to lose information about plus ('+')
ASCII characters encoded as "%2B".
2022-04-10 01:37:45 +02:00
Andreas Kling
3724ce765e AK+LibWeb: Encode ' ' as '+' in application/x-www-form-urlencoded
This matches what the URL and HTML specifications ask us to do.
2022-04-10 01:37:45 +02:00
GeekFiftyFive
832920c003 AK+LibHTTP: Revert prior change to percent encode plus signs
A change was made prior to percent encode plus signs in order to fix an
issue with the Google cookie consent page.

Unforunately, this was treating a symptom of a problem and not the root
cause and is incorrect behavior.
2022-04-08 20:44:49 +02:00
Sam Atkins
c0ca6e470f AK+Userland: Rename Array::front/back to first/last
This is the name that is used for every other collection type so let's
be consistent.
2022-04-06 14:31:52 +02:00
kleines Filmröllchen
7b145d810a AK: Add const version of Vector::first_matching 2022-04-06 12:47:50 +02:00
kleines Filmröllchen
ff8ca811c7 AK: Add find_first_index to NonnullPtrVector that strips smart pointer
When we want to use the find_first_index that base Vector provides, we
need to provide an element of the real contained type. That's impossible
for OwnPtr, however, and even with RefPtr there might be instances where
we have a raw reference to the object we want to find, but no smart
pointer. Therefore, overloading this function (with an identical body,
the magic is done by the find_index templatization) with `T const&` as a
parameter allows there use cases.
2022-04-06 12:47:50 +02:00
Timothy Flynn
9e5abec6f1 AK: Invalidate UTF-8 encoded code points larger than U+10ffff
On oss-fuzz, the LibJS REPL is provided a file encoded with Windows-1252
with the following contents:

    /ô¡°½/

The REPL assumes the input file is UTF-8. So in Windows-1252, the above
is represented as [0x2f 0xf4 0xa1 0xb0 0xbd 0x2f]. The inner 4 bytes are
actually a valid UTF-8 encoding if we only look at the most significant
bits to parse leading/continuation bytes. However, it decodes to the
code point U+121c3d, which is not a valid code point.

This commit adds additional validation to ensure the decoded code point
itself is also valid.
2022-04-05 00:14:29 +01:00
Ali Mohammad Pur
188207ed79 AK: Make Vector<T>::{first,last}_matching() return Optional<T&>
These functions are _very_ misleading, as `first()` and `last()` return
references, but `{first,last}_matching()` return copies of the values.
This commit makes it so that they now return Optional<T&>, eliminating
the copy and the confusion.
2022-04-04 12:48:31 +02:00
Ali Mohammad Pur
33e27c545e AK: Return Optional<T&> from HashMap<..., T>::get()
This avoids a useless copy of the value, as most of the users (except
one) actually just need a reference to the value.
2022-04-04 12:48:31 +02:00
Ali Mohammad Pur
1a74895680 AK: Return Optional<ConstPeekType> for HashMap::get() const
While the previous implementation always copied the object, returning a
non-const reference to a const object is not valid.
2022-04-04 12:48:31 +02:00
Ali Mohammad Pur
221ecf17d3 AK: Allow Optional<T&> to exist
This implements Optional<T&> as a T*, whose presence has been missing
since the early days of Optional.
As a lot of find_foo() APIs return an Optional<T> which imposes a
pointless copy on the underlying value, and can sometimes be very
misleading, with this change, those APIs can return Optional<T&>.
2022-04-04 12:48:31 +02:00
Idan Horowitz
1787d94907 AK: Add begin_from(V&) APIs to IntrusiveRedBlackTree
This method exploits the fact that the values themselves hold the tree
pointers, and as a result this let's us skip the O(logn) traversal down
to the matching Node for a Key-Value pair.
2022-04-04 00:16:11 +02:00
Tim Schumacher
8209c2b570 AK: Add StringView::copy_characters_to_buffer() 2022-04-03 19:15:14 +02:00
kleines Filmröllchen
7a0cd6793e AK: Add non-const iterator for CircularQueue 2022-04-03 09:49:08 -07:00
serenityosrocks
4a6a7cf3c8 AK: Add generic sincos solution for non-x86 platforms 2022-04-03 00:31:41 +01:00
Ben Maxwell
0f2c1f804e AK: Add last() utility function to Span 2022-04-02 21:50:41 +02:00
GeekFiftyFive
737f5b26b7 AK+LibHTTP: Ensure plus signs are percent encoded in query string
Adds a new optional parameter 'reserved_chars' to
AK::URL::percent_encode. This new optional parameter allows the caller
to specify custom characters to be percent encoded. This is then used
to percent encode plus signs by HttpRequest::to_raw_request.
2022-04-02 18:43:15 +02:00
Hendiadyoin1
5ba5a6615d AK: Add vector variants of sqrt and rsqrt 2022-04-02 18:37:38 +02:00
Hendiadyoin1
b1db1e4e4f AK: Add rsqrt and a SSE specific implementation for sqrt 2022-04-02 18:37:38 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
kleines Filmröllchen
09a12247fb AK: Use bucket states with special bit patterns in HashTable
This simplifies some of the bucket state handling code, as there's now
an easy way of checking the basic category of bucket state.
2022-03-31 12:06:13 +02:00
kleines Filmröllchen
49d29c8298 AK: Rehash HashTable in-place instead of shrinking
As seen on TV, HashTable can get "thrashed", i.e. it has a bunch of
deleted buckets that count towards the load factor. This means that hash
tables which are large enough for their contents need to be resized.
This was fixed in 9d8da16 with a workaround that shrinks the HashTable
back down in these cases, as after the resize and re-hash the load
factor is very low again. However, that's not a good solution. If you
insert and remove repeatedly around a size boundary, you might get
frequent resizes, which involve frequent re-allocations.

The new solution is an in-place rehashing algorithm that I came up with.
(Do complain to me, I'm at fault.) Basically, it iterates the buckets
and re-hashes the used buckets while marking the deleted slots empty.
The issue arises with collisions in the re-hash. For this reason, there
are two kinds of used buckets during the re-hashing: the normal "used"
buckets, which are old and are treated as free space, and the
"re-hashed" buckets, which are new and treated as used space, i.e. they
trigger probing. Therefore, the procedure for relocating a bucket's
contents is as follows:
- Locate the "real" bucket of the contents with the hash. That bucket is
  the starting point for the target bucket, and the current (old) bucket
  is the bucket we want to move.
- While we still need to move the bucket:
  - If we're the target, something strange happened last iteration or we
    just re-hashed to the same location. We're done.
  - If the target is empty or deleted, just move the bucket. We're done.
  - If the target is a re-hashed full bucket, we probe by double-hashing
    our hash as usual. Henceforth, we move our target for the next
    iteration.
  - If the target is an old full bucket, we swap the target and to-move
buckets. Therefore, the bucket to move is a the correct location and the
former target, which still needs to find a new place, is now in the
bucket to move. So we can just continue with the loop; the target is
re-obtained from the bucket to move. This happens for each and every
bucket, though some buckets are "coincidentally" moved before their
point of iteration is reached. Either way, this guarantees full in-place
movement (even without stack storage) and therefore space complexity of
O(1). Time complexity is amortized O(2n) asssuming a good hashing
function.

This leads to a performance improvement of ~30% on the benchmark
introduced with the last commit.

Co-authored-by: Hendiadyoin1 <leon.a@serenityos.org>
2022-03-31 12:06:13 +02:00
kleines Filmröllchen
bcb8937898 AK: Merge HashTable bucket state into one enum
The hash table buckets had three different state booleans that are in
fact exclusive. In preparation for further states, this commit
consolidates them into one enum. This has the added benefit on not
relying on the compiler's boolean packing anymore; we definitely now
only need one byte for the bucket state.
2022-03-31 12:06:13 +02:00
safarp
704e1d13f4 AK: Allow printing wide characters using %ls modifier 2022-03-30 11:30:43 +04:30
Ali Mohammad Pur
67357fe984 LibXML: Add a fairly basic XML parser
Currently this can parse XML and resolve external resources/references,
and read a DTD (but not apply or verify its rules).
That's good enough for _most_ XHTML documents as the HTML 5 spec
enforces its own rules about document well-formedness, and does not make
use of XML DTDs (aside from a list of predefined entities).

An accompanying `xml` utility is provided that can read and dump XML
documents, and can also run the XML conformance test suite.
2022-03-28 23:11:48 +02:00
Ali Mohammad Pur
06cedf5bae AK: Add a 'OneOf' concept
Similar to 'SameAs', but for multiple types.
2022-03-28 23:11:48 +02:00
Ali Mohammad Pur
2a1a619eed AK: Display SourceLocation function name in color
It's much easier to spot the function name (which is what you often
expect) like this.
2022-03-28 23:11:48 +02:00
Ali Mohammad Pur
b3c18db463 AK: Add a 'is_not_any_of' similar to 'is_any_of' to GenericLexer
It's often useful to have the negated version, so instead of making a
local lambda for it, let's just add the negated form too.
2022-03-28 23:11:48 +02:00
Ali Mohammad Pur
e21fa158dd AK: Make Vector capable of holding forward-declared types
This is pretty useful for making trees.
2022-03-28 23:11:48 +02:00
Hendiadyoin1
6b20496758 AK: Add appendln helper to SourceGenerator 2022-03-28 23:08:08 +02:00
Hendiadyoin1
f6f7280fe3 AK: Explicitly move value String in SourceGenerator::set 2022-03-28 23:08:08 +02:00
Hendiadyoin1
14caecefb1 AK: Make SourceGenerator move constructible
This makes us able to return one from a function
2022-03-28 23:08:08 +02:00
Linus Groh
22308e52cf AK: Add an ArbitrarySizedEnum template
This is an enum-like type that works with arbitrary sized storage > u64,
which is the limit for a regular enum class - which limits it to 64
members when needing bit field behavior.

Co-authored-by: Ali Mohammad Pur <mpfard@serenityos.org>
2022-03-27 18:54:56 +02:00
Linus Groh
8b2361e362 AK: Add non-const DistinctNumeric::value() getter 2022-03-27 18:54:56 +02:00
Linus Groh
76e85ebbfc AK: Remove unused String.h include from UFixedBigInt.h
This makes it usable in the Kernel. :^)
2022-03-27 18:54:56 +02:00
Idan Horowitz
5626e1b324 LibWeb: Rename PARSER_DEBUG => HTML_PARSER_DEBUG
Since this macro was created we gained a couple more parsers in the
system :^)
2022-03-24 21:37:49 +01:00
Hendiadyoin1
820e03e8d4 AK: Add a case insensitive of is_one_of to String[View] 2022-03-21 10:48:17 +01:00
Sam Atkins
dfc02f9761 AK: Fix typo in warnln_if() 2022-03-19 11:01:49 -07:00
Sam Atkins
7e98c8eaf6 AK+Tests: Fix StringUtils::contains() being confused by repeating text
Previously, case-insensitively searching the haystack "Go Go Back" for
the needle "Go Back" would return false:

1. Match the first three characters. "Go ".
2. Notice that 'G' and 'B' don't match.
3. Skip ahead 3 characters, plus 1 for the outer for-loop.
4. Now, the haystack is effectively "o Back", so the match fails.

Reducing the skip by 1 fixes this issue. I'm not 100% convinced this
fixes all cases, but I haven't been able to find any cases where it
doesn't work now. :^)
2022-03-18 23:51:56 +00:00
Lenny Maiorani
4c5e9f5633 Everywhere: Deduplicate day/month name constants
Day and month name constants are defined in numerous places. This
pulls them together into a single place and eliminates the
duplication. It also ensures they are `constexpr`.
2022-03-18 23:48:50 +00:00
Timothy Flynn
31515a9147 AK: Mark the StringView user-defined literal as consteval
Even though the StringView(char*, size_t) constructor only runs its
overflow check when evaluated in a runtime context, the code generated
here could prevent the compiler from optimizing invocations from the
StringView user-defined literal (verified on Compiler Explorer).

This changes the user-defined literal declaration to be consteval to
ensure it is evaluated at compile time.
2022-03-18 19:56:50 +01:00
Andreas Kling
fc6b7fcd97 AK: Add const variant of Vector::in_reverse() 2022-03-18 15:18:48 +01:00
Lenny Maiorani
2844f7c333 Everywhere: Switch from EnableIf to requires
C++20 provides the `requires` clause which simplifies the ability to
limit overload resolution. Prefer it over `EnableIf`

With all uses of `EnableIf` being removed, also remove the
implementation so future devs are not tempted.
2022-03-17 22:15:42 -07:00
Michiel Visser
3d561abe15 AK: Add constant time equality and zero check to UFixedBigInt 2022-03-18 07:56:47 +03:30
Michiel Visser
590dcb0581 AK: UFixedBigInt add efficient multiplication with full result 2022-03-18 07:56:47 +03:30
Lenny Maiorani
5b59375a56 AK: Fix implicit and narrowing conversions in Base64 2022-03-16 16:19:53 +00:00
Lenny Maiorani
8d1d4d4f09 AK: Make static constexpr variables to avoid stack copy in Base64
Alphabet and lookup table are created and copied to the stack on each
call. Create them and store them in static memory.
2022-03-16 16:19:53 +00:00
Daniel Bertalan
e3eb68dd58 AK+Kernel: Avoid double memory clearing of HashTable buckets
Since the allocated memory is going to be zeroed immediately anyway,
let's avoid redundantly scrubbing it with MALLOC_SCRUB_BYTE just before
that.

The latest versions of gcc and Clang can automatically do this malloc +
memset -> calloc optimization, but I've seen a couple of places where it
failed to be done.

This commit also adds a naive kcalloc function to the kernel that
doesn't (yet) eliminate the redundancy like the userland does.
2022-03-15 11:56:46 +01:00
Hendiadyoin1
cd21e03225 AK+Everywhere: Add sincos and use it in some places
Calculating sin and cos at once is quite a bit cheaper than calculating
them individually.
x87 has even a dedicated instruction for it: `fsincos`.
2022-03-15 11:39:42 +01:00
Timothy Flynn
c12cfe83b7 AK: Allow creating a Vector from any Span of the same underlying type
This allows, for example, to create a Vector from a subset of another
Vector.
2022-03-14 16:33:15 +01:00
Brian Gianforcaro
390666b9fa AK: Add naive implementations of AK::timing_safe_compare
For security critical code we need to have some way of performing
constant time buffer comparisons.
2022-03-13 19:08:58 -07:00
Tim Schumacher
dd71754d10 AK: Properly parse unimplemented format length specifiers
This keeps us from stopping early and not rendering the argument at all.
2022-03-12 12:42:07 +03:30
Sam Atkins
2362cc2943 AK: Remove unused String[256] from JsonParser
This shrinks the JsonParser class from 2072 bytes to 24. :^)
2022-03-10 18:43:09 +01:00
Sam Atkins
a451810599 AK: Print a better error message when missing a SourceGenerator key
Previously, if you forgot to set a key on a SourceGenerator, you would
get this less-than-helpful error message:

> Generate_CSS_MediaFeatureID_cpp:
  /home/sam/serenity/Meta/Lagom/../../AK/Optional.h:174: T
  AK::Optional<T>::release_value() [with T = AK::String]: Assertion
  `m_has_value' failed.

Now, it instead looks like this:

> No key named `name:titlecase` set on SourceGenerator
  Generate_CSS_MediaFeatureID_cpp:
  /home/sam/serenity/Meta/Lagom/../../AK/SourceGenerator.h:44:
  AK::String AK::SourceGenerator::get(AK::StringView) const: Assertion
  `false' failed.
2022-03-09 23:06:30 +01:00
Federico Guerinoni
0aed2f0f86 AK: Add reverse iterator as member 2022-03-09 17:16:28 +01:00
Federico Guerinoni
f34fff852b AK: Implement wrapper for reverse range for loop
Now it is possible to use range for loop in reverse mode for a
container.
```
	for (auto item : in_reverse(vector))
```
2022-03-09 17:16:28 +01:00
Federico Guerinoni
a54e20d958 AK: Implement ReverseIterator for NonnullPtrVector 2022-03-09 17:16:28 +01:00
Federico Guerinoni
b0e74a3fd3 AK: Implement reverse iterator for Vector class 2022-03-09 17:16:28 +01:00
Federico Guerinoni
74650b4e32 AK: Add generic reverse iterator for containers 2022-03-09 17:16:28 +01:00
Tom
2f0e3da142 AK: Add IPv6Address class
This is the IPv6 counter part to the IPv4Address class and implements
parsing strings into a in6_addr and formatting one as a string. It
supports the address compression scheme as well as IPv4 mapped
addresses.
2022-03-08 23:05:44 +01:00
Vrins
73ade62d4f AK: Add float support for JsonValue and JsonObjectSerializer 2022-03-08 22:09:52 +01:00
Vrins
ae1cd4b448 AK: Add to_double() to JsonValue 2022-03-08 22:09:52 +01:00
Andreas Kling
9d8da1697e AK: Automatically shrink HashTable when removing entries
If the utilization of a HashTable (size vs capacity) goes below 20%,
we'll now shrink the table down to capacity = (size * 2).

This fixes an issue where tables would grow infinitely when inserting
and removing keys repeatedly. Basically, we would accumulate deleted
buckets with nothing reclaiming them, and eventually deciding that we
needed to grow the table (because we grow if used+deleted > limit!)

I found this because HashTable iteration was taking a suspicious amount
of time in Core::EventLoop::get_next_timer_expiration(). Turns out the
timer table kept growing in capacity over time. That made iteration
slower and slower since HashTable iterators visit every bucket.
2022-03-07 00:08:22 +01:00
Andreas Kling
eb829924da AK: Remove return value from HashTable::remove() and HashMap::remove()
This was only used by remove_all_matching(), where it's no longer used.
2022-03-07 00:08:22 +01:00
Andreas Kling
623bdd8b6a AK: Simplify HashTable::remove_all_matching()
Just walk the table from start to finish, deleting buckets as we go.
This removes the need for remove() to return an iterator, which is
preventing me from implementing hash table auto-shrinking.
2022-03-07 00:08:22 +01:00
Linus Groh
1719862d12 LibWeb: Hide some debug logging behind CANVAS_RENDERING_CONTEXT_2D_DEBUG
This can be quite noisy and isn't generally useful information.
2022-03-04 23:03:29 +01:00
Peter Ross
34108547b6 AK: Print NaN and infinite numbers in PrintfImplementation 2022-03-02 11:40:37 +01:00
Lucas CHOLLET
39bfc48ea7 AK: Add Time::from_ticks()
This helper allows Time to be constructed from a tick count and a ticks
per second value.
2022-02-28 20:09:37 +01:00
Timur Sultanov
406b3fc3fe AK: Correctly process precision modifiers in printf 2022-02-28 14:08:24 +01:00
kleines Filmröllchen
98058f7efe AK: Add FixedPoint base 2 logarithm
The log base 2 is implemented using the binary logarithm algorithm
by Clay Turner (see the link in the comment)
2022-02-28 13:59:31 +01:00
kleines Filmröllchen
30002c2ccb AK: Add bit shift to FixedPoint 2022-02-28 13:59:31 +01:00
kleines Filmröllchen
5d6e3441fe AK: Fix FixedPoint to integral comparisons
Add tests to ensure that the fixed point numbers compare correctly to
integrals
2022-02-28 13:59:31 +01:00
Idan Horowitz
feb00b7105 Everywhere: Make JSON serialization fallible
This allows us to eliminate a major source of infallible allocation in
the Kernel, as well as lay down the groundwork for OOM fallibility in
userland.
2022-02-27 20:37:57 +01:00
Idan Horowitz
9da8c78133 AK: Add a try variant of StringBuilder::append_escaped_for_json
This will allow us to make a fallible version of the JSON serializers.
2022-02-27 20:37:57 +01:00
kleines Filmröllchen
7e18e6e37b AK: Skip over initial empty chunks in DisjointChunks
This will be caught by new test cases: when the initial chunk is empty,
a dereference before calling operator++ on the iterator will crash as
the initial chunk's size is never checked.
2022-02-27 00:11:14 +03:30
kleines Filmröllchen
4ec599aae5 AK: Make DisjointChunks support FixedArray
This extracts the shatter_chunk logic, because it needs to be different
for FixedArray.
2022-02-27 00:11:14 +03:30
kleines Filmröllchen
ee9eef1fa8 AK: Make DisjointChunk::append move the new chunk
Previously, although we were taking a moved chunk, we still copied it
into our chunk list. This makes DisjointChunk compatible with containers
that don't have a copy constructor but a move constructor.
2022-02-27 00:11:14 +03:30
kleines Filmröllchen
6e5bf7ac6f AK: Export DisjointSpans into the global namespace
I think we just forgot when we added it.
2022-02-27 00:11:14 +03:30
kleines Filmröllchen
75eb5e7984 AK: Add at() indexing methods to FixedArray 2022-02-27 00:11:14 +03:30
kleines Filmröllchen
09df8f812a AK: Allow creating a FixedArray from an initializer list 2022-02-27 00:11:14 +03:30
kleines Filmröllchen
65f34504e9 AK: Add FixedArray::is_empty()
This also exists on Vector, and although it's less needed here, it's
perfectly reasonable to have.
2022-02-27 00:11:14 +03:30
Arne Elster
b7110c2a34 AK: Add constructor to create Span from Array
It's a convenience constructor. But it also seems more consistent
to allow a Span being made from both raw and managed arrays.
2022-02-26 16:01:26 +01:00
Arne Elster
6a0cac7cdb AK: Array can tell its inner type
Array should be able to tell the type of the elements it contains.
2022-02-26 16:01:26 +01:00
Andreas Kling
f2663f477f AK: Ignore whitespace while decoding base64
This matches how other implementations behave.

1% progression on ACID3. :^)
2022-02-25 19:54:13 +01:00
Andreas Kling
dd7eb3d6d8 AK: Add String::split_view(Function<bool(char)>)
This allows you to split around a custom separator, and enables
expressive code like this:

    string.split_view(is_ascii_space);
2022-02-25 19:38:31 +01:00
Linus Groh
1752f7720e AK: Add forward declaration for Utf8CodePointIterator 2022-02-23 21:53:30 +00:00
Linus Groh
b253bca807 AK: Add optional format string parameter to String{,Builder}::join()
Allow specifying a custom format string that's being used for each item
instead of hardcoding "{}".
2022-02-23 21:53:30 +00:00
Linus Groh
f8ff8c8dd6 AK: Add Traits<Span<T>>::hash() 2022-02-23 21:53:30 +00:00
kleines Filmröllchen
604309327e AK: Add the Fundamental concept 2022-02-23 00:42:49 +00:00
kleines Filmröllchen
7418bdb85f AK: Prevent Atomic with complex types
This would throw some really weird linker errors, so let's prevent it
from happening instead!
2022-02-23 00:42:49 +00:00
Max Wipfli
d29d9462e9 AK: Suppress clang-tidy warning on TODO()
This adds a NOLINT directive to the definition of the TODO() macro.
clang-tidy wants the assert replaced with a static_assert, since the
macro simply resolves to assert(false). This is obviously nonsensical,
since we want the code to still compile even with TODO().

The same fix has already been implemented for VERIFY_NOT_REACHED().
2022-02-21 19:01:16 +02:00
Andreas Kling
4b900bc100 AK: Add fast path in String::trim() and String::trim_whitespace()
If the trimmed string would be the entire string, just return *this
instead of creating a new StringImpl.
2022-02-19 14:45:59 +01:00
Andreas Kling
2dd3b54827 AK: Make CaseInsensitiveStringTraits allocation-free
Instead of calling String::to_lowercase(), do case-insensitive hashing
and comparison.
2022-02-19 14:45:59 +01:00
Gunnar Beutner
7a65bd8efb AK: Don't use x86 assembly when building for non-x86 targets
This allows Lagom to be built successfully for Apple M1.

Fixes #12644.
2022-02-19 13:13:22 +02:00
Ben Abraham
ae346cff6b LibWeb: Add partially functioning Worker API
Add a partial implementation of HTML5 Worker API.
Messages can be sent from the inner context externally.
2022-02-17 22:45:21 +01:00
Sam Atkins
1a4dd47d5f AK: VERIFY inside release_value_but_fixme_should_propagate_errors()
While the code did already VERIFY that the ErrorOr holds a value, this
was done by Variant, so the error message was just that `has<T>()` is
false. This is less helpful than I would like, especially if backtraces
are not working and this is all you have to go on. Adding this extra
VERIFY means the assertion message (`!is_error()`) is easier to
understand.
2022-02-16 19:49:41 -05:00
Idan Horowitz
cec669a89a AK: Exclude StringUtils String APIs from the Kernel
These APIs are only used by userland, and String is OOM-infallible,
so let's just ifdef it out of the Kernel.
2022-02-16 22:21:37 +01:00
Idan Horowitz
4c6a1f4db2 AK: Exclude StringView String APIs from the Kernel
These APIs are only used by userland, and String is OOM-infallible,
so let's just ifdef it out of the Kernel.
2022-02-16 22:21:37 +01:00
Idan Horowitz
8f093e91e0 AK: Exclude StringBuilder String APIs from the Kernel
These APIs are only used by userland, and String is OOM-infallible,
so let's just ifdef it out of the Kernel.
2022-02-16 22:21:37 +01:00
Idan Horowitz
43e5c326e2 AK: Exclude JsonValue String APIs from the Kernel
These APIs are only used by userland, and String is OOM-infallible,
so let's just ifdef it out of the Kernel.
2022-02-16 22:21:37 +01:00
Idan Horowitz
e95470702e AK: Use string_view() instead of to_string() in Formatter<wchar_t>
This let's us avoid a heap allocation.
2022-02-16 22:21:37 +01:00
Idan Horowitz
b22cb40565 AK: Exclude GenericLexer String APIs from the Kernel
These APIs are only used by userland, and String is OOM-infallible,
so let's just ifdef it out of the Kernel.
2022-02-16 22:21:37 +01:00
Idan Horowitz
3219ce3d61 AK: Return KString instead of String from encode_hex in the Kernel
This let's us propagate allocation errors from this API.
2022-02-16 22:21:37 +01:00
Idan Horowitz
316fa0c3f3 AK+Kernel: Specialize Trie for NNOP<KString> and use it in UnveilNode
This let's us avoid the infallible String allocations.
2022-02-16 22:21:37 +01:00
Idan Horowitz
7f44e54ad6 AK+Kernel: Return KString from UUID::to_string() in the Kernel
This lets us safely handle allocation failure.
2022-02-16 22:21:37 +01:00
Idan Horowitz
9277d2dce2 AK+Kernel: Return KString from MACAddress::to_string() in the Kernel
This lets us safely handle allocation failure.
2022-02-16 22:21:37 +01:00
Idan Horowitz
6098ffa120 AK+Kernel: Return KString from IPv4Address::to_string() in the Kernel
This lets us safely handle allocation failure.
2022-02-16 22:21:37 +01:00
serenitydev
23c72c6728 AK: Fix userland parsing of rounded floating point numbers
Parse JSON floating point literals properly,
No longer throwing a SyntaxError when the decimal portion
of the number exceeds the capacity of u32.

Added tests to AK/TestJSON and LibJS/builtins/JSON/JSON.parse
2022-02-16 07:22:51 -05:00
Ali Mohammad Pur
a1cb2c371a AK+Kernel: OOM-harden most parts of Trie
The only part of Unveil that can't handle OOM gracefully is the
String::formatted() use in the node metadata.
2022-02-15 18:03:02 +02:00
Ali Mohammad Pur
80e6198563 AK: Conditionally disable a few variant ctors/assignments
We shouldn't let copy/move ctors or assignments be instantiated if the
assignee type does not have a copy/move constructor (even if they're not
used anywhere).
2022-02-15 18:03:02 +02:00
Ali Mohammad Pur
7a58c510e5 AK: Add a 'SpecializationOf' concept
The counterpart to the IsSpecializationOf<...> template.
2022-02-15 18:03:02 +02:00
Idan Horowitz
b32cf33a23 Kernel: Remove make_weak_ptr()
New users of WeakPtr in the kernel should use try_make_weak_ptr instead
2022-02-13 23:02:57 +01:00
Idan Horowitz
98c20b65cc AK+Kernel: Add an OOM-fallible try variant make_weak_ptr()
This will allow us to propagate allocation errors that may be raised by
the construction of the WeakLink.
2022-02-13 23:02:57 +01:00
Idan Horowitz
d6ea6c39a7 AK+Kernel: Rename try_make_weak_ptr to make_weak_ptr_if_nonnull
This matches the likes of the adopt_{own, ref}_if_nonnull family and
also frees up the name to allow us to eventually add OOM-fallible
versions of these functions.
2022-02-13 23:02:57 +01:00
Andreas Kling
c74b6c06a5 AK: Use ByteBuffer::append(u8) in StringBuilder single-char append 2022-02-13 14:44:36 +01:00
Andreas Kling
22f6f0fc9e AK: Don't call memcpy() in ByteBuffer::append(u8)
We can emit way nicer code for the just-append-a-single-byte case.
2022-02-13 14:44:36 +01:00
Idan Horowitz
871a53db76 AK: Make Bitmap construction OOM-fallible 2022-02-11 17:49:46 +02:00
davidot
fdbfe85a87 AK: Clear minimum when removing last node of RedBlackTree 2022-02-10 14:09:39 +00:00
davidot
2bddf157b1 AK: Fix RedBlackTree::find_smallest_not_below_iterator
Before this was incorrectly assuming that if the current node `n` was at
least the key and the left child of `n` was below the key that `n` was
always correct.
However, the right child(ren) of the left child of `n` could still be
at least the key.

Also added some tests which produced the wrong results before this.
2022-02-10 14:09:39 +00:00
Lenny Maiorani
e5d178528d AK: Change static base36 character map to function-local constexpr
Static variables consume memory and can be subject to less
optimization. This variable is only used in 1 place and can be moved
into the function and make it non-static.
2022-02-10 10:22:54 +00:00
Ali Mohammad Pur
e7dea10381 AK: Add RBTree::find_smallest_above_iterator(Key) 2022-02-09 20:57:41 +00:00
Ali Mohammad Pur
cb7becb067 LibTLS+RequestServer: Add an option to dump TLS keys to a log file
This file allows us to decrypt TLS messages in wireshark, which can help
immensely in debugging network stuff :^)
2022-02-09 21:23:25 +01:00
Lenny Maiorani
138d54e595 AK+Kernel: Alphabetize debug macros
This is not ASCII-betical because `_` comes after all the uppercase
characters. Treating `_` as a ` ` (space character), these lists are
now alphabetical.
2022-02-09 17:59:19 +00:00
Hendiadyoin1
fbb798f98c AK: Move integral log2 and exp to IntegerMath.h 2022-02-06 17:52:33 +00:00
Hendiadyoin1
9ba9691d19 AK: Use integral power for FixedPoint formatting
This removes an ifdef for the Kernel
2022-02-06 17:52:33 +00:00
Hendiadyoin1
581c23dc55 AK: Introduce IntegralMath.h starting with pow<I> 2022-02-06 17:52:33 +00:00
Andreas Kling
5dd4b3eaaa LibWeb: Put ResolvedCSSStyleDeclaration debug spam behind a macro
Blowing up the debug console with a fajillion FIXME's whenever you
navigate in the web inspector is no fun.
2022-02-06 16:22:58 +01:00
Ali Mohammad Pur
9cf1c382df AK: Replace 'consteval' with 'constexpr' in some Variant helpers
CLion and/or clangd didn't like the consteval and highlighted visit() as
an error, just replace it with constexpr as it makes no difference here.
2022-02-06 13:10:10 +01:00
Liav A
54845c4bf2 AK: Remove commented-out code from Bitmap container
Instead, add a note to explain that there's a const variant of data()
method in the parent BitmapView class.
2022-02-05 18:14:12 +00:00
Idan Horowitz
de7b5279cb AK: Make Vector::data() ALWAYS_INLINE
This was showing up in profiles of Browser, and it really shouldn't be.
2022-02-05 16:48:14 +01:00
Idan Horowitz
18b98f8c28 AK: Convert the try_make<T> factory function to use ErrorOr
This allows more ergonomic memory allocation failure related error
checking using the TRY macro.
2022-02-03 23:33:20 +01:00
Idan Horowitz
ba0a2a3e2f AK: Hide the infallible make<T> factory function from the Kernel
This function has no users, nor should it ever be used in the kernel,
as all allocation failures in the Kernel should be explicitly checked.
2022-02-03 23:33:20 +01:00
Idan Horowitz
7933a9b6c8 AK: Stop using the make<T> factory function in Trie
This function is infallible, and so we would like to exclude it from
the Kernel, which includes this header.
2022-02-03 23:33:20 +01:00
Idan Horowitz
a65bbbdb71 Kernel: Convert try_make_ref_counted to use ErrorOr
This allows more ergonomic memory allocation failure related error
checking using the TRY macro.
2022-02-03 23:33:20 +01:00
Idan Horowitz
be4c144524 AK: Support formatting Vectors with any inline_capacity
The default Vector type has its inline capacity set to 0, which means
any Vector with non-zero inline capacity was unformattable.
2022-02-03 23:33:20 +01:00
Andreas Kling
e86ab57078 AK+Kernel+LibSanitizer: Store "ubsan-is-deadly" flag as Atomic<bool> 2022-02-03 16:11:26 +01:00
Idan Horowitz
44e8c05c67 AK: Add a Utf16View::code_unit_offset_of(Utf16CodePointIterator) helper
This helper can be used to used to retrieve the code unit offset of an
active Utf16CodePointIterator efficiently.
2022-01-31 21:05:04 +02:00
Timothy Flynn
6efbafa6e0 Everywhere: Update copyrights with my new serenityos.org e-mail :^) 2022-01-31 18:23:22 +00:00
Timothy Flynn
94a346c9b9 AK: Add is_ascii_[binary,octal]_digit to CharacterTypes 2022-01-31 17:50:54 +00:00
Andreas Kling
51e5cc4e13 AK: Remove thread safety gunk from userspace WeakPtr
The implicit thread safety stuff is only needed by the kernel version
of WeakPtr, as userspace already makes no guarantees about this.
2022-01-31 16:19:23 +01:00
Daniel Bertalan
8473f6caee AK+Tests: Make null strings compare less than non-null strings
This behavior regressed in ca58c71faa.

Fixes #12213
2022-01-30 17:23:02 +00:00
Daniel Bertalan
1a4aad9b7e AK: Implement String's comparison operators in terms of StringView's 2022-01-29 23:08:27 +01:00
Daniel Bertalan
5b3ba2d9ad AK: Implement FlyString's comparison operators in terms of StringView's 2022-01-29 23:08:27 +01:00
Daniel Bertalan
ca58c71faa AK: Implement all comparison operators for StringView 2022-01-29 23:08:27 +01:00
Idan Horowitz
9b0d90a71d AK: Support using custom comparison operations for hash compatible keys 2022-01-29 23:01:23 +02:00
Lenny Maiorani
b0a54518d8 Everywhere: Remove redundant inline keyword
`constexpr` implies `inline` so when both are used it is redundant.
2022-01-29 21:45:17 +02:00
Pankaj Raghav
24c66b8442 AK: Fix log2 calculation for Integer
For a `N` bit integer X, the log2 calculation should be as follows:
(N - 1) - ctz(X)
2022-01-29 17:41:06 +02:00
Pankaj Raghav
61027e5303 AK: Add is_power_of_2 helper 2022-01-29 17:41:06 +02:00
Liav A
308e54bc19 AK+Kernel: Implement UUID mixed endianness support
This is being used by GUID partitions so the first three dash-delimited
fields of the GUID are stored in little endian order but the last two
fields are stored in big endian order, hence it's a representation which
is mixed.
2022-01-29 13:35:54 +02:00
kleines Filmröllchen
cfb8eeebe8 AK: Allow constructing a JsonArray from any array-like type 2022-01-28 23:40:25 +01:00
kleines Filmröllchen
2f631f7dc0 AK: Allow constructing a JsonValue from a StringView explicitly
The next commit will destroy overload detection otherwise, so let's add
this constructor. Currently, the same work is already done implicitly
through the implicit `String(StringView)` constructor.
2022-01-28 23:40:25 +01:00
kleines Filmröllchen
07977ad94c AK: Introduce the ArrayLike concept
The ArrayLike type concept focuses on array-like data accesses. This
means the ability to randomly index, obtain size information, as well as
being able to expose the storage pointer. The last two already have the
standard APIs `size` and `data`, respectively.

The ArrayLike concept should always be fulfilled by Vector, FixedArray
and Array as the three main array-like types. C-style arrays themselves
of course can't fulfil ArrayLike (which could be considered ironic), but
as we don't use them much anyways this isn't a problem.
2022-01-28 23:40:25 +01:00
Ali Mohammad Pur
bf82d9b5d7 AK: Simplify Variant's explicit overload detection mechanism a bit
This also allows us to remove the max-64-visitors restriction, and so
removes that assertion.
2022-01-28 00:50:04 +03:30
Timothy Flynn
01395169dc AK: Export the SameAs concept 2022-01-27 16:27:00 +00:00
Idan Horowitz
85437abfad Kernel: Support try-inserting RedBlackTree entry values by reference 2022-01-26 22:05:34 +00:00
Idan Horowitz
6e38076b48 AK: Use x86 specific fast path in fast_u32{fill, copy} on x86_64 2022-01-26 01:16:43 +02:00
Idan Horowitz
67ce9e28a5 AK: Standardize the behaviour of GenericLexer::consume_until overloads
Before this commit all consume_until overloads aside from the Predicate
one would consume (and ignore) the stop char/string, while the
Predicate overload would not, in order to keep behaviour consistent,
the other overloads no longer consume the stop char/string as well.
2022-01-25 13:41:09 +03:30
Idan Horowitz
d49d2c7ec4 AK: Add a consume_until(StringView) overload to GenericLexer
This allows us to skip a strlen call.
2022-01-25 13:41:09 +03:30
James Puleo
10b25d2a57 AK: Implement HashTable::try_ensure_capacity, as used in HashMap
This was used in `HashMap::try_ensure_capacity`, but was missing from
`HashTable`s implementation. No one had used
`HashMap::try_ensure_capacity` before so it went unnoticed!
2022-01-25 09:17:22 +01:00
Sam Atkins
c388a879d7 AK+Userland: Make AK::decode_base64 return ErrorOr 2022-01-24 22:36:09 +01:00
Sam Atkins
f590cd1850 AK+Userland: Make AK::decode_hex() return ErrorOr
This lets us propagate the reason why it failed up to the caller. :^)
2022-01-24 22:36:09 +01:00
Sam Atkins
45cf40653a Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr
Apologies for the enormous commit, but I don't see a way to split this
up nicely. In the vast majority of cases it's a simple change. A few
extra places can use TRY instead of manual error checking though. :^)
2022-01-24 22:36:09 +01:00
Tom
c468a9cc2d AK: Add FixedPoint cast operator for up/downcasting to other sizes
This enables casting between different size FixedPoint variables or
constructing them from other sized FixedPoint values.
2022-01-23 22:45:21 +00:00
Tom
06fc72ca0c AK: Fix warnings when using FixedPoint with a precision >= 32 bits 2022-01-23 22:45:21 +00:00
Tom
f021baf255 AK: Add Formatter<FixedPoint<...>> without floating point
Rather than casting the FixedPoint to double, format the FixedPoint
directly. This avoids using floating point instruction, which in
turn enables this to be used even in the kernel.
2022-01-23 22:45:21 +00:00
Tom
77b3230c80 AK: Loosen FixedPoint template contraints and forward-declare it
Because AK/Concepts.h includes AK/Forward.h and concepts cannot be
forward declared, slightly losen the FixedPoint template arguments
so that we can forward declare it in AK/Forward.h
2022-01-23 22:45:21 +00:00
Idan Horowitz
a3a4d0aea2 AK: Make Optional<T> explicitly constructible from Optional<U>
As long as T is constructible from U. This allows us to avoid patterns
like `abc.has_value() ? Optional<U>(abc.value()) : Optional<U>()`.
2022-01-23 18:53:42 +02:00
Timothy Flynn
b873a222d7 AK: Implement AK::Time's seconds_since_epoch_to_year without LibM
In order for this method to be used within LibC itself, avoid using the
floor() method from LibM, which is not available from within LibC. This
header similarly avoids other standard headers as well.
2022-01-23 12:48:26 +00:00
Michel Hermier
e986ce961a AK: Avoid impl initialization before assignment in Stringconstructor 2022-01-23 13:29:12 +01:00
Nico Weber
fd7de68d07 LibHTTP+AK: Rename CNETWORKJOB_DEBUG to NETWORKJOB_DEBUG 2022-01-23 00:45:22 +00:00
Nico Weber
a17b2248f2 LibHTTP+AK: Rename CHTTPJOB_DEBUG to HTTPJOB_DEBUG 2022-01-23 00:45:22 +00:00
Nico Weber
6d532649d4 RequestServer+AK: Move happy-path logging behind REQUESTSERVER_DEBUG
vdbgln() was responsible for ~10% of samples on pv's flamegraph for
RequestServer (under request_did_finish) when loading github.com in
Browser and recording a whole-system profile. This makes that almost
completely disappear.
2022-01-22 01:28:01 +00:00
davidot
0b89dbc529 Meta: Add JS_MODULE_DEBUG define flag 2022-01-22 01:21:18 +00:00
kleines Filmröllchen
caeb8fc691 LibCore: Introduce BigEndianInputBitStream
BigEndianInputBitStream is the Core::Stream API's bitwise input stream
for big endian input data. The functionality and bitwise read API is
almost unchanged from AK::BitStream, except that this bit stream only
supports big endian operations.

As the behavior for mixing big endian and little endian reads on
AK::BitStream is unknown (and untested), it was never done anyways. So
this was a good opportunity to split up big endian and little endian
reading.

Another API improvement from AK::BitStream is the ability to specify
the return type of the bit read function. Always needing to static_cast
the result of BitStream::read_bits_big_endian into the desired type is
adding a lot of avoidable noise to the users (primarily FlacLoader).
2022-01-22 01:13:42 +03:30
Idan Horowitz
7356110033 AK: Support setting with non copyable keys in HashMap 2022-01-21 16:27:21 +01:00
ForLoveOfCats
1d95fd5443 AK: Identify negative zero when parsing Json and represent with a double
Regardless of the backing type that the number would otherwise parse to,
if it is zero and the sign was supposed to be negative then it needs to
be a floating point number to represent the correct value.
2022-01-19 21:51:09 +00:00
Timothy Flynn
e9e8e2bdf4 AK: Add helper to convert an epoch time in seconds to a year 2022-01-19 21:20:41 +00:00
Timothy Flynn
bc719e7bac AK: Put an empty new line between function definitions in AK::Time
There was over 110 lines without a single line break, let's give our
eyes a break.
2022-01-19 21:20:41 +00:00
Idan Horowitz
404daa0e33 AK: Yield while waiting for another thread to create a strong ref 2022-01-19 01:28:13 +01:00
Idan Horowitz
aa29e38ad5 AK: Yield while waiting for another thread to initialize a Singleton 2022-01-19 01:28:13 +01:00
Lucas CHOLLET
b0d51a6f36 AK: Fix erroneous move operators for SinglyLinkedList
This patch provides a proper implementation of the move operator and
delete the move assignment operator.

Those operators were introduced in #11888
2022-01-19 00:13:56 +01:00
Timothy Flynn
b87e517deb AK: Remove now-unused AK::UnicodeUtils methods 2022-01-18 15:13:25 +00:00
Idan Horowitz
4774bed589 AK: Make Utf8View constexpr-constructible 2022-01-17 14:46:07 +00:00
Jelle Raaijmakers
11c807ebd1 LibGL+LibSoftGPU: Implement the stencil buffer
This implements an 8-bit front stencil buffer. Stencil operations are
SIMD optimized. LibGL changes include:

* New `glStencilMask` and `glStencilMaskSeparate` functions
* New context parameter `GL_STENCIL_CLEAR_VALUE`
2022-01-17 12:49:00 +01:00
Michel Hermier
cb3cc6ec27 AK: Remove kfree definition 2022-01-16 11:18:04 +01:00
Michel Hermier
9039f8fb0f AK: Remove kcalloc definition 2022-01-16 11:18:04 +01:00
Matt Jacobson
47e8d58553 AK: Fix logic in String::operator>(const String&)
Null strings should not compare greater than non-null strings.

Add tests for >, <, >=, and <= comparison involving null strings.
2022-01-16 11:08:23 +01:00
Idan Horowitz
8a879e205b AK: Mark the error branch of the TRY() macro as unlikely
This results in a measurable (and free!) 2% improvement in test-js
run time.
2022-01-16 02:01:23 +02:00
creator1creeper1
4869dda79f AK: Explicitly name types in Iterator.h
In this particular case, auto is a footgun, because we are very
certain about the type that we want to return. const-correctness
could have been violated (as Vector did), because Iterator did not
enforce that the returned pointer was actually const if the Iterator
was an Iterator over a const container.
2022-01-16 00:38:21 +03:30
creator1creeper1
6484d42933 AK: Make Vector more const-correct by using RemoveReference<T>
Methods marked as const should always only return Foo const&, never
Foo&. Previously, this only worked correctly with Foo, but not with
Foo&: If someone fetched a T const&, this would have been expanded
to Foo& const& which is just Foo&. Therefore, they were able to modify
the elements of the Vector, even though it was marked as const.
This commit fixes that by introducing VisibleType as an alias for
RemoveReference<T> and using it throughout Vector.

There are also other cases where we don't require a mutable reference
to the underlying type, only a const reference (for example in a find
operation). In these cases, we now also correctly expand the type
to Foo const&.
2022-01-16 00:38:21 +03:30
creator1creeper1
64778f9e69 AK: Add a constructor from Span for FixedArray
This is particularly useful in the Kernel, where the physical pages of
a VMObject are stored as a FixedArray but often passed around as a Span
from which a new FixedArray should be cloned.
2022-01-15 22:16:00 +02:00
creator1creeper1
0362b15895 AK: Add a constructor from C-style arrays for FixedArray
We really want to be able to construct FixedArray from a list of
non-copyable but movable objects. This constructor is useful for
such things.
2022-01-15 22:16:00 +02:00
Lucas CHOLLET
1222eba0fb AK: Explicitly define copy and assignment operator for SinglyLinkedList
Defined operators:
 - SinglyLinkedList(const SinglyLinkedList&) - deleted
 - SinglyLinkedList(SinglyLinkedList&&) - defaulted
 - SinglyLinkedList& operator=(const SinglyLinkedList&) - deleted
 - SinglyLinkedList& operator=(SinglyLinkedList&&) - defaulted
2022-01-15 01:44:12 +01:00
Timothy Flynn
820dc1fc53 AK: Use appropriate types in AK::Time::from_timestamp factory
Allow the provided year to be negative, and allow millisecond values
larger than 255.
2022-01-14 22:39:06 +01:00
kleines Filmröllchen
be6418cc50 Everywhere: Use my new serenityos.org e-mail :^) 2022-01-14 11:54:09 +01:00
Ali Mohammad Pur
95b8c1745a AK: Make Variant::visit() prefer overloads accepting T const& over T&
This makes the following code behave as expected:

    Variant<int, String> x { some_string() };
    x.visit(
        [](String const&) {}, // Expectation is for this to be called
        [](auto&) {});
2022-01-14 11:35:40 +03:30
Ali Mohammad Pur
9de33629da AK+Everywhere: Make Variant::visit() respect the Variant's constness
...and fix all the instances of visit() taking non-const arguments.
2022-01-14 11:35:40 +03:30
sin-ack
28063de488 AK: Add ByteBuffer::{must_,}get_bytes_for_writing()
This is useful for writing new data at the end of a ByteBuffer. For
instance, with the Stream API:

    auto pending_bytes = TRY(stream.pending_bytes());
    auto receive_buffer = TRY(buffer.get_bytes_for_writing(
        pending_bytes));
    TRY(stream.read(receive_buffer));
2022-01-13 15:16:12 +03:30
sin-ack
9569841589 AK: Use Error::from_errno in adopt_nonnull_own_or_enomem
This fails to build on Lagom otherwise.
2022-01-13 15:16:12 +03:30
kleines Filmröllchen
068aea660c AK: Explain why FixedArray has no move assignment 2022-01-13 11:17:44 +01:00
kleines Filmröllchen
594bbbf020 Tests: Test FixedArray completely
Except for tangential accessors such as data(), there is no more feature
of FixedArray that is untested after this large expansion of its test
cases. These tests, with the help of the new NoAllocationGuard, also
test the allocation contract that was fixated in the last commit.

Hopefully this builds confidence in future Kernel uses of FixedArray
as well as its establishment in the real-time parts of the audio
subsystem. I'm excited :^)
2022-01-13 11:17:44 +01:00
kleines Filmröllchen
1d144ed6fc AK: Remove clear() from FixedArray and fixate its allocation guarantees
FixedArray always *almost* had the following allocation guarantees:
There is (possibly) one allocation in the constructor and one (or more)
deallocation(s) in the destructor. No other operation allocates or
deallocates. With this removal of the public clear() method, which
nobody except the test used anyways, those guarantees are now completely
true and furthermore fixated with an explanatory comment.
2022-01-13 11:17:44 +01:00
kleines Filmröllchen
9bf2d0b718 AK: Disable NoAllocationGuard on Lagom
Because we don't have our LibC on Lagom, the allocation guard global
flag doesn't exist and NoAllocationGuard fails to build on Lagom.
Whoops. For now, just disable NoAllocationGuard's functionality here.
2022-01-13 11:17:44 +01:00
Andreas Kling
a702b6ec42 AK: Remove unnecessary null checks in RedBlackTree 2022-01-12 14:52:47 +01:00
Brian Gianforcaro
142e099001 AK: Implement StringView::for_each_split_view
StringView::for_each_split_view allows you to process the splits in a
StringView without needing to allocate a Vector<StringView> to store
each of the parts.

Since we migrated the implementation from the normal split_view path, we
can also re-implement split_view in terms of for_each_split_view.
2022-01-12 13:03:44 +01:00
Brian Gianforcaro
cd42f64bc7 AK: Rewrite StringView::split_view(char..), using StringView 2022-01-12 13:03:44 +01:00
Timothy Flynn
2b5840296a AK: Add AK::Time factory method to construct from individual time fields 2022-01-11 23:56:35 +01:00
Timothy Flynn
548643bcc9 AK: Redeclare a few AK::Time helpers as constexpr
This is to allow using these methods within an upcoming constexpr
factory method.
2022-01-11 23:56:35 +01:00
Andreas Kling
a4b4b358ff AK+Kernel: Remove one_ref_left() footgun
This mechanism was unsafe to use in any multithreaded context, since
the hook function was invoked on a raw pointer *after* decrementing
the local ref count.

Since we don't use it for anything anymore, let's just get rid of it.
2022-01-11 01:12:16 +01:00
Timothy Flynn
3dccaa39d8 AK: Define a traits helper for case-insensitive StringView hashing
Currently, we define a CaseInsensitiveStringTraits structure for String.
Using this structure for StringView involves allocating a String from
that view, and a second string to convert that intermediate string to
lowercase.

This defines CaseInsensitiveStringViewTraits (and the underlying helper
case_insensitive_string_hash) to avoid allocations.
2022-01-11 00:36:45 +01:00
kleines Filmröllchen
2f50d8f4d3 AK+LibC+LibPthread: Introduce NoAllocationGuard
NoAllocationGuard is an RAII stack guard that prevents allocations
while it exists. This is done through a thread-local global flag which
causes malloc to crash on a VERIFY if it is false. The guard allows for
recursion.

The intended use case for this class is in real-time audio code. In such
code, allocations are really bad, and this is an easy way of dynamically
enforcing the no-allocations rule while giving the user good feedback if
it is violated. Before real-time audio code is executed, e.g. in LibDSP,
a NoAllocationGuard is instantiated. This is not done with this commit,
as currently some code in LibDSP may still incorrectly allocate in real-
time situations.

Other use cases for the Kernel have also been added, so this commit
builds on the previous to add the support both in Userland and in the
Kernel.
2022-01-11 00:08:58 +01:00
Marcus Nilsson
4459cb33ed LibGUI+AK: Add DRAG_DEBUG opt and put drag operations behind dbgln_if
No need to have this enabled all the time.
2022-01-10 14:23:04 +01:00
Rafał Babiarz
0012c03eb5 AK: Added human_readable_time() method for "unsaved changes" dialogs 2022-01-09 20:25:48 -08:00
Stephan Unverwerth
f9c5c120f6 AK/SIMD: Suppress psabi warnings and add explanatory comment 2022-01-09 21:03:08 +01:00
Stephan Unverwerth
444a15bad3 AK: Add SIMDMath.h with vectorized version of math functions 2022-01-09 16:21:13 +03:30
Stephan Unverwerth
7adcdecc7b AK: Add SIMDExtras.h with SIMD related functions
Adds a header to AK with helper functions for writing vectorized code.

Co-authored-by: Hendiadyoin <leon2002.la@gmail.com>
2022-01-09 16:21:13 +03:30
Maciej
ad2551e6b8 AK: Add ByteBuffer::append(char) 2022-01-09 00:18:46 +01:00
creator1creeper1
f73afbb5ae AK: Reorder functions in FixedArray so that mutable comes before const 2022-01-08 22:54:05 +01:00
creator1creeper1
18a2685c6a AK: Reorder access in FixedArray so that m_size comes before m_elements 2022-01-08 22:54:05 +01:00
creator1creeper1
3c05261611 AK+Everywhere: Make FixedArray OOM-safe
FixedArray now doesn't expose any infallible constructors anymore.
Rather, it exposes fallible methods. Therefore, it can be used for
OOM-safe code.
This commit also converts the rest of the system to use the new API.
However, as an example, VMObject can't take advantage of this yet,
as we would have to endow VMObject with a fallible static
construction method, which would require a very fundamental change
to VMObject's whole inheritance hierarchy.
2022-01-08 22:54:05 +01:00
Andreas Kling
0e70759271 AK: Unbreak ref counting hooks in RefCounted
Same fix as 5871072ed3, but for userspace
this time. Regressed in c4a0f01b02.
2022-01-08 19:38:00 +01:00
Andreas Kling
c4a0f01b02 AK+Kernel: Use requires expression when invoking ref counting hooks
Replace some old-school template trickery with C++20 requires. :^)
2022-01-08 16:31:14 +01:00
mjz19910
10ec98dd38 Everywhere: Fix spelling mistakes 2022-01-07 15:44:42 +01:00
Schlufi
55a7738837 AK: Use a full-period xorshift PRNG for double_hash
The previous implementation had some pretty short cycles and two fixed
points (1711463637 and 2389024350). If two keys hashed to one of these
values insertions and lookups would loop forever.
This version is based on a standard xorshift PRNG with period 2**32-1.
The all-zero state is usually forbidden, so we insert it into the cycle
at an arbitrary location.
2022-01-07 12:34:44 +01:00
mjz19910
3102d8e160 Everywhere: Fix many spelling errors 2022-01-07 10:56:59 +01:00
Timothy Flynn
bb9db5937a AK: Add Time.h helper to compute the number of days since epoch 2022-01-05 20:05:12 +01:00
Timothy Flynn
0c75a14b4f AK: Move TimeSpecType concept inside the AK namespace
This is just to allow removing the 'clang-format off' directive. This
concept is only used within this header, so it doesn't need to be in the
global namespace.
2022-01-05 20:05:12 +01:00
Andreas Kling
558fb0a04a AK: Make Vector::remove_all_matching() return removal success
This matches the behavior of other remove_*_matching() functions.
2022-01-05 18:57:14 +01:00
Andreas Kling
5279a04c78 AK: Make Hash{Map,Table}::remove_all_matching() return removal success
These functions now return whether one or more entries were removed.
2022-01-05 18:57:14 +01:00
Andreas Kling
376e5ef912 AK: Add HashMap::remove_all_matching(predicate)
This removes all matching entries from a hash map in a single pass.
2022-01-05 18:57:14 +01:00
Andreas Kling
54cf42fac1 AK: Add HashTable::remove_all_matching(predicate)
This removes all matching entries from a table in a single pass.
2022-01-05 18:57:14 +01:00
Brian Gianforcaro
1a2aad287f AK: Disable Vector insert/empend/prepend + a append overload in Kernel
We have whittled away at the usages of these AK::Vector APIs in the
Kernel. This change disables them from being visible when building
the Kernel to make sure no new usages get added.
2022-01-05 14:04:18 +01:00
Brian Gianforcaro
48206be121 AK: Use MUST + try_empend so AK::Trie continues to compile in the kernel 2022-01-05 14:04:18 +01:00
Brian Gianforcaro
7d27798c8d AK: Use unchecked_append in AK::Stack, as we always validate the size
This removes one additional usage of Vector::append that stops us from
disabling it when compiling the Kernel.
2022-01-05 14:04:18 +01:00
Jelle Raaijmakers
8da0925d6d AK: Add mix 2022-01-04 17:48:28 +00:00
B0IIZZ
6124050187 AK: Fix UFixedBigInt comparison operators
Instead of using the specified type U like we want,
we were using the type T all along when comparing with
smaller integers. This is now fixed.
2022-01-04 06:01:22 +00:00
James Puleo
5b164e9934 AK: Include utility from the STD if we aren't replacing STD
If we didn't define our own `move` and `forward` and inject it into the
`std` namespace, then we would error just after trying to `using` those,
if no one has included it before. Now, we will include `utility` from
the STD if we aren't replacing the `std`.
2022-01-02 12:05:12 +01:00
Daniel Bertalan
1d2f78682b Kernel+AK: Eliminate a couple of temporary String allocations 2021-12-30 14:16:03 +01:00
Andreas Kling
ac7ce12123 Kernel: Remove the kmalloc_eternal heap :^)
This was a premature optimization from the early days of SerenityOS.
The eternal heap was a simple bump pointer allocator over a static
byte array. My original idea was to avoid heap fragmentation and improve
data locality, but both ideas were rooted in cargo culting, not data.

We would reserve 4 MiB at boot and only ended up using ~256 KiB, wasting
the rest.

This patch replaces all kmalloc_eternal() usage by regular kmalloc().
2021-12-28 21:02:38 +01:00
Andreas Kling
1c2aa7396d AK: Don't include AK::demangle() in KERNEL builds
This was not used anywhere in the kernel anyway.
2021-12-26 21:22:59 +01:00
Andreas Kling
8a51f64503 AK: Increase StringBuilder's inline buffer size from 128 to 256 bytes 2021-12-26 01:42:58 +01:00
Ali Mohammad Pur
986d63466e AK: Remove Variant<Ts...>::operator Variant<NewTs...>()
This is an interface to downcast(), which degrades errors into runtime
errors, and allows seemingly-correct-but-not-quite constructs like the
following to appear to compile, but fail at runtime:

    Variant<NonnullRefPtr<T>, U> foo = ...;
    Variant<RefPtr<T>, U> bar = foo;

The expectation here is that `foo` is converted to a RefPtr<T> if it
contains one, and remains a U otherwise, but in reality, the
NonnullRefPtr<T> variant is simply dropped on the floor, and the
resulting variant becomes invalid, failing the assertion in downcast().

This commit adds a Variant<Ts...>(Variant<NewTs...>) constructor that
ensures that no alternative can be left out at compiletime, for the
users that were using this interface for merely increasing the number of
alternatives (for instance, LibSQL's Value class).
2021-12-25 18:24:43 +03:30
Daniel Bertalan
2b1864c53a AK: Add missing Array.h include to CheckedFormatString.h
GCC 12 complains that iota_array is used before it's declared. GCC 11
works fine without it though.
2021-12-24 14:35:33 -08:00
Michel Hermier
4758dac218 AK: Make Disjoint*::is_empty() not call size
This is a raffinement of 49cbd4dcca.

Previously, the container was scanned to compute the size in the unhappy
path. Now, using `all_of` happy and unhappy path should be fast.
2021-12-24 05:55:34 -08:00
Michel Hermier
3a177b9209 AK: Add DisjointChunkc::ensure_capacity 2021-12-24 05:55:34 -08:00
Nick Johnson
08e4a1a4dc AK+Everywhere: Replace __builtin bit functions
In order to reduce our reliance on __builtin_{ffs, clz, ctz, popcount},
this commit removes all calls to these functions and replaces them with
the equivalent functions in AK/BuiltinWrappers.h.
2021-12-21 22:13:51 +01:00
Xavier Defrang
9e97823ff8 AK: Add convert_to_uint_from_octal 2021-12-21 13:13:04 -08:00
Ali Mohammad Pur
49cbd4dcca AK: Make DisjointChunks not query size() when there are no chunks 2021-12-21 22:10:07 +01:00
Ali Mohammad Pur
2df54a7b56 AK: Add Disjoint(Chunks Spans)::find(index)
For when the may or may not be out of bounds.
2021-12-21 22:10:07 +01:00
Ali Mohammad Pur
f0709c7a24 LibC+AK: Implement all sorts of wprintf variants 2021-12-21 21:24:36 +03:30
Andreas Kling
452a5531be AK+LibMain: Improve formatter for AK::Error in userspace
Print the full associated string metadata by default (if available.)
2021-12-20 21:13:42 +01:00
Nick Johnson
e122502f70 AK: Speed up BitmapView::find_next_range_of_unset_bits
While watching Andreas' most recent video, I noticed that this function
only worked with 32 bit values, but was a serious performance
bottleneck for the kernel. As such, I reworked it to use `size_t`, so
it now can switch to 64-bit sweeps on 64-bit platforms. This caused
test-js to go from 12.5 seconds hot to 11.5 seconds hot on my machine
when running on KVM x86_64.
2021-12-18 23:36:08 +01:00
Nick Johnson
548529ace4 AK: Add BuiltinWrappers.h
The goal of this file is to enable C++ overloaded functions for
standard builtin functions that we use. It contains fallback
implementations for systems that do not have the builtins available.
2021-12-18 23:36:08 +01:00
kleines Filmröllchen
3891d6d73a AK: Fast path for single-element TypedTransfer::copy
Co-Authored-By: Brian Gianforcaro <bgianf@serenityos.org>
2021-12-17 13:13:00 -08:00
kleines Filmröllchen
d5dce448ea AK: Bypass Buffered's buffer for large reads
Before, if we couldn't read enough data out of the buffer, we would re-
fill the buffer and recursively call read(), which in turn reads data
from the buffer into the resliced target span. This incurs very
intensive superflous memmove's when large chunks of data are read from
a buffered stream.

This commit changes the behavior so that when we exhaust the buffer, we
first read any necessary additional data directly into the target, then
fill up the buffer again. Effectively, this results in drastically
reduced overhead from Buffered when reading large contiguous chunks.
Of course, Buffered is designed to speed up data access patterns with
small frequent reads, but it's nice to be able to combine both access
patterns on one stream without penalties either way.

The final performance gain is about an additional 80% of abench decoding
speed.
2021-12-17 13:13:00 -08:00
Andreas Kling
a409b832fa AK: Make JsonValue::from_string("") return a null JsonValue
This unbreaks the /var/run/utmp system which starts out as an empty
string, and is then turned into an object by the first update.

This isn't necessarily the best way for this to work, but it's how
it used to work, so this just fixes the regression for now.
2021-12-16 22:48:17 +01:00
sin-ack
69ef211925 Kernel+LibC: Move errno definitions to Kernel/API/POSIX
This fixes at least half of our LibC includes in the kernel. The source
of truth for errno codes and their description strings now lives in
Kernel/API/POSIX/errno.h as an enumeration, which LibC includes.
2021-12-16 22:21:35 +03:30
sin-ack
e4a1bc1542 AK: Use __builtin_memmove for ByteBuffer and Span's overwrite
__builtin_memcpy will fail when the target area and the source area
overlap. Using __builtin_memmove will handle this case as well.
2021-12-16 22:21:35 +03:30
Ben Wiederhake
208d85e707 AK+Tests: Use less space in ErrorOr 2021-12-16 09:32:51 +01:00
Hendiadyoin1
c673b7220a AK: Enable fast path for removal by hash-compatible key in HashMap/Table 2021-12-15 23:35:14 -08:00
Hendiadyoin1
b429f9c7aa AK: Add implied const qualifiers to the Json interface
As specified by clang-tidy.
2021-12-15 23:35:14 -08:00
Hendiadyoin1
b39c4c62d0 AK: Use StringView as key-type when removing a Value from an JsonObject 2021-12-15 23:35:14 -08:00
Hendiadyoin1
e35709cbd2 AK: Return bool in JsonValue::as_bool() 2021-12-15 23:35:14 -08:00
Andrew Kaster
db33cdbc2f AK+LibSanitizer: Add method to zero out a UBSAN SourceLocation
This is the same strategy that LLVM's compiler-rt uses to make sure that
each UBSAN error is only reported once, when UBSAN is *not* deadly.

Otherwise, each time we head through a UB codepath, we will log the same
error over and over. That behavior just adds noise to the logs and makes
it nearly impossible to run binaires that have some common code path
with flagged UB in them.

compiler-rt goes the extra step to make sure the "clear" action is
atomic, but we don't really have that many multi-threaded apps gettting
tested with UBSAN yet, so we can add that later.
2021-12-15 10:30:32 -08:00
Hendiadyoin1
422b624743 AK: Convert JsonObject to use StringViews for lookup
Most of the Keys we use are compile-time strings anyway, there is no
need to use the heap to pass them around.
2021-12-15 13:09:49 +03:30
Hendiadyoin1
d50360f5dd AK: Allow hash-compatible key types in Hash[Table|Map] lookup
This will allow us to avoid some potentially expensive type conversion
during lookup, like form String to StringView, which would allocate
memory otherwise.
2021-12-15 13:09:49 +03:30
Hendiadyoin1
c8bee92fb9 AK: Add the concept of hash-compatible types 2021-12-15 13:09:49 +03:30
Hendiadyoin1
92e824afa1 AK: Add a Concept for any String type 2021-12-15 13:09:49 +03:30
Hendiadyoin1
6c6e917cf0 AK: Add dedicated Traits for c-strings 2021-12-15 13:09:49 +03:30
Hendiadyoin1
ceb0e28ea5 AK: Add helper to test for pointer and cv-pointer at the same time 2021-12-15 13:09:49 +03:30
Hendiadyoin1
dfe2cf3a40 AK: Add a Decay helper for Concepts 2021-12-15 13:09:49 +03:30
Martin Blicha
c4c8f59284 AK: Fix preprocessor OS check
Instead of checking __linux__ macro directly, the code should check if
this macro is defined. This is already done correctly a couple of lines
above.

I ran into this when trying to build libjs-test262 on MacOS where I got
the following error message
   error: "__linux__" is not defined, evaluates to 0 [-Werror=undef]
2021-12-12 11:10:34 -08:00
Jelle Raaijmakers
bc36e39d07 AK: Simplify Array::back() by checking for Size > 0
We do not want `Array::max()` to be used here at all - we know the
size at compile-time, after all.
2021-12-11 23:15:24 +01:00
Andreas Kling
c9a35e104b AK: Add RefCountForwarder<T>
This is a convenience template that implements reference count
forwarding. This means that an object forwards ref() and unref() to
another object.

We can use this when two ref-counted objects need to keep each other
alive. This situation poses two problems:

- Using 2x RefPtr would cause a ref cycle and leak both objects.
- Using 2x WeakPtr would allow one of them to be destroyed early.

With RefCountForwarder, only one of the objects has a ref count. The
object with the ref count points to the forwarding object by using a
non-counting smart pointer (OwnPtr or NonnullOwnPtr). Thus, both objects
are kept alive by the same ref count, and they can safely point to each
other without worrying about disjoint lifetimes.
2021-12-09 21:28:52 +01:00
Tim Schumacher
5c511de4cc AK: Zero-pad automatically if formatting with precision 2021-12-07 20:13:59 -08:00
Ben Wiederhake
6f37510a71 AK: Implement missing const getters in AK::Error, fix typo
Note that the return type for the non-const method error() changed. This
is most likely an accident, hidden by the fact that ErrorType typically
is Error.
2021-12-05 22:59:09 +01:00
Ben Wiederhake
dbd60f9ff4 AK: Implement Formatter for ErrorOr<>
As the Formatter for Error already exists, this apparently was just
accidentally omitted.
2021-12-05 22:59:09 +01:00
Sam Atkins
5013a6480d AK: Mark smart pointer classes as [[nodiscard]]
This makes it an error to not do something with a returned smart
pointer, which should help prevent mistakes. In cases where you do need
to ignore the value, casting to void will placate the compiler.

I did have to add comments to disable clang-format on a couple of lines,
where it wanted to format the code like this:

```c++
private : NonnullRefPtr() = delete;
```
2021-12-05 15:31:03 +01:00
James Mintram
ef52fe7d2f Kernel: Add VALIDATE_IS_X86 macro 2021-12-01 11:22:04 -08:00
Andreas Kling
cb9cac4e40 LibIPC+IPCCompiler+AK: Make IPC value decoders return ErrorOr<void>
This allows us to use TRY() in decoding helpers, leading to a nice
reduction in line count.
2021-11-28 23:14:19 +01:00
kleines Filmröllchen
295eec2d49 AK: Stop Vector::extend from unnecessary reallocation
Previously, Vector::extend for a moved vector would move the other
vector into this vector if this vector was empty, thereby throwing away
existing allocated capacity. Therefore, this commit allows the move to
only happen if this vector's capacity is too small to fit the other
vector. This will also alleviate bugs where callers relied on the
capacity to never shrink with calls to unchecked_append, extend and the
like.
2021-11-28 13:33:51 -08:00
kleines Filmröllchen
05cb499d58 AK: Add Vector::unchecked_append for data pointers
This mirrors the existence of append() for data pointers and is very
useful when the program needs to have a guarantee of no allocations,
as is necessary for real-time audio.
2021-11-28 13:33:51 -08:00
kleines Filmröllchen
cbb2b4fe71 AK: Expose Buffered's buffer size and underlying stream 2021-11-28 13:33:51 -08:00
Hendiadyoin1
6f74c1bb11 AK: Allow to "get a result" from Result<void>
This is to make Result<void> work inside TRY
2021-11-28 13:33:51 -08:00
Ben Wiederhake
b1982267b2 AK: Remove unused static member of Bitmap
This is a remnant of the Bitmap/BitmapView split.
2021-11-28 13:16:41 -08:00
csb6
d55dfe2418 AK: On macOS host builds, wrap unistd.h with missing extern "C"
During the build process on macOS, multiple versions of <unistd.h> were
being included (Apple's version and GCC's version). It appears that
all other places #include the version from GCC, but in Platform.h the
Apple header was being used. GCC's <unistd.h> is wrapped in
`extern "C"`, while Apple's is not. This causes a conflicting
declaration, so we need to wrap the #include with extern "C".

Issue has been observed on macOS Mojave.

See https://github.com/microsoft/vcpkg/issues/11320 for a similar issue.
2021-11-23 18:48:59 +00:00
Andreas Kling
58fb3ebf66 LibCore+AK: Move MappedFile from AK to LibCore
MappedFile is strictly a userspace thing, so it doesn't belong in AK
(which is supposed to be user/kernel agnostic.)
2021-11-23 11:33:36 +01:00
Andreas Kling
4e530135d5 AK+LibSystem+LibMain: Add Error::from_syscall() for syscall failures
This creates an error that contains the name of the syscall that failed.
This allows error handlers to print out the name of the call if they
want to. :^)
2021-11-22 19:28:31 +01:00
Tim Schumacher
07351762c7 AK: Add LexicalPath::prepend() 2021-11-22 09:03:47 +01:00
Andrew Kaster
bf33a14081 AK: Mark MemMem header-only functions as inline rather than static
Avoid including a per-translation unit copy of all these functions.

Also, drive-by two clang-tidy fixes for readability-qualified-auto and
readability-implicit-bool-conversion.
2021-11-22 05:23:24 +03:30
James Mintram
bcd518a228 Kernel: Wrap format timespec assignment in a check for !AARCH64
Currently TimeManagement wont compile on AARCH64, so it is not included.
This creates a link error since format.cpp now relies on functionality
in TimeManagement.cpp to add timestamps to log lines.

This PR disables that functionality for AARCH64 builds until
TimeManagement will compile.
2021-11-21 09:12:16 +01:00
Andreas Kling
0f22ba5bf2 AK: Make RedBlackTree::try_insert() return ErrorOr<void> instead of bool 2021-11-18 21:11:30 +01:00
Jelle Raaijmakers
dfbdd035da AK: Implement acos<T> correctly
This is a naive implementation based on the symmetry with `asin`.

Before, I'm not really sure what we were doing, but it was returning
wildly incorrect results.
2021-11-18 21:10:30 +01:00
Andreas Kling
8fe1c1f788 AK: Add missing return in Formatter<unsigned char[Size]>::format()
Caught by ENABLE_ALL_THE_DEBUG_MACROS.
2021-11-17 07:45:10 +01:00
Andreas Kling
216e21a1fa AK: Convert AK::Format formatting helpers to returning ErrorOr<void>
This isn't a complete conversion to ErrorOr<void>, but a good chunk.
The end goal here is to propagate buffer allocation failures to the
caller, and allow the use of TRY() with formatting functions.
2021-11-17 00:21:13 +01:00
Andreas Kling
008355c222 AK: Add failable try_* functions to StringBuilder
These will allow us to start using TRY() with StringBuilder operations.
2021-11-17 00:21:13 +01:00
Andreas Kling
11aad74dce AK: Forward declare Error and ErrorOr in AK/Forward.h 2021-11-17 00:21:12 +01:00
Andreas Kling
587f9af960 AK: Make JSON parser return ErrorOr<JsonValue> (instead of Optional)
Also add slightly richer parse errors now that we can include a string
literal with returned errors.

This will allow us to use TRY() when working with JSON data.
2021-11-17 00:21:10 +01:00
Hendiadyoin1
6cb42d8a40 AK: Verify that we are not overreaching in StringView's substring_view() 2021-11-16 00:49:48 +00:00
Andrew Kaster
f1d8978804 AK+Kernel: Remove implicit conversion from Userspace<T*> to FlatPtr
This feels like it was a refactor transition kind of conversion. The
places that were relying on it can easily be changed to explicitly ask
for the ptr() or a new vaddr() method on Userspace<T*>.

FlatPtr can still implicitly convert to Userspace<T> because the
constructor is not explicit, but there's quite a few more places that
are relying on that conversion.
2021-11-16 00:13:22 +01:00