1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-01 11:55:37 +00:00
Commit Graph

3545 Commits

Author SHA1 Message Date
Nico Weber
9cc688041a AK: Give IntrusiveBinaryHeap template args named types
Works around https://gcc.gnu.org/PR70413. Without this, the next
commit would cause -Wsubobject-linkage warnings for AK/BinaryHeap.h
when used in LibCompress/Huffman.h.

We can undo this once we're on GCC 14 everywhere.

No behavior change.
2024-07-01 00:29:39 +02:00
Dan Klishch
2360df3ab8 Everywhere: Define even more destructors out of line
You guessed it, this fixes compilation with LLVM trunk.
2024-06-30 08:52:07 +02:00
Dan Klishch
c03cca7b2f AK+LibTest: Choose definition of CO_TRY and CO_TRY_OR_FAIL more robustly
There are three compiler bugs that influence this decision:

 - Clang writing to (validly) destroyed coroutine frame with -O0 and
   -fsanitize=null,address under some conditions
   (https://godbolt.org/z/17Efq5Ma5) (AK_COROUTINE_DESTRUCTION_BROKEN);

 - GCC being unable to handle statement expressions in coroutines
   (AK_COROUTINE_STATEMENT_EXPRS_BROKEN);

 - GCC being unable to deduce template type parameter for TryAwaiter
   with nested CO_TRYs (AK_COROUTINE_TYPE_DEDUCTION_BROKEN).

Instead of growing an ifdef soup in AK/Coroutine.h and
LibTest/AsyncTestCase.h, define three macros in AK/Platform.h that
correspond to these bugs and use them accordingly in the said files.
2024-06-29 20:15:05 -06:00
Liav A.
f6e01aae9a Prekernel: Add support for assertion printing
This is done by using a FixedStringBuffer as the foundation to perform
string formatting, which ensures that we avoid memory allocations in
the prekernel stage.
2024-06-29 19:56:45 +02:00
implicitfield
176999e20c AK/Span: Add a method to check if a Span is filled with a value 2024-06-29 19:16:08 +02:00
Diego
7b50f71e0e AK: Read signed LEB128 integers without 64-bit assumptions
This fixes some errors where too many bytes were allowed to be read for
signed integers of a smaller size (e.g. i32). The new parser doesn't
make 64-bit assumptions and now matches the generality of its unsigned
counterpart.

(cherry picked from commit 596dd5252d477747d466e660acca25c015ce12e4)
2024-06-26 22:13:13 +02:00
Daniel Bertalan
d1f1a6eef0 Everywhere: Remove usages of template keyword with no parameter list
These were made invalid with P1787, and Clang (19) trunk started warning
on them with https://github.com/llvm/llvm-project/pull/80801.

(cherry picked from commit 397774d42272fff8dbc6d8d53616d79667d6608a)
2024-06-25 17:42:49 +02:00
Liav A.
b91c625f8f AK: Introduce declerations for base10 size suffixes
Also, re-organize the base2 size suffixes to not use KiB repeatedly.
2024-06-25 09:24:55 +02:00
Ali Mohammad Pur
a711bb63b7 LibHTTP+LibCore+RequestServer: Use async streams for HTTP
We no longer use blocking reads and writes, yielding a nice performance
boost and a significantly cleaner (and more readable) implementation :^)
2024-06-19 15:45:02 +02:00
Ali Mohammad Pur
6edf5653a5 AK: Add a formatter for OwnPtr<T>
This formatter just prints the object out as a pointer.
2024-06-19 15:45:02 +02:00
Dan Klishch
79051e5f79 AK: Add AK::AsyncStreamBuffer
This class encapsulates all the logic required for a buffer of
asynchronous stream.
2024-06-13 17:40:24 +02:00
Dan Klishch
73b4d39189 AK: Add AK::AsyncStreamTransform
This class allows to convert an asynchronous generator which generates
chunks of data into an AsyncInputStream. This is useful in practice
because the said generator often ends up looking very similar to the
underlying synchronous algorithm it describes.
2024-06-13 17:40:24 +02:00
Dan Klishch
0f1d67f2f0 AK: Introduce AK::Generator 2024-06-13 17:40:24 +02:00
Dan Klishch
aeb17a864e AK: Instantiate GenericLexer::consume_decimal_integer<size_t> on MacOS
u64 and size_t are different types on it.
2024-06-13 17:40:24 +02:00
Dan Klishch
60476e247b AK: Introduce a few asynchronous stream helpers
These were proven to be generally useful after writing some asynchronous
streams code.
2024-06-13 17:40:24 +02:00
Dan Klishch
7fb6d24402 LibTest: Support asynchronous tests 2024-06-13 17:40:24 +02:00
Dan Klishch
6662d5de2b AK: Introduce asynchronous streams 2024-06-13 17:40:24 +02:00
Dan Klishch
b15b51f9da AK: Don't delete Badge move constructor
Otherwise it is impossible to use Badge as an argument of a coroutine.
2024-06-13 17:40:24 +02:00
Dan Klishch
8263e0a619 AK: Introduce AK::Coroutine 2024-06-13 17:40:24 +02:00
Dan Klishch
9054682536 AK: Qualify forward call in AK::exchange
Otherwise it fails to resolve ambiguity between std::forward and
AK::forward when called with the std:: type.
2024-06-13 17:40:24 +02:00
Nico Weber
bb2d80a2bb Everywhere: Gently remove the ladybird android port
With Ladybird now being its own repository, there's little reason
to keep the Ladybird Android port in the SerenityOS repository.

(The Qt port is useful to be able to test changes to LibWeb in lagom
so it'll stay around. Similar for the AppKit port, since getting
Qt on macOS is a bit annoying. But if the AppKit port is too much
pain to keep working, we should toss that too.

Eventually, the lagom browser ports should move out from Ladybird/
to Meta/Lagom/Contrib, but for now it might make sense to leave them
where they are to keep cherry-picks from ladybird easier.)
2024-06-11 19:40:08 -04:00
Diego
a8639245bf AK: Add AllowSurrogates to UTF-8 validator
The [UTF-8](https://datatracker.ietf.org/doc/html/rfc3629#page-5)
standard says to reject strings with upper or lower surrogates. However,
in many standards, ECMAScript included, unpaired surrogates (and
therefore UTF-8 surrogates) are allowed in strings. So, this commit
extends the UTF-8 validation API with `AllowSurrogates`, which will
reject upper and lower surrogate characters.
2024-06-09 16:30:09 +02:00
Timothy Flynn
fe3fde2411 AK+LibUnicode: Implement a case-insensitive variant of find_byte_offset
The existing String::find_byte_offset is case-sensitive. This variant
allows performing searches using Unicode-aware case folding.
2024-06-01 07:37:54 +02:00
Daniel Bertalan
637ccacce5 AK: Enable format string checking in Clang builds
Format string checking was disabled in Clang-based builds due to a
compiler bug: https://github.com/llvm/llvm-project/issues/51182. Now
that the requirement has been raised to Clang 17, that is no longer
necessary.

This has been tested to work correctly with Apple Clang 15.0.0 (which is
the *least modern* supported compiler), as well as CLion 2024.1's
bundled Clangd.
2024-05-29 13:34:15 -06:00
Matthew Olsson
e0d6afbabe ClangPlugins: Invert the lambda detection escape mechanism
Instead of being opt-out with NOESCAPE, it is now opt-in with ESCAPING.
Opt-out is ideal, but unfortunately this was extremely noisy when
compiling the entire codebase. Escaping functions are rarer than non-
escaping ones, so let's just go with that for now.

This also allows us to gradually add heuristics for detecting missing
ESCAPING annotations and emitting them as errors. It also nicely matches
the spelling that Swift uses (@escaping), which is where this idea
originally came from.
2024-05-22 21:55:34 -06:00
Matthew Olsson
a5f4c9a632 AK+Userland: Remove NOESCAPE
See the next commit for an explanation
2024-05-22 21:55:34 -06:00
Dan Klishch
38b51b791e AK+Kernel+LibVideo: Include workarounds for missing P0960 only in Xcode
With this change, ".*make.*" function family now does error checking
earlier, which improves experience while using clangd. Note that the
change also make them instantiate classes a bit more eagerly, so in
LibVideo/PlaybackManager, we have to first define SeekingStateHandler
and only then make() it.

Co-Authored-By: stelar7 <dudedbz@gmail.com>
2024-05-21 14:24:59 +02:00
Tim Ledbetter
d0d81e470e AK: Fix off by one error in integral ceil_log2()
Previously, certain values of `ceil_log2(x)` would be 1 smaller than
`ceil(log2(x))`.
2024-05-21 09:31:17 +02:00
Dan Klishch
be36dbce7d AK: Don't put element count next to heap-allocated data in FixedArray
This not only makes code easier to follow but also makes it faster.
2024-05-18 18:30:42 +02:00
Lucas CHOLLET
c6e4563489 AK: Export Statistics to the global namespace 2024-05-18 18:30:07 +02:00
Andreas Kling
b2e6843055 LibJS+AK: Fix integer overflow UB on (any Int32 - -2147483648)
It wasn't safe to use addition_would_overflow(a, -b) to check if
subtraction (a - b) would overflow, since it doesn't cover this case.

I don't know why we didn't have subtraction_would_overflow(), so this
patch adds it. :^)
2024-05-18 18:11:50 +02:00
Sönke Holz
b6cc95c38e AK: Add a function for frame pointer-based stack unwinding
Instead of duplicating stack unwinding code everywhere, introduce a new
AK helper to unwind the stack in a generic way.
2024-05-14 14:02:06 -06:00
ptrcnull
13e44ab035 AK: Add stack size fixup for musl libc
Fixes #16681
2024-05-14 13:56:45 -06:00
Andreas Kling
6b2b90d2b0 AK: Remove AK_HAS_CONDITIONALLY_TRIVIAL
Code behind this appears to compile nicely with Clang 17 and later.
2024-05-10 15:03:24 +00:00
implicitfield
f923016e0b AK: Add reinterpret_as_octal()
This is useful for parsing user-provided integers that should be
interpreted as octals.
2024-05-07 16:54:27 -06:00
Abuneri
b5bed37074 AK: Replace FP math in is_power_of with a purely integral algorithm
The previous naive approach was causing test failures because of
rounding issues in some exotic environments. In particular, MSVC
via MSBuild
2024-05-07 16:43:34 -06:00
Andreas Kling
ebe6ec6069 AK: Check for u32 overflow in String::repeated()
I don't know why this was checking for size_t overflow, but it was
tripping up ASAN malloc() checks by passing a way-too-large size.
2024-05-07 09:15:40 +02:00
Nico Weber
c421a3d7ce AK: Add missing using statements to Find.h 2024-05-06 17:32:19 +02:00
Sergey Bugaev
0bb37f9c0e AK: Include <features.h> before checking for platform macros
AK/Platform.h did not include any other header file, but expected
various macros to be defined. While many of the macros checked here are
predefined by the compiler (i.e. GCC's TARGET_OS_CPP_BUILTINS), some
may be defined by the system headers instead. In particular, so is
__GLIBC__ on glibc-based systems.

We have to include some system header for getting __GLIBC__ (or not).
It could be possible to include something relatively small and
innocuous, like <string.h> for example, but that would still clutter
the name space and make other code that would use <string.h>
functionality, but forget to include it, build on accident; we wouldn't
want that. At the end of the day, the header that actually defines
__GLIBC__ (or not) is <features.h>. It's typically included from other
glibc headers, and not by user code directly, which makes it unlikely
to mask other code accidentlly forgetting to include it, since it
wouldn't include it in the first place.

<features.h> is not defined by POSIX and could be missing on other
systems (but it seems to be present at least when using either glibc or
musl), so guard its inclusion with __has_include().

Specifically, this fixes AK/StackInfo.cpp not picking up the glibc code
path in the cross aarch64-gnu (GNU/Hurd on 64-bit ARM) Lagom build.
2024-05-02 07:46:53 -06:00
Tim Ledbetter
8b01abf9f7 AK: Don't move trivially copyable types in BufferedStream methods 2024-04-30 13:22:56 +02:00
Liav A.
122c82a2a1 AK: Add the SetOnce class
The SetOnce class is meant to be used as one-time set boolean flag,
which is useful for flags that change only once and then stay immutable
forever.
2024-04-26 23:46:23 -06:00
Nico Weber
88d0702763 AK: Make ceil_div() handle one argument being negative correctly
`ceil_div(-1, 2)` used to return -1.
Now it returns 0, which is the correct ceil(-0.5).

(C++'s division semantics have floor semantics for numbers > 0,
but ceil semantics for numbers < 0.)

This will be important for the JPEG2000 decoder eventually.
2024-04-27 07:09:08 +02:00
Timothy Flynn
fecd08ce64 Everywhere: Remove 'clang-format off' comments that are no longer needed 2024-04-24 16:50:01 -04:00
Timothy Flynn
ec492a1a08 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-18 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")

There are a couple of weird cases where clang-format now thinks that a
pointer access in an initializer list, e.g. `m_member(ptr->foo)`, is a
lambda return statement, and it puts spaces around the `->`.
2024-04-24 16:50:01 -04:00
kleines Filmröllchen
8443d0a74d AK: Use common ComponentType integer type for float bitfields
This allows us to easily use an appropriate integer type when performing
float bitfield operations.

This change also adds a comment about the technically-incorrect 80-bit
extended float mantissa field.
2024-04-23 19:18:09 -06:00
Andrew Kaster
913cffe928 AK: Add workaround for faulty Sanitizer warning on gcc 13+ in Atomic
gcc can't seem to figure out that the address of a member variable of
AK::Atomic<u32> in AtomicRefCounted cannot be null when fetch_sub-ing.
Add a bogus condition to convince the compiler that it can't be null.
2024-04-23 15:37:07 -06:00
dgaston
08aaf4fb07 AK: Add methods to BufferedStream to resize the user supplied buffer
These changes allow lines of arbitrary length to be read with
BufferedStream. When the user supplied buffer is smaller than
the line, it will be resized to fit the line. When the internal
buffer in BufferedStream is smaller than the line, it will be
read into the user supplied buffer chunk by chunk with the
buffer growing accordingly.

Other behaviors match the behavior of the existing read_line method.
2024-04-21 11:46:55 +02:00
Jess
ecb7d4b40f LibJS: Throw RangeError in StringPrototype::repeat if OOM
currently crashes with an assertion failure in `String::repeated` if
malloc can't serve a `count * input_size` sized request, so add
`String::repeated_with_error` to propagate the error.
2024-04-20 19:23:46 -04:00
Andrew Kaster
1e749d023a AK: Add fallible dequeue method to Queue 2024-04-19 16:38:55 -04:00
Dan Klishch
5ed7cd6e32 Everywhere: Use east const in more places
These changes are compatible with clang-format 16 and will be mandatory
when we eventually bump clang-format version. So, since there are no
real downsides, let's commit them now.
2024-04-19 06:31:19 -04:00