Commit graph

1831 commits

Author SHA1 Message Date
Gunnar Beutner 661d1aa8d1 AK: Add inline storage support for the Function class
This allows us to allocate most Function objects on the stack or as
part of other objects and gets rid of quite a few allocations.
2021-05-19 21:36:57 +02:00
Gunnar Beutner d954c11f66 Everywhere: Add missing includes for <AK/OwnPtr.h>
Previously <AK/Function.h> also included <AK/OwnPtr.h>. That's about to
change though. This patch fixes a few build problems that will occur
when that change happens.
2021-05-19 21:36:57 +02:00
Timothy Flynn 145e246a5e AK: Allow AK::Variant::visit to return a value
This changes Variant::visit() to forward the value returned by the
selected visitor invocation. By perfectly forwarding the returned value,
this allows for the visitor to return by value or reference.

Note that all provided visitors must return the same type - the compiler
will otherwise fail with the message: "inconsistent deduction for auto
return type".
2021-05-19 20:41:09 +02:00
Lenny Maiorani 0681086cad Time: Remove static from function local constexpr variable
Problem:
- Function local `constexpr` variables do not need to be
  `static`. This consumes memory which is unnecessary and can prevent
  some optimizations.
- C-style arrays are not as safe as AK::Arrays and require the user to
  specify the length of the array manually.

Solution:
- Remove `static` keyword.
- Change from C-style array for AK::Array.
2021-05-19 16:24:02 +02:00
Ali Mohammad Pur 73cb566041 AK: Make vout() log to debug instead of VERIFY()'ing
In case the write was to stderr/stdout, and it just so happened to fail
because of an issue like "the pty is gone", VERIFY() would end up
calling vout() back to write to stderr, which would then fail forever
until the stack is exhausted.
"Fixes" the issue where the Shell would crash in horrible ways when the
terminal is closed.
2021-05-19 09:19:29 +02:00
Gunnar Beutner 598d7f4127 AK: StringBuilder should prefer to use its inline capacity first
Previously StringBuilder would start allocating an external buffer
once the caller has used up more than half of the inline buffer's
capacity. Instead we should prefer to use the inline buffer until
it is full and only then start to allocate an external buffer.
2021-05-18 21:49:10 +02:00
Max Wipfli f51b0729f5 AK: Implement StringBuilder::append_as_lowercase(char ch)
This patch adds a convenience method to AK::StringBuilder which converts
ASCII uppercase characters to lowercase before appending them.
2021-05-18 21:02:07 +02:00
Ali Mohammad Pur b6e5c76427 AK: Add deduction guides to Tuple 2021-05-18 18:48:15 +01:00
Ali Mohammad Pur 5bf37d758c AK: Let HashMap export its key and value types 2021-05-18 18:48:15 +01:00
stelar7 24c5b0e81c LibGfx: Add support for DDS images 2021-05-18 08:45:53 +01:00
Gunnar Beutner c99fd217e2 AK: Make LexicalPath handle relative paths correctly
Previously LexicalPath would consider "." and ".." as equivalent to
"/". This is not true though.
2021-05-18 08:11:21 +02:00
Lenny Maiorani ebb1d9740e BitmapView: Disable mutations of the underlying Bitmap
Problem:
- `BitmapView` permits changing the underlying `Bitmap`. This violates
  the idea of a "view" since views are simply overlays which can
  themselves change but do not change the underlying data.

Solution:
- Migrate all non-`const` member functions to Bitmap.
2021-05-18 08:10:45 +02:00
Lenny Maiorani 44a9c7c23e AK/PrintfImplementation: Change static constexpr array to function local
Problem:
- Static variables take memory and can be subject to less optimization.
- This static variable is only used in 1 place.

Solution:
- Move the variable into the function and make it non-static.
2021-05-18 08:07:01 +02:00
Gunnar Beutner 3908a49661 AK: Revert removal of StringBuilder::will_append optimization
This was removed as part of the ByteBuffer changes but the allocation
optimization is still necessary at least for non-SerenityOS targets
where malloc_good_size() isn't supported or returns a small value and
causes a whole bunch of unnecessary reallocations.
2021-05-18 08:06:32 +02:00
Linus Groh 61e132ddfa AK: Sort all the debug macros 2021-05-17 22:33:35 +01:00
Ali Mohammad Pur 056be42c0b LibWasm: Start implementing a naive bytecode interpreter
As the parser now flattens out the instructions and inserts synthetic
nesting/structured instructions where needed, we can treat the whole
thing as a simple parsed bytecode stream.
This currently knows how to execute the following instructions:
- unreachable
- nop
- local.get
- local.set
- {i,f}{32,64}.const
- block
- loop
- if/else
- branch / branch_if
- i32_add
- i32_and/or/xor
- i32_ne

This also extends the 'wasm' utility to optionally execute the first
function in the module with optionally user-supplied arguments.
2021-05-17 23:25:30 +02:00
Ali Mohammad Pur e9b746a723 AK: Include HashTable.h in StringImpl.cpp
This was used without an include, I'm not sure how it didn't break
before :P
2021-05-17 23:25:30 +02:00
Ali Mohammad Pur 1ad6ac1cb4 AK: Include String.h in ScopeLogger 2021-05-17 23:25:30 +02:00
Linus Groh 0aab774343 Everywhere: Fix a bunch of typos 2021-05-17 17:48:55 +01:00
Andreas Kling bebbeda726 Revert "BitmapView: Disable mutations of the underlying Bitmap"
This reverts commit f25209113f.
2021-05-17 18:29:47 +02:00
Lenny Maiorani f25209113f BitmapView: Disable mutations of the underlying Bitmap
Problem:
- `BitmapView` permits changing the underlying `Bitmap`. This violates
  the idea of a "view" since views are simply overlays which can
  themselves change but do not change the underlying data.

Solution:
- Migrate all non-`const` member functions to Bitmap.
2021-05-17 18:16:35 +02:00
Andrew Kaster 73adbb319c AK: Don't read past the end in BitmapView::count_in_range()
The current code is factored such that reads to the entirety of the last
byte should be dropped. This was relying on the fact that last would be
one past the end in that case. Instead of actually reading that byte
when it's completely out of bounds of the bitmask, just skip reads that
would be invalid. Add more tests to make sure that the behavior is
correct for byte aligned reads of byte aligned bitmaps.
2021-05-16 21:58:14 +01:00
Andrew Kaster 11214bc94d AK: Don't call memcpy with null argument in ByteBuffer::copy()
This was happening in TestBase64.test_decode, while copying an empty
string.
2021-05-16 21:58:14 +01:00
Liav A 20743e8aed Kernel/Graphics + SystemServer: Support text mode properly
As we removed the support of VBE modesetting that was done by GRUB early
on boot, we need to determine if we can modeset the resolution with our
drivers, and if not, we should enable text mode and ensure that
SystemServer knows about it too.

Also, SystemServer should first check if there's a framebuffer device
node, which is an indication that text mode was not even if it was
requested. Then, if it doesn't find it, it should check what boot_mode
argument the user specified (in case it's self-test). This way if we
try to use bochs-display device (which is not VGA compatible) and
request a text mode, it will not honor the request and will continue
with graphical mode.

Also try to print critical messages with mininum memory allocations
possible.

In LibVT, We make the implementation flexible for kernel-specific
methods that are implemented in ConsoleImpl class.
2021-05-16 19:58:33 +02:00
Gunnar Beutner 53d0150827 AK+Userland: Remove nullability feature for the ByteBuffer type
Nobody seems to use this particular feature, in fact there were some
bugs which were uncovered by removing operator bool.
2021-05-16 17:49:42 +02:00
Gunnar Beutner fcaf98361f AK: Turn ByteBuffer into a value type
Previously ByteBuffer would internally hold a RefPtr to the byte
buffer and would behave like a reference type, i.e. copying a
ByteBuffer would not create a duplicate byte buffer, but rather
two objects which refer to the same internal buffer.

This also changes ByteBuffer so that it has some internal capacity
much like the Vector<T> type. Unlike Vector<T> however a byte
buffer's data may be uninitialized.

With this commit ByteBuffer makes use of the kmalloc_good_size()
API to pick an optimal allocation size for its internal buffer.
2021-05-16 17:49:42 +02:00
Gunnar Beutner f0fa51773a AK+Userland: Fix some compiler warnings and make variables const-ref
This fixes a few compiler warnings and makes some variables const-ref
in preparation for the next commit which changes how ByteBuffer works.
2021-05-16 17:49:42 +02:00
Timothy Flynn ce030ca584 AK+Meta: Add a debug option for Solitaire 2021-05-16 16:37:51 +02:00
Daniel Bertalan be519022c3 LibVT: Implement new ANSI escape sequence parser
This commit replaces the former, hand-written parser with a new one that
can be generated automatically according to a state change diagram.

The new `EscapeSequenceParser` class provides a more ergonomic interface
to dealing with escape sequences. This interface has been inspired by
Alacritty's [vte library](https://github.com/alacritty/vte/).

I tried to avoid changing the application logic inside the `Terminal`
class. While this code has not been thoroughly tested, I can't find
regressions in the basic command line utilities or `vttest`.

`Terminal` now displays nicer debug messages when it encounters an
unknown escape sequence. Defensive programming and bounds checks have
been added where we access parameters, and as a result, we can now
endure 4-5 seconds of `cat /dev/urandom`. :D

We generate EscapeSequenceStateMachine.h when building the in-kernel
LibVT, and we assume that the file is already in place when the userland
library is being built. This will probably cause problems later on, but
I can't find a way to do it nicely.
2021-05-16 11:50:56 +02:00
Nicholas Baron aa4d41fe2c
AK+Kernel+LibELF: Remove the need for IteratorDecision::Continue
By constraining two implementations, the compiler will select the best
fitting one. All this will require is duplicating the implementation and
simplifying for the `void` case.

This constraining also informs both the caller and compiler by passing
the callback parameter types as part of the constraint
(e.g.: `IterationFunction<int>`).

Some `for_each` functions in LibELF only take functions which return
`void`. This is a minimal correctness check, as it removes one way for a
function to incompletely do something.

There seems to be a possible idiom where inside a lambda, a `return;` is
the same as `continue;` in a for-loop.
2021-05-16 10:36:52 +01:00
Gunnar Beutner f89e8fb71a AK+LibC: Implement malloc_good_size() and use it for Vector/HashTable
This implements the macOS API malloc_good_size() which returns the
true allocation size for a given requested allocation size. This
allows us to make use of all the available memory in a malloc chunk.

For example, for a malloc request of 35 bytes our malloc would
internally use a chunk of size 64, however the remaining 29 bytes
would be unused.

Knowing the true allocation size allows us to request more usable
memory that would otherwise be wasted and make that available for
Vector, HashTable and potentially other callers in the future.
2021-05-15 16:30:14 +02:00
Andreas Kling a4099fc756 AK: Try to avoid String allocation in FlyString(StringView)
If we're constructing a FlyString from a StringView, and we already
have a matching StringImpl in the table, use HashTable::find() to
locate the existing string without creating a temporary String.
2021-05-15 11:01:05 +02:00
Jean-Baptiste Boric 069bf988ed AK: Introduce get_random_uniform()
This is arc4random_uniform(), but inside AK.
2021-05-14 22:24:02 +02:00
Jean-Baptiste Boric ad7cd05fc1 AK: Fix redefinition of macro inside AK/Platform.h 2021-05-14 22:24:02 +02:00
Andreas Kling d039542c7c AK: Remove unused STRINGIMPL_DEBUG instrumentation 2021-05-14 17:17:32 +02:00
Andreas Kling 3e603b2f32 AK: Make StringView::hash() constexpr
This required moving string_hash() to its own header so that everyone
can see it.
2021-05-14 15:24:32 +02:00
Gunnar Beutner a8e6cdc0d8 AK: Avoid allocations in ByteBuffer
Creating a ByteBuffer involves two allocations:

-One for the ByteBufferImpl object
-Another one for the actual byte buffer

This changes the ByteBuffer and ByteBufferImpl classes
so only one allocation is necessary.
2021-05-14 12:51:13 +02:00
Andreas Kling fccfc33dfb AK: Use move semantics to avoid copying in JSON parser
The JSON parser was deep-copying JsonValues left and right, and it was
all totally avoidable. :^)
2021-05-14 11:54:43 +02:00
Ali Mohammad Pur df515e1d85 LibCrypto+LibTLS: Avoid unaligned reads and writes
This adds an `AK::ByteReader` to help with that so we don't duplicate
the logic all over the place.
No more `*(const u16*)` and `*(const u32*)` for anyone.
This should help a little with #7060.
2021-05-14 08:39:29 +01:00
Ali Mohammad Pur bfd4c7a16c AK: Avoid passing nullptr to __buitin_memcpy() in ByteBuffer::grow() 2021-05-14 08:39:29 +01:00
Andrew Kaster 28987d1b56 AK: Add #define for [[gnu::no_sanitize_address]]
This lines up with other attribute global #defines
2021-05-14 08:34:00 +01:00
Gunnar Beutner a11a1cd4d6 AK: Vector::resize() should initialize new slots for primitive types
We call placement new for the newly added slots. However, we should
also specify an initializer so primitive data types like u64 are
initialized appropriately.
2021-05-14 00:35:57 +02:00
Ali Mohammad Pur 06a1c27e4d AK: Fix Variant's copy constructor trying to delegate to the wrong base
This was forgotten in 4fdbac2.
2021-05-13 19:44:32 +01:00
Brian Gianforcaro d07309a180 AK: Introduce adopt_ref_if_nonnull(..) to aid in Kernel OOM hardening
Unfortunately adopt_ref requires a reference, which obviously does not
work well with when attempting to harden against allocation failure.
The adopt_ref_if_nonnull() variant will allow you to avoid using bare
pointers, while still allowing you to handle allocation failure.
2021-05-13 08:29:01 +02:00
Brian Gianforcaro b0fef03e3f AK: Introduce adopt_own_if_nonnull(..) to aid in Kernel OOM hardening
Unfortunately adopt_own requires a reference, which obviously does not
work well with when attempting to harden against allocation failure.
The adopt_own_if_nonnull() variant will allow you to avoid using bare
pointers, while still allowing you to handle allocation failure.
2021-05-13 08:29:01 +02:00
sin-ack 2de11b0dc8 AK: Add LexicalPath::append and LexicalPath::join
This patch adds two new methods to LexicalPath.  LexicalPath::append
appends a new path component to a LexicalPath, and LexicalPath::join
constructs a new LexicalPath from one or more components.

Co-authored-by: Gunnar Beutner <gunnar@beutner.name>
2021-05-12 22:38:20 +02:00
Mart G b00cdf8ed8 Kernel+LibC: Make get_dir_entries syscall retriable
The get_dir_entries syscall failed if the serialized form of all the
directory entries together was too large to fit in its temporary buffer.

Now the kernel uses a fixed size buffer, that is flushed to an output
buffer when it is full. If this flushing operation fails because there
is not enough space available, the syscall will return -EINVAL. That
error code is then used in userspace as a signal to allocate a larger
buffer and retry the syscall.
2021-05-12 12:50:23 +02:00
Ali Mohammad Pur 02de813950 AK: Add a Tuple implementation
Please don't use this outside of metaprogramming needs, *please*.
2021-05-11 14:09:17 +01:00
Ali Mohammad Pur 4fdbac236d AK/Variant: Deduplicate the contained types
This allows the construction of `Variant<int, int, int>`.
While this might not seem useful, it is very useful for making variants
that contain a series of member function pointers, which I plan to use
in LibGL for glGenLists() and co.
2021-05-11 14:09:17 +01:00
Ali Mohammad Pur 3038b6b7dc AK: Avoid the use of typeinfo in Variant
typeid() and RTTI was a nice clutch to implement this, but let's move
away from the horrible slowness and implement variants using type
indices for faster variants.
2021-05-11 14:09:17 +01:00
Matthew Olsson 8c745ad0d9 LibPDF: Parse page structures
This commit introduces the ability to parse the document catalog dict,
as well as the page tree and individual pages. Pages obviously aren't
fully parsed, as we won't care about most of the fields until we
start actually rendering PDFs.

One of the primary benefits of the PDF format is laziness. PDFs are
not meant to be parsed all at once, and the same is true for pages.
When a Document is constructed, it builds a map of page number to
object index, but it does not fetch and parse any of the pages. A page
is only parsed when a caller requests that particular page (and is
cached going forwards).

Additionally, this commit also adds an object_cast function which
logs bad casts if DEBUG_PDF is set. Additionally, utility functions
were added to ArrayObject and DictObject to get all types of objects
from the collections to avoid having to manually cast.
2021-05-10 10:32:39 +02:00
Matthew Olsson af9a7b1374 AK: Add missing 'const' in Span 2021-05-10 10:32:39 +02:00
Ali Mohammad Pur aa4d8d26b9 LibWasm: Start implementing a basic WebAssembly binary format parser
This can currently parse a really simple module.
Note that it cannot parse the DataCount section, and it's still missing
almost all of the instructions.
This commit also adds a 'wasm' test utility that tries to parse a given
webassembly binary file.
It currently does nothing but exit when the parse fails, but it's a
start :^)
2021-05-08 22:14:39 +02:00
Ali Mohammad Pur 56a6d7924e AK: Let Result<T, E> know its Value and Error types
It's much easier to ask for T::ValueType than for
RemoveReference<decltype(declval<T>().release_value())>
2021-05-08 22:14:39 +02:00
Ali Mohammad Pur 62af7c4bdf AK+LibCpp: Remove DEBUG_SPAM in favour of per-application defines
What happens if one file defines DEBUG_SPAM, and another doesn't,
then we link them together and get ODR violations? -- @ADKaster
2021-05-08 22:14:39 +02:00
Ali Mohammad Pur 080f2c0e3e AK: Add an optional 'extra' descriptive field to ScopeLogger
Often it's easier to know what the functions are doing with a unique
name next to the function's name :)
2021-05-08 22:14:39 +02:00
Itamar 8a01167c7d AK: Add missing GenericTraits<NonnullRefPtr>
This enables us to use keys of type NonnullRefPtr in HashMaps and
HashTables.

This commit also includes fixes in various places that used
HashMap<T, NonnullRefPtr<U>>::get() and expected to get an
Optional<NonnullRefPtr<U>> and now get an Optional<U*>.
2021-05-08 18:10:56 +02:00
Itamar 1da0d402b7 AK: Add constructors to Optional that accept non const qualified inputs 2021-05-08 18:10:56 +02:00
Itamar 484823e9d5 AK: Add a non-const overload to HapMap::get()
Additionally, the const version of get() returns Optional<ConstPeekType>
for smart pointers.

For example, if the value in the HashMap is OwnPtr<u32>,
HashMap::get() const returns Optional<const u32*>.
2021-05-08 18:10:56 +02:00
Itamar b816bd0806 AK: Add ConstPeekType to Traits
Also, the PeekType of smart pointers is now T* instead of const T*.

Note: This commit doesn't compile, it breaks HashMap::get() for some
types. Fixed in the next commit.
2021-05-08 18:10:56 +02:00
Jesse Buhagiar 4807d32139 LibGL: Implement a basic OpenGL 1.x compatible library
This currently (obviously) doesn't support any actual 3D hardware,
hence all calls are done via software rendering.

Note that any modern constructs such as shaders are unsupported,
as this driver only implements Fixed Function Pipeline functionality.

The library is split into a base GLContext interface and a software
based renderer implementation of said interface. The global glXXX
functions serve as an OpenGL compatible c-style interface to the
currently bound context instance.

Co-authored-by: Stephan Unverwerth <s.unverwerth@gmx.de>
2021-05-08 10:13:22 +02:00
Stephan Unverwerth 0a557d65a0 AK: Add epsilon() to NumericLimits for float, double, long double 2021-05-08 10:13:22 +02:00
Andreas Kling 834b6508d7 AK: Remove StringBuilder::appendf()
All users have been converted to using AK::Format via appendff().
2021-05-07 21:12:09 +02:00
Valtteri Koskivuori 1069979ddf AK: Implement Span::starts_with()
Useful for checking for contents at the start of a span.
2021-05-07 11:46:53 +01:00
Ali Mohammad Pur da68c4580c AK: Make Checked<T> check for division overflow as well
Signed integer overflow can occur with division when the RHS is -1,
as the negative values' range is one larger than the positives.
2021-05-07 09:26:11 +02:00
Brian Gianforcaro 67322b0702 Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
AnotherTest ba6c9423b8 AK: Implement printf fraction length specification for strings
This adds support for '%.20s' and friends :^)
2021-05-06 15:20:31 +01:00
Ali Mohammad Pur a51113c58e AK: Add a Variant<Ts...> implementation
Also adds an AK::Empty struct, because 'empty' variants are useful, but
this implementation leaves that to the user (i.e. a variant cannot
actually be empty, but it can contain an instance of Empty - i.e. a
byte).
Note that this is more of a constrained Any type, but they basically do
the same things anyway :^)
2021-05-05 19:02:51 +02:00
Ali Mohammad Pur ab03c6fadf AK: Export integer_sequence_generate_array() 2021-05-05 19:02:51 +02:00
Ali Mohammad Pur b361793ad8 AK: Add min() and max() methods to Array<T, N>
...That are only defined when min() and max() are defined on the
elements.
2021-05-05 19:02:51 +02:00
Ali Mohammad Pur d288f6654e AK: Make LEB128 capable of reading into any type
And not just ssize_t/size_t.
This is useful in cases where the output size is supposed to be larger
than size_t.
2021-05-04 22:33:35 +02:00
Ali Mohammad Pur 48260b5054 AK: Move the LEB128 logic to AK and make it usable with InputStream 2021-05-04 22:33:35 +02:00
Ali Mohammad Pur 415fd4d2ec AK: Make DistinctNumeric constexpr-capable 2021-05-04 21:32:15 +02:00
Gunnar Beutner 56ee4a1af2 AK: Silence -Wmaybe-uninitialized warning
Adding -fno-semantic-interposition to the GCC command
line caused this new warning.

I don't see how output.data() could be uninitialized here. Also,
commenting out the ensure_capacity() call for the Vector
also gets rid of this warning.
2021-05-03 08:42:39 +02:00
Tobias Christiansen 4016e04061 AK: Move bijective-base-conversion into AK/String
This allows everybody to create a String version of their number
in a arbitrary bijective base. Bijective base meaning that the mapping
doesn't have a 0. In the usual mapping to the alphabet the follower
after 'Z' is 'AA'.
The mapping using the (uppercase) alphabet is used as a standard but
can be overridden specifying 'base' and 'map'.

The code was directly yanked from the Spreadsheet.
2021-05-01 01:19:40 +02:00
Gunnar Beutner ad688ffc73 AK: Make dbgln log the thread ID
This makes debugging multi-threaded programs easier.
2021-04-29 23:12:05 +02:00
Andreas Kling 3d4afe7614 Everywhere: "indexes" => "indices"
I've wasted a silly amount of time in the past fretting over which
of these words to use. Let's just choose one and use it everywhere. :^)
2021-04-29 22:23:52 +02:00
Andreas Kling 7ae7170d61 Everywhere: "file name" => "filename" 2021-04-29 22:16:18 +02:00
Sahan Fernando c3cf739b94 AK: Make AK::Vector expose allocation failures in API 2021-04-29 09:02:58 +02:00
Linus Groh 649d2faeab Everywhere: Use "the SerenityOS developers." in copyright headers
We had some inconsistencies before:

- Sometimes "The", sometimes "the"
- Sometimes trailing ".", sometimes no trailing "."

I picked the most common one (lowecase "the", trailing ".") and applied
it to all copyright headers.

By using the exact same string everywhere we can ensure nothing gets
missed during a global search (and replace), and that these
inconsistencies are not spread any further (as copyright headers are
commonly copied to new files).
2021-04-29 00:59:26 +02:00
Mart G c9f3cc6dcc AK: Guarantee a maximum stack depth for dual_pivot_quick_sort
When the two chosen pivots happen to be the smallest and largest
elements of the array, three partitions will be created, two of
size 0 and one of size n-2. If this happens on each recursive call
to dual_pivot_quick_sort, the stack depth will reach approximately n/2.

To avoid the stack from deepening, iteration can be used for the
largest of the three partitions. This ensures the stack depth
will only increase for partitions of size n/2 or smaller, which
results in a maximum stack depth of log(n).
2021-04-28 21:38:48 +02:00
Mart G 67b0d04315 AK: Change pivot selection of dual_pivot_quick_sort
Picking the first and last elements as pivots makes it so that
a sorted array is the worst-case input for the algorithm.

This change instead picks pivots at approximately 1/3 and 2/3 in
the array. This results in desired performance for sorted arrays.

Of course this only changes which inputs result in worst-case
performance, but hopefully those inputs occur less frequently than
already sorted arrays.
2021-04-28 21:38:48 +02:00
Jean-Baptiste Boric 7d84f09e7e Userland: Move non-standard math constants from math.h 2021-04-27 23:06:16 +02:00
Gunnar Beutner f57c57966b AK: Fix argument type for JsonArray::at and JsonArray::operator[] 2021-04-26 17:13:55 +02:00
Linus Groh dbe72fd962 Everywhere: Remove empty line after function body opening curly brace 2021-04-25 20:20:00 +02:00
sin-ack bb096429ad Tests: Remove 4chan catalog JSON from tree
According to kling, it was "an early stress test for the JSON decoder"
and can be removed now.
2021-04-25 10:15:15 +02:00
Brian Gianforcaro 87724b3d09 AK: Add default constructor to SourceLocation 2021-04-25 09:38:27 +02:00
Andrew Kaster 35c0a6c54d AK+Userland: Move AK/TestSuite.h into LibTest and rework Tests' CMake
As many macros as possible are moved to Macros.h, while the
macros to create a test case are moved to TestCase.h. TestCase is now
the only user-facing header for creating a test case. TestSuite and its
helpers have moved into a .cpp file. Instead of requiring a TEST_MAIN
macro to be instantiated into the test file, a TestMain.cpp file is
provided instead that will be linked against each test. This has the
side effect that, if we wanted to have test cases split across multiple
files, it's as simple as adding them all to the same executable.

The test main should be portable to kernel mode as well, so if
there's a set of tests that should be run in self-test mode in kernel
space, we can accomodate that.

A new serenity_test CMake function streamlines adding a new test with
arguments for the test source file, subdirectory under /usr/Tests to
install the test application and an optional list of libraries to link
against the test application. To accomodate future test where the
provided TestMain.cpp is not suitable (e.g. test-js), a CUSTOM_MAIN
parameter can be passed to the function to not link against the
boilerplate main function.
2021-04-25 09:36:49 +02:00
Andrew Kaster 89ee38fe5c Tests: Add environment variable for tests only
This is useful for CI where we don't want to spend a minute and a half
benchmarking Vector::append, and we don't have a good way to pass
test-specific arguments yet. :)
2021-04-25 09:36:49 +02:00
Brian Gianforcaro 7a73f11005 LibCpp: Convert ScopeLogger to use AK:SourceLocation
Utilize AK::SourceLocation to get function information into
the scope logger, instead of relying on pre-processor macros.
2021-04-25 09:32:03 +02:00
Brian Gianforcaro 357a13b404 AK: Add a AK::Formatter implementation for AK::SourceLocation 2021-04-25 09:32:03 +02:00
Brian Gianforcaro 0ad29bc3c9 AK: Add SourceLocation support
C++20 added std::source_location, which lets you capture the
callers __FILE__ / __LINE__ / __FUNCTION__ etc as a default
argument to functions.
See: https://en.cppreference.com/w/cpp/utility/source_location

During a bug investigation @ADKaster suggested we could use this
to make the LOCK_DEBUG feature of the kernel more user friendly
and allow it to automatically instrument all call sites.

We then implemented / tested it over discord. :^)

Co-Authored-by: Andrew Kaster <andrewdkaster@gmail.com>
2021-04-24 20:33:00 +02:00
Andreas Kling b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Idan Horowitz f90c224fc5 Revert "AK: Remove virtual destructors from non-virtual classes"
This reverts commit 4378d36f67.
2021-04-23 10:26:14 +02:00
Lenny Maiorani 4378d36f67 AK: Remove virtual destructors from non-virtual classes
Problem:
- Some classes have `virtual` destructors despite not having any
  virtual functions. This causes the classes to have a v-table and
  perform extra jumps at destruction time when there is no need.

Solution:
- Remove `virtual` keyword from destructors where there are no other
  virtual functions.
- Remove the destructor completely when the default destructor can be
  used.
2021-04-23 08:28:25 +02:00
Idan Horowitz 1c512a702a AK+Userland: Use idan.horowitz@serenityos.org for my copyright headers 2021-04-22 22:42:38 +02:00
Ali Mohammad Pur 38418fdfdf AK+Userland: Use mpfard@serenityos.org for my copyright headers 2021-04-22 22:19:09 +02:00
Brian Gianforcaro dc0fc16981 Everywhere: Use bgianf@serenityos.org for my copyright attribution 2021-04-22 21:15:54 +02:00
Lenny Maiorani 254e010c75 AK/GenericLexer: constexpr where possible
Problem:
- Much of the `GenericLexer` can be `constexpr`, but is not.

Solution:
- Make it `constexpr` and de-duplicate code.
- Extend some of `StringView` with `constexpr` to support.
- Add tests to ensure `constexpr` behavior.

Note:
- Construction of `StringView` from pointer and length is not
  `constexpr`-compatible at the moment because the VERIFY cannot be,
  yet.
2021-04-22 20:27:21 +02:00
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Ali Mohammad Pur ba261aba72 AK: Reenable the IntrusiveList<...NonnullRefPtr, ...> tests 2021-04-22 00:20:51 +02:00
Ali Mohammad Pur 88b97f5367 AK: Make IntrusiveList work with NonnullRefPtr's 2021-04-22 00:20:51 +02:00
Andreas Kling edf0b14e23 AK: Remove String::format()
There are no more clients of this function, everyone has been converted
to String::formatted().
2021-04-21 23:49:03 +02:00
Andreas Kling f8dfc74f8b AK: Decorate most of ByteBuffer with [[nodiscard]] 2021-04-21 23:49:01 +02:00
Andreas Kling b0ccb5ba9d AK: Decorate most of String's API's with [[nodiscard]] 2021-04-21 23:49:01 +02:00
Lenny Maiorani e117756d9f AK/Format: Compute TypeErasedParameter type and size at compile-time
Problem:
- Type and size information is known at compile-time, but computations
  are being performed using run-time parameters.

Solution:
- Move function arguments to be template arguments.
- Convert to `consteval` where possible.
- Decorate functions with `constexpr` which are used in both run-time
  and compile-time contexts.
2021-04-21 23:26:16 +02:00
Lenny Maiorani 730fbfb31e AK/Format: Fix incorrectly non-inlined variable templates
Problem:
- Global variables (and variable templates) defined in header files
  need to be decorated `inline` to avoid multiple definition issues.

Solution:
- Put back the `inline` keyword which was erroneously removed.
2021-04-21 21:15:35 +02:00
Lenny Maiorani ece8aeaaf4 Everywhere: Remove redundant inline keyword with constexpr
Problem:
- `constexpr` functions are additionally decorated with `inline`
  keyword. This is redundant since `constexpr` implies `inline`.

Solution:
- Remove redundancies.
2021-04-21 20:49:49 +02:00
Brian Gianforcaro f1d832e5ea AK: Add unit tests to verify AK::InstrusiveList<T> holding RefPtr<T>
Validate that the refcounting works as expected, and continues to work.
2021-04-21 19:31:49 +02:00
Brian Gianforcaro 93e5ba2347 AK: Fix IntrusvieList::take_first/last() actually compile with RefPtr<T>
PR #6376 made IntrusiveList capable of holding RefPtr<T>, etc. however
there was a latent bug where take_first() / take_last() would fail to
compile because they weren't being converted to their container type.
2021-04-21 19:31:49 +02:00
Brian Gianforcaro 0e63a7255e AK: Add some initial unit tests for AK::IntrusiveList 2021-04-21 19:31:49 +02:00
Timothy Flynn 55b7b8e930 AK+Meta: Add a debug option for LibSQL 2021-04-20 18:28:34 +02:00
Leon Albrecht 6f5e92a279
AK/Tests: Install test fixtures required for TestJSON 2021-04-19 18:16:46 +02:00
DexesTTP 8e44a0bd46 AK: Add default ports for Websockets to the URL class 2021-04-18 22:42:10 +02:00
Lenny Maiorani c1971df4c7 AK/Hex: Cleanup implementation
Problem:
- Post-increment of loop index.
- `const` variables are not marked `const`.
- Incorrect type for loop index.

Solution:
- Pre-increment loop index.
- Mark all possible variables `const`.
- Corret type for loop index.
2021-04-18 22:09:25 +02:00
Lenny Maiorani d462a56163 AK/Hex: Decode hex digit in constexpr context
Problem:
- Hex digit decoding is not `constexpr`, but can be.

Solution:
- Move the body of the function to the header and decorate with
  `constexpr`.
- Provide tests for run-time and compile-time evaluation.
2021-04-18 22:09:25 +02:00
Lenny Maiorani 0ac02b9084 AK/Complex: C++20-compatible comparison operators
Problem:
- Clang correctly reports non-`const` member function comparison
  operators as ambiguous.

Solution:
- Make them `const`.
2021-04-18 22:09:25 +02:00
Marco Biscaro 7dc95721ee Tests: Fix test-math expected values
Some of the expected values in test-math were wrong, which caused some
tests to fail.

The updated values were generated by Python's math library, and rounded
to 6 decimals places:

>>> import math
>>> round(math.exp(20.99), 6)
1305693298.670892

Examples of failure outputs:

FAIL: ../Userland/Tests/LibM/test-math.cpp:98:
EXPECT_APPROXIMATE(exp(v.x), v.exp) failed with
lhs=1305693298.670892, rhs=1304956710.432034, (lhs-rhs)=736588.238857

FAIL: ../Userland/Tests/LibM/test-math.cpp:99:
EXPECT_APPROXIMATE(sinh(v.x), v.sinh) failed with
lhs=652846649.335446, rhs=652478355.216017, (lhs-rhs)=368294.119428

FAIL: ../Userland/Tests/LibM/test-math.cpp💯
EXPECT_APPROXIMATE(cosh(v.x), v.cosh) failed with
lhs=652846649.335446, rhs=652478355.216017, (lhs-rhs)=368294.119429
2021-04-18 21:41:17 +02:00
Linus Groh 2b0c361d04 Everywhere: Fix a bunch of typos 2021-04-18 10:30:03 +02:00
Andreas Kling 873da38d0e AK: Remove String-from-StringView optimization
We had an unusual optimization in AK::StringView where constructing
a StringView from a String would cause it to remember the internal
StringImpl pointer of the String.

This was used to make constructing a String from a StringView fast
and copy-free.

I tried removing this optimization and indeed we started seeing a
ton of allocation traffic. However, all of it was due to a silly
pattern where functions would take a StringView and then go on
to create a String from it.

I've gone through most of the code and updated those functions to
simply take a String directly instead, which now makes this
optimization unnecessary, and indeed a source of bloat instead.

So, let's get rid of it and make StringView a little smaller. :^)
2021-04-17 01:27:31 +02:00
Andreas Kling 1f684c8123 AK: Implement case-insensitive StringUtils::matches() without allocs
Previously this would create new to_lowercase()'d strings from the
needle and the haystack. This generated a huge amount of malloc
traffic in some programs.
2021-04-17 01:27:30 +02:00
Andreas Kling f7139d9422 AK: Make LexicalPath take String instead of StringView 2021-04-17 01:27:30 +02:00
AnotherTest e4412f1f59 AK+Kernel: Make IntrusiveList capable of holding non-raw pointers
This should allow creating intrusive lists that have smart pointers,
while remaining free (compared to the impl before this commit) when
holding raw pointers :^)
As a sidenote, this also adds a `RawPtr<T>` type, which is just
equivalent to `T*`.
Note that this does not actually use such functionality, but is only
expected to pave the way for #6369, to replace NonnullRefPtrVector<T>
with intrusive lists.

As it is with zero-cost things, this makes the interface a bit less nice
by requiring the type name of what an `IntrusiveListNode` holds (and
optionally its container, if not RawPtr), and also requiring the type of
the container (normally `RawPtr`) on the `IntrusiveList` instance.
2021-04-16 22:26:52 +02:00
AnotherTest fb814ee720 AK: Avoid the unnecessarily confusing bunch of casts in IntrusiveList
And use bit_cast instead.
Also explain what it does, because it's not at all trivial
to understand :^)
2021-04-16 22:26:52 +02:00
Hendiadyoin1 2e11b2d35a AK: Add outln_if and warnln_if
This uses the same gating mechanism as dbgln_if and should be equivalent
to #define flag etc
2021-04-16 20:03:35 +02:00
Timothy Flynn 99e1d8a359 AK: Add type alias for AK::Optional 2021-04-16 19:19:31 +02:00
Nicholas-Baron 73dd293ec4 Everywhere: Add -Wdouble-promotion warning
This warning informs of float-to-double conversions. The best solution
seems to be to do math *either* in 32-bit *or* in 64-bit, and only to
cross over when absolutely necessary.
2021-04-16 19:01:54 +02:00
Matthew Olsson d719e745fb AK: Fix incorrect formatter signing of numbers between -1.0 and 0.0
Floating point numbers are casted to i64 and passed to the integer
formatting logic, and the floating point portion of the number is
handled separately. However, casting to i64 when the number is between
-1.0 and 0.0 produces 0, so the sign would be lost. This commit fixes
that by using put_u64 instead, which allows us to manually provide the
is_negative flag.
2021-04-16 17:42:42 +02:00
Idan Horowitz 2ab292f381 AK: Expose the decode_hex_digit helper
This helper is useful on its own for things like uri encoding/decoding,
so this commit exposes it via the AK/Hex header
2021-04-14 13:30:10 +02:00
Timothy Flynn 3f4e90f32b AK: Fix StringView::find_last_of for one-character views
The find_last_of implementations were breaking out of the search loop
too early for single-character string views. This caused a crash in
CookieJar setting a cookie on google.com - CookieJar::default_path knew
there was at least one "/" in a string view, but find_last_of returned
nullopt, so dereferencing the optional caused a crash.

Fixes #6273
2021-04-12 22:37:00 +02:00
Timothy Flynn 2370efbea6 AK: Add a predicate variant of StringView::split_view 2021-04-12 22:37:00 +02:00
Idan Horowitz f8a3da46fd AK: Implement IntrusiveRedBlackTree container
This container is similar to the RedBlackTree container, but instead of
transparently allocating tree nodes on insertion and freeing on removal
this container piggybacks on intrusive node fields in the stored class
2021-04-12 18:03:44 +02:00
Idan Horowitz e962254eb2 AK: Implement RedBlackTree container
This container is based on a balanced binary search tree, and as such
allows for O(logn) worst-case insertion, removal, and search, as well
as O(n) sorted iteration.
2021-04-12 18:03:44 +02:00
Tim Waterhouse 4d81d868c7 AK: Update LexicalPath::relative_path to work for '/' prefix
If the prefix path is just a slash the LexicalPath was removing too many
characters. Now only remove an extra character if the prefix is not just
the root path.
2021-04-11 19:19:49 +02:00
Brian Gianforcaro 7db74a6b3e AK: Annotate StringBuilder functions as [[nodiscard]] 2021-04-11 12:50:33 +02:00
Brian Gianforcaro 23454cab46 AK: Annotate WeakPtr functions as [[nodiscard]] 2021-04-11 12:50:33 +02:00
Brian Gianforcaro 56ab0da6a4 AK: Annotate Trie functions as [[nodiscard]] 2021-04-11 12:50:33 +02:00
Brian Gianforcaro 75e7c780e7 AK: Annotate StringView functions as [[nodiscard]] 2021-04-11 12:50:33 +02:00
Brian Gianforcaro 28e40e22c0 AK: Annotate IntrusiveList functions as [[nodiscard]] 2021-04-11 12:50:33 +02:00
Brian Gianforcaro 0593fa4dcb AK: Annotate HashTable functions as [[nodiscard]] 2021-04-11 12:50:33 +02:00
Brian Gianforcaro 15b94ec1fd AK: Make HashTable with capacity constructor explicit 2021-04-11 12:50:33 +02:00
Brian Gianforcaro a8671ec166 AK: Annotate HashMap functions with [[nodiscard]] 2021-04-11 12:50:33 +02:00
Brian Gianforcaro eaa9ec9b5d AK: Annotate DoublyLinkedList functions with [[nodiscard]] 2021-04-11 12:50:33 +02:00
Brian Gianforcaro 5165661799 AK: Annotate Checked functions with [[nodiscard]] 2021-04-11 12:50:33 +02:00
AnotherTest a6e4482080 AK+Everywhere: Make StdLibExtras templates less wrapper-y
This commit makes the user-facing StdLibExtras templates and utilities
arguably more nice-looking by removing the need to reach into the
wrapper structs generated by them to get the value/type needed.
The C++ standard library had to invent `_v` and `_t` variants (likely
because of backwards compat), but we don't need to cater to any codebase
except our own, so might as well have good things for free. :^)
2021-04-10 21:01:31 +02:00
Andreas Kling c268df79e6 AK: Add BitmapView::set_range_and_verify_that_all_bits_flip()
This function sets a range of bits to the same value while also
verifying that all bits in the range get flipped in the process.
2021-04-09 17:08:49 +02:00
Jelle Raaijmakers c4e19250a1 Format: Strip trailing zeroes from floating point values
This is a pretty naive implementation that works well. The precision
parameter is interpreted as "maximum precision" instead of "minimum
precision", which in my opinion is the most useful interpretation.
2021-04-08 20:30:56 +02:00
Jelle Raaijmakers 4bfd394384 Tests: Merge duplicate TestFormat test into AK directory 2021-04-08 20:30:56 +02:00
thislooksfun e55b8712d4 AK: Inline HashTable writing bucket lookup
The old approach was more complex and also had a very bad edge case
with lots of collisions. This approach eliminates that possiblility.
It also makes both reading and writing lookups a little bit faster.
2021-04-02 12:54:54 +02:00
thislooksfun 509eb10df4 AK: Inline the bucket index calculation
The result of the modulo is only used in the array index, so why
make the code more complex by calculating it in two different places?
2021-04-02 12:54:54 +02:00
thislooksfun 8fb7739cfb AK: Add tests for HashTable 2021-04-02 12:54:54 +02:00
Linus Groh f418115f1b LibJS: Add initial support for Promises
Almost a year after first working on this, it's finally done: an
implementation of Promises for LibJS! :^)

The core functionality is working and closely following the spec [1].
I mostly took the pseudo code and transformed it into C++ - if you read
and understand it, you will know how the spec implements Promises; and
if you read the spec first, the code will look very familiar.

Implemented functions are:

- Promise() constructor
- Promise.prototype.then()
- Promise.prototype.catch()
- Promise.prototype.finally()
- Promise.resolve()
- Promise.reject()

For the tests I added a new function to test-js's global object,
runQueuedPromiseJobs(), which calls vm.run_queued_promise_jobs().
By design, queued jobs normally only run after the script was fully
executed, making it improssible to test handlers in individual test()
calls by default [2].

Subsequent commits include integrations into LibWeb and js(1) -
pretty-printing, running queued promise jobs when necessary.

This has an unusual amount of dbgln() statements, all hidden behind the
PROMISE_DEBUG flag - I'm leaving them in for now as they've been very
useful while debugging this, things can get quite complex with so many
asynchronously executed functions.

I've not extensively explored use of these APIs for promise-based
functionality in LibWeb (fetch(), Notification.requestPermission()
etc.), but we'll get there in due time.

[1]: https://tc39.es/ecma262/#sec-promise-objects
[2]: https://tc39.es/ecma262/#sec-jobs-and-job-queues
2021-04-02 10:47:40 +02:00
vcollette 804ab79995
AK: Fix bogus return type of Result::release_error() (#6054)
The function was not used anywhere so the error was unnoticed.
2021-04-01 21:03:57 +02:00
Michel Hermier 7d591432c4 AK: Add Signed/Unsigned concepts. 2021-03-28 11:45:51 +02:00
Michel Hermier 4f1c72c174 AK: Add IsSigned conterpart to IsUnsigned. 2021-03-28 11:45:51 +02:00
Michel Hermier d77cbc0fa8 AK: Remove IsSigned<char> test as it is platform/compiler dependant. 2021-03-28 11:45:51 +02:00
Michel Hermier b8fac0a8b3 AK: Make Concepts.h and StdLibExtras.h properly alias their own sumbols. 2021-03-28 11:45:51 +02:00
Cesar Torres f4f5a1c0e7 AK: Add complex number library
Useful for diverse algorithms.
Also added some tests for it.
2021-03-27 10:20:55 +01:00
Timothy Flynn 4babf6e4e1 AK: Allow assigning a value to a specific index in a JsonArray 2021-03-26 22:58:31 +01:00
Idan Horowitz edecf8f6a3 AK: Add starts_with to Utf8View
Unlike String/StringView::starts_with this compares utf8 code points
instead of "characters" (bytes), which is important when handling
aribtary utf-8 input that could include overlong characters.
2021-03-25 10:59:34 +01:00
David Isaksson 17c0349d23 AK: Add longer human readable size to string helper function
Wraps the existing AK::human_readable_size function but will always
display the bytes in the base unit as well as the shorter string with
one decimal. E.g. "14 KiB (14396 bytes)".
2021-03-25 10:59:11 +01:00
Andreas Kling d20e3dbe8b LibGUI: Remove one ancient GMENU_DEBUG debug log 2021-03-23 20:37:39 +01:00
Oleg Sikorskiy e99dabc729 AK: Implement bit_cast 2021-03-23 08:22:15 +01:00
Hendiadyoin1 0d934fc991 Kernel::CPU: Move headers into common directory
Alot of code is shared between i386/i686/x86 and x86_64
and a lot probably will be used for compatability modes.
So we start by moving the headers into one Directory.
We will probalby be able to move some cpp files aswell.
2021-03-21 09:35:23 +01:00
Hendiadyoin1 60caffb113 AK+LibC: Make %p specifier Architecture Independent
We were using u32 as a pointer representation and not FlatPtr
2021-03-21 09:35:23 +01:00
Hendiadyoin1 f673f08bec AK: Fix integer_sequence_generate_array
It was for some reason Architecture dependent.
Now we use size_t instead of unsinged long
2021-03-21 09:35:23 +01:00
Hendiadyoin1 7ba3c22931 AK: Add a Ptr32 type to handle fixed sized pointers
This will be used to fix the UHCI Controller, which relies on
the pointer-size being 32-bit
2021-03-21 09:35:23 +01:00
Jean-Baptiste Boric 607fac662d AK: Implement terabytes, petabytes, exabytes 2021-03-17 23:22:42 +01:00
Jean-Baptiste Boric 7ffc6c371a AK: Add 64 bit methods to JsonValue 2021-03-17 23:22:42 +01:00
Andreas Kling ea81dc13cf AK: Move move() into the "std" namespace
This makes GCC emit warnings about redundant and pessimizing moves.
It also allows static analyzers like clang-tidy to detect common bugs
like use-after-move.
2021-03-17 16:31:17 +01:00
Andreas Kling f59ad2dc57 Everywhere: Remove pessimizing and redundant move() 2021-03-17 16:30:15 +01:00
Brendan Coles fa28cc85e6 AK: Tests: TestURL: Add port_int_overflow_wrap test 2021-03-17 12:39:03 +01:00
Idan Horowitz ea5f83616e LibCompress+AK: Dont short-circuit error handling propagation
In the case that both the stream and the wrapped substream had errors
to be handled only one of the two would be resolved due to boolean
short circuiting. this commit ensures both are handled irregardless
of one another.
2021-03-16 14:56:50 +01:00
Idan Horowitz a955fd4156 LibCompress+AK: Propagate error handling to wrapped streams
This ensures that when a DeflateCompressor stream is cleared of any
errors its underlying wrapped streams (InputBitStream/InputMemoryStream)
will be cleared as well and wont fail a VERIFY on destruction.
2021-03-15 21:35:48 +01:00
Andreas Kling 64cb04996f AK: Make ByteBuffer::slice(0, size()) a freebie
If you want the whole buffer, we can just give you the buffer itself.
2021-03-15 18:01:11 +01:00
Idan Horowitz 1b7b503bae AK: Add fast paths for aligned bit writes in BitOutputStream
If the bit write is aligned (or has been aligned during the write) we can
write in multiples of 32/16/8 bits for increased performance.
2021-03-13 23:50:07 +01:00
Idan Horowitz 3c7aa56ae8 AK: Store BinaryHeap key-value pairs together for efficient swaps
The 2 seperate key and value arrays are replaced with a single struct pair
array that allows for a 2x reduction in loads/stores during element swaps
in the common case of same-sized keys and values.
2021-03-13 23:50:07 +01:00
Idan Horowitz 168cf6fac9 AK: Implement minimum BinaryHeap
This enables efficient implementations of priority queues,
and will also be used in LibCompress for efficient huffman
tree generation.
2021-03-13 20:07:25 +01:00
Idan Horowitz 0ddc0e45ae AK: Add OutputBitStream class
This will be used in the deflate compressor.
2021-03-13 20:07:25 +01:00
Ben Wiederhake 81079ae616 AK: Fix some overflows/underflows that weren't properly handled
Based on #5699. Closes #5699.
2021-03-13 10:17:28 +01:00
Tom 8a8bdb2cd7 AK: Add decrement operator to Checked 2021-03-13 10:17:28 +01:00
Andreas Kling d3f112f9a2 AK+LibCore: Remove empty files 2021-03-12 17:38:17 +01:00
Andreas Kling ef1e5db1d0 Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)
Good-bye LogStream. Long live AK::Format!
2021-03-12 17:29:37 +01:00
Andreas Kling 1b2ea12062 AK: Add basic const iteration to IntrusiveList 2021-03-11 14:21:49 +01:00
Andreas Kling 4d30166d61 AK: Add Formatter for RefPtr 2021-03-09 22:10:41 +01:00
Mițca Dumitru 8f7aa1e03a AK: Include Assertions.h in StdLibExtras.h 2021-03-09 07:28:06 +01:00
Brian Gianforcaro c825159f01 AK: Add AK_ENUM_BITWISE_OPERATORS(..) to enable type-safe enum bitwise operations
This change introduces `AK_ENUM_BITWISE_OPERATORS(..)` which when
enabled for an enum, will automatically declare all the necessary
bitwise operators for that enum.

This allows bit masks enums to be used as first class, type safe, citizens.
2021-03-08 18:47:40 +01:00
Tom 183b2e71ba AK: Take advantage of constexpr in Time and add time conversion methods
By making the Time constructor constexpr we can optimize creating a
Time instance from hardcoded values.

Also add more functions to convert between Time and various time units.
2021-03-08 15:29:11 +01:00
Tom 42bc229500 AK: Initialize the AK::Time members
Since we tell the compiler to provide a default constructor we
need to initialize the member variables.
2021-03-08 15:29:11 +01:00
Andreas Kling 483b45db3f AK: JsonObject::value_or() fallback value should be a const reference 2021-03-08 11:50:36 +01:00
Ben Wiederhake b6472204e5 AK+Tests: Also test Checked<> with unsigned
As expected, Checked<unsigned> works as intended. However, we didn't have a
test for that, so I added one.

See also 90c070cb1d.
2021-03-07 17:31:25 +01:00
speles 50de653cc9 AK: Add optional fragment parameter to create_with_file_protocol()
Now that we use fragment for specifying starting selection in
FileManager we would benefit from providing it as argument instead of
setting it each time separately.
2021-03-07 11:00:36 +01:00
Brian Gianforcaro fc5b252010 AK: Implement IsEnum<T> and UnderlyingType<T> type traits
I needed these meta-programming type traits while working on something else.
Add basic support for these two type traits as well as some tests.
2021-03-05 11:30:13 +01:00
Liav A 4a5cf8c789 AK: Add a full memory barrier function based on atomic operations
We use atomic_signal_fence and atomic_thread_fence together to prevent
reordering of memory accesses by the CPU and the compiler.

The usage of these functions was suggested by @tomuta so we can be sure
that important memory accesses happen in the expected order :)
2021-03-05 11:29:34 +01:00
Andreas Kling 1208fc7d37 AK: Simplify Bitmap and implement in terms of BitmapView
Add Bitmap::view() and forward most of the calls to BitmapView since
the code was identical.

Bitmap is now primarily concerned with its dynamically allocated
backing store and BitmapView deals with the rest.
2021-03-04 11:25:45 +01:00
Andreas Kling 40552bb5fb AK: Add BitmapView class (like StringView but for bitmaps)
AK::Bitmap is an awkwardly modal class which can either own or wrap
the underlying data. To get ourselves out of this unpleasant situation,
this patch adds BitmapView to replace the wrapped mode.

A BitmapView is simply a { data pointer, bit count } tuple internally
and provides all the convenient functionality of a bitmap class.
2021-03-04 11:25:45 +01:00
AnotherTest e59a631511 HackStudio/LanguageServers: Move some components out of Cpp
This makes them available for use by other language servers.
Also as a bonus, update the Shell language server to discover some
symbols and add go-to-definition functionality :^)
2021-03-04 11:21:43 +01:00
William McPherson 2479ead718 Everywhere: Remove unnecessary clang-format offs
Mostly due to the fact that clang-format allows aligned comments via
AlignTrailingComments.

We could also use raw string literals in inline asm, which clang-format
deals with properly (and would be nicer in a lot of places).
2021-03-04 11:01:48 +01:00
Andreas Kling ddaeb294dc AK: Add Bitmap::is_null()
This class has a null state but there was no API to check for it.
2021-03-04 10:11:37 +01:00
Linus Groh a5d6962148 AK+Kernel: Remove NO_DISCARD macro hack
This was added as clang-format would mess up the formatting when using
[[nodiscard]] on a class, which is no longer the case.
2021-03-03 23:08:42 +01:00