Commit Graph

2515 Commits

Author SHA1 Message Date
Lucas CHOLLET
3843b8c0a1 AK: Perform a resize in ByteBuffer::get_bytes_for_writing()
ByteBuffer::get_bytes_for_writing() was only ensuring capacity before
this patch. The method needs to call resize to register the appended
data, otherwise it will be overwritten with next data addition.
2022-06-27 20:22:15 +01:00
Ali Mohammad Pur
2104e9a6e4 AK: Recognize __CLION_IDE__ as well as __CLION_IDE_
This used to be `__CLION_IDE_` before, but it seems to have been fixed
in the latest EAP.
2022-06-26 22:21:17 +01:00
kleines Filmröllchen
07d712ea00 AK: Add saturating addition and subtraction to Checked 2022-06-23 23:26:33 +01:00
Hendiadyoin1
5bf84a5b0e AK: Zero previous pointer *after* fixing the insertion list in HashTable 2022-06-23 20:25:12 +03:00
Idan Horowitz
eb02425ef9 AK: Clear the previous and next pointers of deleted HashTable buckets
Usually the values of the previous and next pointers of deleted buckets
are never used, as they're not part of the main ordered bucket chain,
but if an in-place rehashing is done, which results in the bucket being
turned into a free bucket, the stale pointers will remain, at which
point any item that is inserted into said free-bucket will have either
a stale previous pointer if the HashTable was empty on insertion, or a
stale next pointer, resulting in undefined behaviour.

This commit also includes a new HashMap test that reproduces this issue
2022-06-22 21:53:13 +02:00
Linus Groh
9e79856b43 Revert "AK: Add comparison operators to NonnullOwnPtr"
This reverts commit 50c88e5e3a.

The intention was to add them to NonnullRefPtr, not NonnullOwnPtr. That
is also what was advertised in the PR, but not actually done in the
reverted commit.
2022-06-18 13:17:49 +01:00
Allan Regush
50c88e5e3a AK: Add comparison operators to NonnullOwnPtr 2022-06-18 02:11:08 +01:00
Andreas Kling
75dca629df AK+Kernel: Remove RefPtrTraits template param in userspace code
Only the kernel actually uses RefPtrTraits, so let's not burden
userspace builds with the complexity.
2022-06-15 17:15:04 +02:00
Andreas Kling
9e994da2ac Kernel+AK: Split Weakable.h into userspace and kernel variants
Only the kernel expects AK::Weakable to lock its refcount manipulation,
so let's not force userspace to pay for that as well.
2022-06-15 17:15:04 +02:00
Hediadyoin1
e6a3cac5ce AK: Add sqrt(2) and sqrt(1/2) constants 2022-06-14 23:00:52 +02:00
Luke Wilde
076c9772a4 LibWeb: Add ability to present LibGL framebuffer and add clearing 2022-06-13 21:45:27 +01:00
Matthias Zimmerman
c10d48b72c AK/ByteBuffer+Everywhere: Handle errors in ByteBuffer::slice() 2022-06-13 15:38:51 +01:00
Karol Kosek
65afa113e5 AK: Make URL ApplicationXWWWFormUrlencoded encoding closer to spec
It was mostly implemented based on a spec note, that described only
allowed characters, but instead of allowing some special characters not
to be escaped, we escaped every special character except those 'new in
this encode set' disallowed characters from the spec definition.
2022-06-10 22:32:29 +01:00
Karol Kosek
9e69a89f8e AK: Append correct number of port characters when serializing a URL
Instead of formatting a port string, it put bytes from stack, using the
port number as a length (so for port 8000 it appended 8000 bytes).
2022-06-10 22:32:29 +01:00
Tim Schumacher
b3e0aed91f AK: Add SinglyLinkedList::prepend() 2022-06-10 19:06:46 +01:00
Lucas CHOLLET
dad4716cc2 AK: Add Error::operator==(Error const&) 2022-06-09 22:08:04 +02:00
huttongrabiel
8ffa860bc3 AK: Add invert_case() and invert_case(StringView)
In the given String, invert_case() swaps lowercase characters with
uppercase ones and vice versa.
2022-05-26 21:51:23 +01:00
Ali Mohammad Pur
06c6c046f3 AK: Use static_cast to cast to base type
This is an issue on systems that don't have the empty base class
optimisation (such as windows), and we normally don't need to care -
however static_cast is technically the right thing to use, so let's use
that instead.

Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
2022-05-21 02:18:40 +02:00
Daniel Bertalan
014b9fd709 AK+DHCPClient: Fix false positive gcc 12 warnings
The compiler would complain about `__builtin_memcpy` in ByteBuffer::copy
writing out of bounds, as it isn't able to deduce the invariant that the
inline buffer is only used when the requested size is smaller than the
inline capacity.

The other change is more bizarre. If the destructor's declaration
exists, gcc complains about a `delete` operation causing an
out-of-bounds array access.

error: array subscript 'DHCPv4Client::__as_base [0]' is partly outside
array bounds of 'unsigned char [8]' [-Werror=array-bounds]
   14 |   ~DHCPv4Client() = default;
      |   ^

This looks like a compiler bug, and I'll report it if I find a suitable
reduced reproducer.
2022-05-12 13:12:37 +02:00
Jelle Raaijmakers
2c381ea45c AK: Add clamp(f32x4, float, float)
We are allowed to directly compare `f32x4` with a `float`, so make use
of it.
2022-05-09 21:49:48 +02:00
Vitaly Dyachkov
a0a4d169f4 AK+LibGUI: Pass predicate to *_matching() methods by const reference 2022-05-08 17:02:00 +02:00
EWouters
0317882b61 AK: Use AK:: sin and cos on aarch64 build
This fixes the lagom build on aarch64, as `__builtin_sincosf` doesn't
take double arguments.
2022-05-08 16:51:23 +02:00
EWouters
6ea89c35fe AK: Use builtin versions of llrint{,l,f}
This fixes the build on M1 Macs.
2022-05-07 23:36:49 +02:00
Hendiadyoin1
d4fe02152a AK: Add an SSE2 specific implementation of sqrt(double) 2022-05-07 20:27:05 +02:00
Hendiadyoin1
6d9bc87903 AK: Add a cpp-y, more fine grained version of fenv.h: FPControl.h
This allows direct inlining and hides away some assembly and
bit-fiddling when manipulating the floating point environment.

This only implements the x87/SSE versions, as of now.
2022-05-07 20:27:05 +02:00
Hendiadyoin1
37ff2b9bd2 AK: Add an helper for quick hardware based rounding
This uses the `fistp` and `cvts[sd]2si` respectively, to potentially
round floating point values with just one instruction.

This falls back to `llrint[fl]?` on aarch64 for now.
2022-05-07 20:25:39 +02:00
kleines Filmröllchen
df57536c40 AK: Put invalid UTF8 debug spam behind a flag
This is very annoying if we're (intentionally) passing invalid UTF8 into
Utf8View.
2022-04-27 00:02:24 +02:00
Andrew Kaster
83603d68d2 AK: Make sure we don't include Math.h or math.h from KERNEL 2022-04-23 10:43:32 -07:00
kleines Filmröllchen
6b13436ef6 LibCore: Introduce SharedSingleProducerCircularQueue
This new class with an admittedly long OOP-y name provides a circular
queue in shared memory. The queue is a lock-free synchronous queue
implemented with atomics, and its implementation is significantly
simplified by only accounting for one producer (and multiple consumers).
It is intended to be used as a producer-consumer communication
datastructure across processes. The original motivation behind this
class is efficient short-period transfer of audio data in userspace.

This class includes formal proofs of several correctness properties of
the main queue operations `enqueue` and `dequeue`. These proofs are not
100% complete in their existing form as the invariants they depend on
are "handwaved". This seems fine to me right now, as any proof is better
than no proof :^). Anyways, the proofs should build confidence that the
implemented algorithms, which are only roughly based on existing work,
operate correctly in even the worst-case concurrency scenarios.
2022-04-21 13:55:00 +02:00
kleines Filmröllchen
65b338ad04 AK: Allow alignment to cache line size with CACHE_ALIGNED
This is particularly important to avoid false sharing, which thrashes
performance when two process-shared atomics are on the same cache line.
2022-04-21 13:55:00 +02:00
Tim Schumacher
908d5a2853 AK: Expose RedBlackTree::find_smallest_not_below() 2022-04-21 13:16:56 +02:00
ForLoveOfCats
79a2088a13 AK: Make Vector::contains_slow templated
This allows for calling this function with any argument type for which
the appropriate traits and operators have been implemented so it can be
compared to the Vector's item type
2022-04-21 09:12:37 +04:30
ForLoveOfCats
a7fe3183f5 AK: Add URL::create_with_help_scheme helper function 2022-04-21 09:12:37 +04:30
faxe1008
b8bd667782 AK: Add FuzzyMatch header
This patch adds a header containing the fuzzy match algorithm
previously used in Assistant. The algorithm was moved to AK
since there are many places where a search may benefit from fuzzyness.
2022-04-20 18:34:09 +02:00
Ali Mohammad Pur
dd370fcdd1 AK: Explicitly instantiate String::to_uint<unsigned long{, long}>()
Instead of just to_uint<u64>().
2022-04-20 00:15:23 +04:30
Ali Mohammad Pur
2b79f36148 AK: Add a OneOfIgnoringCV concept
Some functions want to ignore cv-qualifiers, and it's much easier to
constrain the type through a concept than a separate requires clause on
the function.
2022-04-20 00:15:23 +04:30
Thitat Auareesuksakul
f4b8bae65f AK: Add Kernel namespace to KStrings in AK::IPv6Address
Currently there is no AK::IPv6Address in the kernel. But when there is,
KStrings won't resolve properly because they are in Kernel namespace.
2022-04-17 16:57:52 -07:00
Tim Schumacher
d6ccee4089 AK: Differ between long and long long formats 2022-04-14 03:12:56 +04:30
Tim Schumacher
fbfa378e74 AK: Deduplicate formatting hexadecimal values
Both calls essentially only differ in one boolean, which dictates
whether to print the value in uppercase or lowercase.

Move the long function call into a new function and pass in the
"uppercase" boolean seperately to avoid having to write everything
twice.
2022-04-14 03:12:56 +04:30
Tim Schumacher
0d5098fdc0 AK: Merge print_i64 into print_signed_number
Those functions only differ by the input type of `number`. No other
wrapper does this, as they rely on adjusting the type of the argument on
the caller side instead.

Avoid specializing too much by just doing the same for signed numbers.
2022-04-14 03:12:56 +04:30
Andreas Kling
83082b12b7 LibWeb: Make reverse iterators work for const NonnullPtrVectors 2022-04-13 19:52:25 +02:00
Andreas Kling
40f584a2bb AK: Add missing include to Traits.h 2022-04-10 19:18:16 +02:00
Andreas Kling
ae6b09f4dc AK: Add hash traits for floating-point primitives
This allows us to use float and double as hash keys.
2022-04-10 12:39:44 +02:00
Jelle Raaijmakers
1577a8ba42 AK: Remove KERNEL check from String
Since we no longer use `String` inside of the kernel code, we can drop
this `#ifndef`.
2022-04-10 12:08:31 +02:00
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