Commit graph

1816 commits

Author SHA1 Message Date
Ali Mohammad Pur c38fafbf4e AK: Make {min,max,clamp}(T, U) work when U can be implicitly cast to T
It was really annoying to `static_cast` the arguments to be the same
type, so instead of doing that, just convert the second one to the first
one, and let the compiler warn about sign differences and truncation.
2021-06-23 19:04:08 +02:00
Lenny Maiorani 24225df979 AK: Reimplement any_of in terms of find_if
Problem:
- Now that a generic free-function form of `find_if` is implemented
  the code in `any_of` is redundant.

Solution:
- Follow the "don't repeat yourself" mantra and make the code DRY by
  implementing `any_of` in terms of `find_if`.
2021-06-20 10:54:09 +01:00
Idan Horowitz 5e53a690ac AK: Add support for keeping trailing zeros in fixed precision floats
This uses the same syntax as zero padding integers:
String::formatted("{:0.5}", 1.234) => "1.23400"
2021-06-19 16:13:59 +01:00
Itamar 03ef2a479a LibCoreDump: Include source locations of inlined functions in backtrace 2021-06-19 14:51:18 +02:00
Itamar d26f4f9e8c AK: Add RedBlackTree::find_largest_not_above_iterator
It's a version of find_largest_not_above that returns an iterator.
2021-06-19 14:51:18 +02:00
sin-ack 3abcfcc178 AK: Add a way to disable the trimming of whitespace in to_*int
This behavior might not always be desirable, and so this patch adds a
way to disable it.
2021-06-18 19:18:15 +01:00
Ali Mohammad Pur 7eda164c25 AK: Add a :hex-dump mode to AK::Format
This will just hexdump the given value.
Note that not all formatters respect this, the ones that do are:
- (Readonly)Bytes: formatter added in this commit
- StringView / char const*
- integral types
2021-06-17 18:44:00 +04:30
Gunnar Beutner 0dd03413d6 Meta: Add support for declaring components
Components are a group of build targets that can be built and installed
separately. Whether a component should be built can be configured with
CMake arguments: -DBUILD_<NAME>=ON|OFF, where <NAME> is the name of the
component (in all caps).

Components can be marked as REQUIRED if they're necessary for a
minimally functional base system or they can be marked as RECOMMENDED
if they're not strictly necessary but are useful for most users.

A component can have an optional description which isn't used by the
build system but may be useful for a configuration UI.

Components specify the TARGETS which should be built when the component
is enabled. They can also specify other components which they depend on
(with DEPENDS).

This also adds the BUILD_EVERYTHING CMake variable which lets the user
build all optional components. For now this defaults to ON to make the
transition to the components-based build system easier.

The list of components is exported as an INI file in the build directory
(e.g. Build/i686/components.ini).

Fixes #8048.
2021-06-17 11:03:51 +02:00
Idan Horowitz fea6d952a4 AK: Add the Utf8View::{contains, trim} helper methods 2021-06-16 20:05:18 +01:00
Brian Gianforcaro 31081e8ebf AK: Remove now unused InlineLinkedList class
All usages of AK::InlineLinkedList have been converted to
AK::IntrusiveList. So it's time to retire our old friend.

Note: The empty white space change in AK/CMakeLists.txt is to
force CMake to re-glob the header files in the AK directory so
incremental build will work when folks git pull this change locally.

Otherwise they'll get errors, because CMake will attempt to install
a file which no longer exists.
2021-06-16 10:40:01 +02:00
Brian Gianforcaro b7f8343f87 AK+Tests: Add IntrusiveList<T,...>::insert_before(..) method
The insert_before method on AK::InlineLinkedList is used, so in order to
achieve feature parity, we need to implement it for AK::IntrusiveList as
well.
2021-06-16 10:40:01 +02:00
Brian Gianforcaro 4586668fc3 AK: Use IntrusiveList::remove() in the IntrusiveList::prepend() prolog
All other functions use the functionality for removal, use it in the
prepend function as well for consistency.
2021-06-16 10:40:01 +02:00
Idan Horowitz 8c7fe8d6c8 AK: Add support for removing SinglyLinkedList nodes during iteration
This commit also fixes the now-broken usage of SinglyLinkedList::remove
in the Piano application.
2021-06-15 23:59:21 +01:00
Idan Horowitz f1f00be691 AK: Add a missing using AK::OrderedHashMap statement 2021-06-15 23:51:20 +01:00
Hediadyoin1 4a81c79909 AK: Add Ordering support to HashTable and HashMap
Adds a IsOrdered flag to Hashtable and HashMap, which allows iteration
in insertion order
2021-06-15 22:16:55 +02:00
Ali Mohammad Pur f7f88adc78 AK: Add a function that casts an enum to its underlying type
This is basically the same thing as `std::to_underlying(Enum)`.
2021-06-15 22:06:33 +04:30
Andreas Kling cd12b182ca AK: Add FlyString::from_fly_impl()
This allows you to create a FlyString directly from a known-fly
StringImpl instance.
2021-06-13 19:11:29 +02:00
Gunnar Beutner d476144565 Userland: Allow building SerenityOS with -funsigned-char
Some of the code assumed that chars were always signed while that is
not the case on ARM hosts.

Also, some of the code tried to use EOF (-1) in a way similar to what
fgetc() does, however instead of storing the characters in an int
variable a char was used.

While this seemed to work it also meant that character 0xFF would be
incorrectly seen as an end-of-file.

Careful reading of fgetc() reveals that fgetc() stores character
data in an int where valid characters are in the range of 0-255 and
the EOF value is explicitly outside of that range (usually -1).
2021-06-13 18:52:58 +02:00
Matthew Olsson ffda24373a AK: Add ByteBuffer::append(ReadonlyBytes) 2021-06-12 22:45:01 +04:30
Hediadyoin1 8a739f986a AK: Make Ptr32 more transparent
This adds a transparent dereference operator, aswell as a constant
arrow operator

Also increaces the verbosity of the code
2021-06-12 20:43:47 +04:30
Andreas Kling dc65f54c06 AK: Rename Vector::append(Vector) => Vector::extend(Vector)
Let's make it a bit more clear when we're appending the elements from
one vector to the end of another vector.
2021-06-12 13:24:45 +02:00
Hendiadyoin1 5ffe23e4f3 AK+LibX86: Generalize u128/256 to AK::UFixedBigInt
Doing these as custom classes might be faster, especially when writing
them in SSE, but this would cause a lot of Code duplication and due to
the nature of constexprs and the intelligence of the compiler they might
be using SSE/MMX either way
2021-06-11 18:14:11 +04:30
Ali Mohammad Pur 7b2c838162 AK: Make NonnullRefPtrVector constructible from Vector<NonnullRefPtr> 2021-06-11 00:30:09 +02:00
Ali Mohammad Pur d3db45c60b AK: Make Vector::take_last() ALWAYS_INLINE
This function doesn't do a whole lot, but is called quite a bit.
2021-06-09 23:05:32 +04:30
Ali Mohammad Pur 8410d6aadb AK: Make a bunch of Variant methods ALWAYS_INLINE 2021-06-09 23:05:32 +04:30
Ali Mohammad Pur 50349de38c Meta: Disable -Wmaybe-uninitialized
It's prone to finding "technically uninitialized but can never happen"
cases, particularly in Optional<T> and Variant<Ts...>.
The general case seems to be that it cannot infer the dependency
between Variant's index (or Optional's boolean state) and a particular
alternative (or Optional's buffer) being untouched.
So it can flag cases like this:
```c++
if (index == StaticIndexForF)
    new (new_buffer) F(move(*bit_cast<F*>(old_buffer)));
```
The code in that branch can _technically_ make a partially initialized
`F`, but that path can never be taken since the buffer holding an
object of type `F` and the condition being true are correlated, and so
will never be taken _unless_ the buffer holds an object of type `F`.

This commit also removed the various 'diagnostic ignored' pragmas used
to work around this warning, as they no longer do anything.
2021-06-09 23:05:32 +04:30
Max Wipfli d1dae5f4d1 AK: Implement IPv4Address::to_string_reversed() 2021-06-09 17:43:32 +04:30
Idan Horowitz 71c54198fa AK: Allow changing the HashTable behaviour for sets on existing entries
Specifically, replacing the existing entry or just keeping it and
canceling the set.
2021-06-09 11:48:04 +01:00
Ali Mohammad Pur 3d94b5051d AK: Make Vector capable of holding reference types
This commit makes it possible to instantiate `Vector<T&>` and use it
to store references to `T` in a vector.
All non-pointer observers are made to return the reference, and the
pointer observers simply yield the underlying pointer.
Note that the 'find_*' methods act on the values and not the pointers
that are stored in the vector.
This commit also makes errors in various vector methods much more
readable by directly using requires-clauses on them.
And finally, it should be noted that Vector cannot hold temporaries :^)
2021-06-08 19:14:24 +02:00
Ali Mohammad Pur 48195b7c30 AK: Switch to east const in Vector.h
Let's get this out of the way before touching the file.
2021-06-08 19:14:24 +02:00
Ali Mohammad Pur b7b0b199a8 AK: Reorder Vector methods to place similar methods next to each other
The methods of this class were all over the place, this commit reorders
them to place them in a more logical order:
- Constructors/Destructor
- Observers
- Comparisons and const existence checks
- Mutators: insert
- Mutators: append
- Mutators: prepend
- Mutators: assignment
- Mutators: remove
- OOM-safe mutators: insert
- OOM-safe mutators: append
- OOM-safe mutators: prepend
- OOM-safe size management
- Size management
- Iterators
2021-06-08 19:14:24 +02:00
Ali Mohammad Pur c3fa13fa73 AK: Rename Vector::{value_type => ValueType} 2021-06-08 19:14:24 +02:00
Max Wipfli 3b04420490 AK: Don't create Utf8View from temporary String in URLParser
This fixes a bug where a Utf8View was created with data from a temporary
string, which was immediately deleted. This lead to a use-after-free
issue. This also changes most occurences for StringBuilder::to_string in
URLParser to use ::string_view(), as the value is passed as StringView
const& most of the time anyways.

This fixes oss-fuzz issue 34973.
2021-06-08 19:08:02 +02:00
Max Wipfli 3c7e775a9a AK: Utf8CodePointIterator: Don't output full string to debug output
When a code point is invalid, the full string was outputted to the debug
output. For large strings, this can make the system quite slow.
Furthermore, one of the cases incorrectly assumed the data to be null
terminated. This patch modifies the debug statements not to print the
full string.

This fixes oss-fuzz issue 35050.
2021-06-08 19:08:02 +02:00
Gunnar Beutner d2662df57c LibC+AK: Remove our custom macros from <assert.h>
Other software might not expect these to be defined and behave
differently if they _are_ defined, e.g. scummvm which checks if
the TODO macro is defined and fails to build if it is.
2021-06-08 17:29:57 +02:00
Max Wipfli 1e8006ebb8 AK: Add children() accessor to Trie 2021-06-08 12:15:04 +02:00
Andreas Kling 7cbe4daa7c LibJS: Move bytecode debug spam behind JS_BYTECODE_DEBUG :^) 2021-06-07 18:11:59 +02:00
Brian Gianforcaro f5e04759cc AK: Add IntrusiveList::size_slow() to match InlineLinkedList
The functionality is needed to replace InlineLinkedList with
IntrusiveList in the Kernel Process class.
2021-06-07 09:42:55 +02:00
FalseHonesty 403bb07443 LibVideo: Scaffold LibVideo and implement simplistic Matroska parser
This commit initializes the LibVideo library and implements parsing
basic Matroska container files. Currently, it will only parse audio
and video tracks.
2021-06-06 17:47:00 +02:00
Linus Groh 0a7e91329f Revert "Revert "AK: Always inline FlyString::view()""
This reverts commit f09216ac42.
This was supposed to be a local test only, didn't mean to push it. :^)
2021-06-06 08:05:49 +01:00
Linus Groh f09216ac42 Revert "AK: Always inline FlyString::view()"
This reverts commit 66f15c2e0c.
2021-06-06 01:58:09 +01:00
Idan Horowitz 2011fcff24 AK: Add the parse_ascii_base36_digit method
This is similar to parse_ascii_hex_digit but can parse the whole A-Z
range (also known as base36).
2021-06-06 01:34:22 +01:00
Ali Mohammad Pur 51c2c69357 AK+Everywhere: Disallow constructing Functions from incompatible types
Previously, AK::Function would accept _any_ callable type, and try to
call it when called, first with the given set of arguments, then with
zero arguments, and if all of those failed, it would simply not call the
function and **return a value-constructed Out type**.
This lead to many, many, many hard to debug situations when someone
forgot a `const` in their lambda argument types, and many cases of
people taking zero arguments in their lambdas to ignore them.
This commit reworks the Function interface to not include any such
surprising behaviour, if your function instance is not callable with
the declared argument set of the Function, it can simply not be
assigned to that Function instance, end of story.
2021-06-06 00:27:30 +04:30
Andreas Kling 66f15c2e0c AK: Always inline FlyString::view() 2021-06-05 12:36:14 +02:00
Max Wipfli 2164d8aae8 AK: Stop using U+0000 as end of file code point in URL parser
This changes URL parser to use the 0xFFFFFFFF constant instead of 0 to
indicate end of file. This fixes a bug where inputs containing null
bytes would terminate the parser early, because they were interpreted
as end of file.
2021-06-05 10:53:31 +02:00
Max Wipfli 97425c7dfb AK: Make debugging URLParser easier
This patch adds a state_name method to URLParser to convert a state to a
string. With this, the debugging statements now display the state names.

Furthermore, this fixes a bug where non-ASCII code points were
formatted as characters, which fails an assertion in the formatting
system.
2021-06-05 10:53:31 +02:00
Max Wipfli 99d5555134 AK: Do not trim away non-ASCII bytes when parsing URL
Because non-ASCII code points have negative byte values, trimming away
control characters requires checking for negative bytes values.

This also adds a test case with a URL containing non-ASCII code points.
2021-06-05 10:53:31 +02:00
Max Wipfli 44937e2dfc AK: Update URLParser.{cpp,h} to use east const 2021-06-05 10:53:31 +02:00
Gunnar Beutner 8f81d9ad90 AK: Verify that functions aren't modified while they're being invoked
A Function object should not be set to a different functor while the
original functor is currently executing.
2021-06-04 19:32:25 +02:00
Gunnar Beutner 44418cb351 AK: Allow deferring clear() for the Function class
Ideally a Function should not be clear()ed while it's running.
Unfortunately a number of callers do just that and identifying all of
them would require inspecting all call sites for operator() and clear().

Instead this adds support for deferring clear() until after the
function has finished executing.
2021-06-04 19:32:25 +02:00