Commit graph

3258 commits

Author SHA1 Message Date
Andrew Kaster 6e8f1549a3 AK+LibCore: Don't use unsupported features on Android 2023-09-03 11:38:51 +02:00
Andrew Kaster aa03f73c2e AK: Demangle symbols on assertion failure on Linux as well
While macOS backtrace(3) puts a space directly after the mangled symbol
name, some versions of glibc put a + directly after it. This new logic
accounts for both situations when trying to demangle.

Co-Authored-By: Andreas Kling <kling@serenityos.org>
2023-09-03 07:51:03 +02:00
Andrew Kaster 4641af7873 AK: Always use our assertion failure method, and add backtrace to it
On platforms that support it, enable using ``<execinfo.h>`` to get
backtrace(3) to dump a backtrace on assertion failure. This should make
debugging things like WebContent crashes in Lagom much easier.
2023-09-01 11:50:47 +02:00
Shannon Booth 50d8ef94ba AK: Port percent_encode_after_encoding to String 2023-08-31 11:02:18 +02:00
Shannon Booth cb4c279e90 AK: Percent encode URL fragments when parsed
This fixes URL fragments containing characters in the fragment encoding
set that were not being correctly percent encoded.
2023-08-31 11:02:18 +02:00
Shannon Booth e233de1e48 AK: Report validation error for URLs with invalid percent encodings
This part of the spec is mostly useful for our debugging for now, but
could eventually be hooked up so that the user can see any reported
validation errors.
2023-08-31 11:02:18 +02:00
Shannon Booth f53dfdd6ac AK: Write scheme state of URL parsing closer to spec steps
The main change here is that we now follow the spec by asserting the URL
is not special. Previously I could not find a way to enable this without
getting assertions when browsing the web - but that seems to no longer
be the case (probably from some other fixes which have since been made).
2023-08-31 11:02:18 +02:00
Shannon Booth 23e82114b4 AK: Do not consider port of 0 as a null port
This fixes an issue where if a port number of 0 was given for a non
special scheme the port number was being dropped.
2023-08-31 11:02:18 +02:00
ronak69 2caf68fd03 AK: Add binary and octal mode formatting for FixedPoint 2023-08-29 11:10:45 +02:00
ronak69 352480338e AK: Refactor FixedPoint's formatter
The main change is the simplification of the expression
`(10^precision * fraction) / 2^precision` to `5^precision * fraction`.

Those expressions overflow or not depends on the value of `precision`
and `fraction`. For the maximum value of `fraction`, the following table
shows for which value of `precision` overflow will occur.

            Old   New
    u32      08    10
    u64      15    20
    u128     30    39

As of now `u64` type is used to calculate the result of the expression.
Meaning that before, only FixedPoints with `precision` less than 15
could be accurately rendered (for every value of fraction) in decimal.
Now, this limit gets increased to 20.

This refactor also fixes, broken decimal render for explicitly specified
precision width in format string, and broken hexadecimal render.
2023-08-29 11:10:45 +02:00
ronak69 d40807681d AK: Cast lhs of left shifts to FixedPoint's underlying integer type
By default, `1` is of the type `int` which is 32-bits wide at max.
Because of that, if `precision` of a `FixedPoint` is greater than 32,
the expression `1 << precision` will get clamped at 32-bits and the
result will always be zero. Casting `1` to the wider underlying type
will make the expression not overflow.
2023-08-29 11:10:45 +02:00
ronak69 4c6ea4a963 AK: Fix off-by-one error in round-to-even logic of FixedPoint
Because of the off-by-one error, the second bit of the fraction was
getting ignored in differentiating between fractions equal to 0.5 or
greater than 0.5. This resulted in numbers like 2.75 being considered
as having fraction equal to 0.5 and getting rounded incorrectly (to 2).
2023-08-29 11:10:45 +02:00
Andreas Kling b256e52586 AK: Make Formatter for NonnullOwnPtr<T> format the T
This mirrors the behavior of NonnullRefPtr<T>. If you want to format
the pointer address, call .ptr() on it.
2023-08-25 20:10:47 +02:00
Liav A 72231b405a AK+Kernel: Introduce StdLib function to copy FixedStringBuffer to user
This new Kernel StdLib function will be used to copy contents of a
FixedStringBuffer with a null character to a user process.

The first user of this new function is the prctl option of
PR_GET_PROCESS_NAME which would copy a process name including a null
character to a user provided buffer.
2023-08-25 11:51:52 +02:00
Karol Kosek 9663ccff77 AK: Use Iterator's trait when comparing a value
It's not needed, from what I can gather, but I changed it just for
the correctness sake.
2023-08-23 20:21:09 +02:00
Karol Kosek e575ee4462 AK+Kernel: Unify Traits<T>::equals()'s argument order on different types
There was a small mishmash of argument order, as seen on the table:

                 | Traits<T>::equals(U, T) | Traits<T>::equals(T, U)
   ============= | ======================= | =======================
   uses equals() | HashMap                 | Vector, HashTable
defines equals() | *String[^1]             | ByteBuffer

[^1]: String, DeprecatedString, their Fly-type equivalents and KString.

This mostly meant that you couldn't use a StringView for finding a value
in Vector<String>.

I'm changing the order of arguments to make the trait type itself first
(`Traits<T>::equals(T, U)`), as I think it's more expected and makes us
more consistent with the rest of the functions that put the stored type
first (like StringUtils functions and binary_serach). I've also renamed
the variable name "other" in find functions to "entry" to give more
importance to the value.

With this change, each of the following lines will now compile
successfully:

    Vector<String>().contains_slow("WHF!"sv);
    HashTable<String>().contains("WHF!"sv);
    HashMap<ByteBuffer, int>().contains("WHF!"sv.bytes());
2023-08-23 20:21:09 +02:00
Andreas Kling 0b83717ea2 AK: Make SourceGenerator::fork() infallible 2023-08-22 13:08:24 +02:00
Andreas Kling 244516142a AK: Remove fallible SourceGenerator::try_append()
And fall back to the infallible append().
2023-08-22 13:08:24 +02:00
Andreas Kling a1d694ccdc AK: Remove fallible SourceGenerator::try_appendln()
And fall back to the infallible appendln().
2023-08-22 13:08:24 +02:00
Andreas Kling 8b936b5912 AK: Make SourceGenerator::set() infallible 2023-08-22 13:08:24 +02:00
Sönke Holz e300da4db4 AK: Don't use GCC's __builtin_ffs on riscv64 without Zbb extension
GCC redirects `__builtin_ffs` to `ffs` on RISC-V without the Zbb
extension, causing a linker error.
2023-08-21 13:28:22 +02:00
Sönke Holz d572ad38ac AK: Add riscv64 support 2023-08-21 13:28:22 +02:00
Ali Mohammad Pur 3c176bafee LibWasm: Implement a few SIMD instructions 2023-08-21 13:39:32 +03:30
Ali Mohammad Pur 4f0f1c7c72 AK: Add support for Little/BigEndian<UFixedBigInteger<M>> 2023-08-21 13:39:32 +03:30
Ali Mohammad Pur 94f5389934 AK: Add a 'HostIsLittleEndian' constant and use it instead of BYTE_ORDER
Previously we were using the preprocessor everywhere we needed this
constant, so let's move away from that and use a constexpr constant.
2023-08-21 13:39:32 +03:30
Andrew Kaster f87a488b22 AK: Silence -Wimplicit-const-int-float-conversion in clamp_to_int 2023-08-19 21:05:06 -06:00
Daniel Bertalan 075ce53d14 AK: Fix Clang 18 -Wdeprecated-literal-operator warning
The proper syntax for defining user-defined literals does not require a
space between the `operator""` token and the operator name:

> error: identifier 'sv' preceded by whitespace in a literal operator
>        declaration is deprecated
2023-08-19 11:07:12 +02:00
Aliaksandr Kalenik 469aea5a5b AK+LibJS: Introduce JS::HeapFunction
This change introduces HeapFunction, which is intended to be used as a
replacement for SafeFunction. The new type behaves like a regular
GC-allocated object, which means it needs to be visited from
visit_edges, and unlike SafeFunction, it does not create new roots for
captured parameters.

Co-Authored-By: Andreas Kling <kling@serenityos.org>
2023-08-19 05:03:17 +02:00
Daniel Bertalan 192ee4594c AK: Fix volatile qualifier in Atomic<T*>::ptr()
It's the pointer that should be volatile, not the pointed-to object.
2023-08-18 16:20:13 +02:00
Dan Klishch 39dee6ad67 AK: Add missing include in RecursionDecision.h 2023-08-18 08:58:51 +03:30
Dan Klishch 3556c27d2d AK: Add StringView::count(char) 2023-08-18 08:58:51 +03:30
kleines Filmröllchen 3d0da734ee AK: Allow Statistics to be used with any container type
This not only facilitates using non-owning types, but also those that
cannot be default-constructed.
2023-08-16 01:10:35 +02:00
Nicolas Ramz fda5590313 LibGfx/ILBM: Add an IFF-ILBM decoder :)
IFF was a generic container fileformat that was popular on the Amiga
since it was the only file format supported by Deluxe Paint.

ILBM is an image format popular in the late eighties/nineties
that uses the IFF container.

This is a very first version of the decoder that only supports
(byterun) compressed files with bpp <= 8.

Only the minimal chunks are decoded: CMAP, BODY, BMHD.

I am planning to add support for the following variants:

- EHB (32 colours + lighter 32 colours)
- HAM6 / HAM8 (special mode that allowed to display the whole Amiga
4096 colours / 262 144 colours palette)
- TrueColor (24bit)

Things that could be fun to do:

- Still images could be animated using color cycle information
2023-08-15 18:36:11 +01:00
Hendiadyoin1 394529b7d0 AK: Fix formatting of negative whole fixed point numbers
Instead of `-2` we were printing `-2.1`

Co-Authored-By: Daniel Bertalan <dani@danielbertalan.dev>
2023-08-14 14:20:45 -06:00
Hendiadyoin1 daacc5c6c2 AK: Rename AK::FixedPoint::round to rint and fix a rounding error
`rint` is a more accurate name for the roudning mode as the fixme above
stated
2023-08-14 14:20:45 -06:00
Hendiadyoin1 05c959e40b AK: Change standard casting method of FixedPoint to truncation
This matches what floats do.

Also fix typo `trunk`->`trunc`
2023-08-14 14:20:45 -06:00
Hendiadyoin1 8526791617 AK: Use wider type for FixedPoint division
This allows us to shift first and then divide, preserving more precision
2023-08-14 14:20:45 -06:00
Hendiadyoin1 e609ac74a3 AK: Fix FixedPoint multiplication rounding and overflow behaviour
We now preform the multiplication in a widened type which makes it
overflow-safe and use the correct bit for rounding direction detection.
2023-08-14 14:20:45 -06:00
Shannon Booth 582784d0cf AK: Remove unused ApplyPercentDecoding enum from URL class 2023-08-13 15:03:53 -06:00
Shannon Booth 9d60f23abc AK: Port URL::m_fragment from DeprecatedString to String 2023-08-13 15:03:53 -06:00
Shannon Booth 5663a2d3b4 AK+LibWeb: Do not percent encode/decode in URL fragment setter/getters
The web specs do not expect decoding or decoding to happen when calling
these helpers. This allows us to remove the raw_fragment helper function
from the URL class.
2023-08-13 15:03:53 -06:00
Shannon Booth c25485700a AK: Port URL scheme from DeprecatedString to String 2023-08-13 15:03:53 -06:00
Shannon Booth 21fe86d235 AK: Port URL::m_query from DeprecatedString to String 2023-08-13 15:03:53 -06:00
Shannon Booth 55a01e72ca AK: Port URL username/password from DeprecatedString to String
And for cases that just need to check whether the password/username is
empty, add a raw_{password,username} helper to avoid any allocation.
2023-08-13 15:03:53 -06:00
Shannon Booth d2fe657879 AK: Remove unused URL::m_path member 2023-08-13 15:03:53 -06:00
kleines Filmröllchen 625aac2367 LibAudio: Add a FLAC encoder
This encoder can handle all integer formats and sample rates, though
only two channels well. It uses fixed LPC and performs a
close-to-optimal parameter search on the LPC order and residual Rice
parameter, leading to decent compression already.
2023-08-12 12:25:26 -06:00
kleines Filmröllchen fb37587efe LibCrypto: Implement a generic 16-bit CRC
This is mostly a 16-bit version of the 8-bit CRC, using the same general
byte-LUT algorithm.
2023-08-12 12:25:26 -06:00
kleines Filmröllchen 001ea22917 AK+LibCore: Make output buffered stream seekable
Just like with input buffered streams, we don't currently have a use
case for output buffered streams which aren't seekable, since the main
application are files.
2023-08-12 12:25:26 -06:00
Liav A b2fd51f561 AK: Implement string formatting for FixedStringBuffers
To ensure this happens without duplicating code, we allow forcing a
StringBuilder object to only use the inline buffer, so the code in the
AK/Format.cpp file doesn't need to deal with different underlying
storage types (expandable or inline-fixed) at all.
2023-08-12 11:48:48 -06:00
Valtteri Koskivuori 8451c4d91c LibIMAP: Add useful dbgln_if() printouts to IMAP::Parser
I couldn't run the parser in a debugger like I normally would, so I
added printouts to understand where the parser is failing.
More could be added, but these are enough to get a good idea of what
the parser is doing. It's very spammy, though, so enable it by flicking
the IMAP_PARSER_DEBUG switch :^)
2023-08-12 11:45:52 -06:00