Commit graph

1685 commits

Author SHA1 Message Date
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
Ben Wiederhake cf32f29af6 AK+LibM: Rename EXPECT_CLOSE to EXPECT_APPROXIMATE 2021-03-03 20:19:24 +01:00
Ben Wiederhake 5df014b8ff AK+LibM: Make EXPECT_CLOSE more useful during debugging 2021-03-03 20:19:24 +01:00
ihsinme 69f82ede7a AK: Fix OOO mistake in StackInfo.cpp
"!=" has higher priority than "=".
2021-03-03 11:09:44 +01:00
Ben Wiederhake 340813e087 AK: Make Time more usable 2021-03-02 08:36:08 +01:00
Ben Wiederhake e510c41fd2 Kernel: Prevent using copy_from_user() for timespec/timeval
These structs can be inconsistent, for example if the amount of microseconds is
negative or larger than 1'000'000. Therefore, they should not be copied as-is.
Use copy_time_from_user instead.
2021-03-02 08:36:08 +01:00
Ben Wiederhake bd6be910e5 AK: Implement C++ 'Time' type for easier time-calculations
This adds a bunch of code in the hope that other, wrong code can be deleted.

Related to #5315.
2021-03-02 08:36:08 +01:00
Ben Wiederhake b7c5d977c7 AK: Remove unused template 2021-03-02 08:36:08 +01:00
Ben Wiederhake 90c070cb1d AK+Tests: Test Checked for main functionality 2021-03-02 08:36:08 +01:00
Andrew Kaster 669b6c43aa AK/Lagom: Modify TestSuite to return how many tests failed from main
This allows us to remove the FAIL_REGEX logic from the CTest invocation
of AK and LibRegex tests, as they will return a non-zero exit code on
failure :^).

Also means that running a failing TestSuite-enabled test with the
run-test-and-shutdown script will actually print that the test failed.
2021-03-01 11:12:36 +01:00
Andrew Kaster e787738c24 Meta: Build AK and LibRegex tests in Lagom and for Serenity
These tests were never built for the serenity target. Move their Lagom
build steps to the Lagom CMakeLists.txt, and add serenity build steps
for them. Also, fix the build errors when building them with the
serenity cross-compiler :^)
2021-02-28 18:19:37 +01:00
Sviatoslav Peleshko 183ebaee91 LibWeb: Add actual document loading for the CSS (at)import rule 2021-02-28 10:27:32 +01:00
Andreas Kling daf18e7777 AK: Use Array iterator instead of indexing outside Array bounds 2021-02-27 11:48:25 +01:00
Andreas Kling 69d8ad52c4 AK: Always do bounds checking in Array::operator[] 2021-02-27 09:23:32 +01:00
Linus Groh e265054c12 Everywhere: Remove a bunch of redundant 'AK::' namespace prefixes
This is basically just for consistency, it's quite strange to see
multiple AK container types next to each other, some with and some
without the namespace prefix - we're 'using AK::Foo;' a lot and should
leverage that. :^)
2021-02-26 16:59:56 +01:00
Andreas Kling 42133a196a AK: Don't compare past '\0' in StringView::operator==(const char*)
We kept scanning the needle string even after hitting a null terminator
and that's clearly not right.

Found by oss-fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31338
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31351
2021-02-24 22:13:04 +01:00
Brian Gianforcaro 31e1b08e15 AK: Add support for AK::StringView literals with operator""sv
A new operator, operator""sv was added as of C++17 to support
string_view literals. This allows string_views to be constructed
from string literals and with no runtime cost to find the string
length.

See: https://en.cppreference.com/w/cpp/string/basic_string_view/operator%22%22sv

This change implements that functionality in AK::StringView.
We do have to suppress some warnings about implementing reserved
operators as we are essentially implementing STL functions in AK
as we have no STL :).
2021-02-24 14:38:31 +01:00
Linus Groh 6ad3454bfb AK: Rename {DBGLN_NO => ENABLE}_COMPILETIME_FORMAT_CHECK
This is no longer limited to dbgln(). Also invert it to match all the
other ENABLE_FOO options.
2021-02-24 13:07:57 +01:00
AnotherTest 857cdee0d0 AK: Make dbgln_if() avoid evaluating the arguments when disabled
Naturally, this makes the `enabled` flag on dbgln() obsolete.
2021-02-24 13:07:28 +01:00
Andreas Kling 679cc154e6 Everywhere: Remove unused RELEASE_ASSERT macro 2021-02-23 21:11:53 +01:00
Andreas Kling 5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling 145923bdc9 AK: Slap Optional with the ALWAYS_INLINE stick
I saw some Optional constructors when profiling the dynamic loader
and that seemed silly since we can inline them at no/little cost.
2021-02-23 17:42:05 +01:00
Andreas Kling 31ac93d051 AK: Optimize StringView::operator==(const char*) a little bit
Don't compute the strlen() of the string we're comparing against first.
This can save a lot of time if we're comparing against something that
already fails to match in the first few characters.
2021-02-23 17:41:18 +01:00
AnotherTest 7c2754c3a6 AK+Kernel+Userland: Enable some more compiletime format string checks
This enables format string checks for three more functions:
- String::formatted()
- Builder::appendff()
- KBufferBuilder::appendff()
2021-02-23 13:59:33 +01:00
AnotherTest 347d741afb AK+Userland: Extend the compiletime format string check to other functions
Thanks to @trflynn89 for the neat implicit consteval ctor trick!
This allows us to basically slap `CheckedFormatString` on any
formatting function, and have its format argument checked at compiletime.

Note that there is a validator bug where it doesn't parse inner replaced
fields like `{:~>{}}` correctly (what should be 'left align with next
argument as size' is parsed as `{:~>{` following a literal closing
brace), so the compiletime checks are disabled on these temporarily by
forcing them to be StringViews.

This commit also removes the now unused `AK::StringLiteral` type (which
was introduced for use with NTTP strings).
2021-02-23 13:59:33 +01:00
AnotherTest 644d981b2b AK: Untangle TestSuite assertions a bit 2021-02-23 13:59:33 +01:00
Linus Groh 4fafe14691 AK: Add String{,Utils}::to_snakecase()
This is an improved version of WrapperGenerator's snake_name(), which
seems like the kind of thing that could be useful elsewhere but would
end up getting duplicated - so let's add this to AK::String instead,
like to_{lowercase,uppercase}().
2021-02-21 19:47:47 +01:00
Ivan Hansgaard Hansen 46ca7d3cb5 AK: Alter ByteBuffer to utilise memcmp.
__builtin_memcmp is already heavily utilised in AK.
2021-02-21 16:34:51 +01:00
Andreas Kling a65f178ce8 AK: Do bounds checking (assertions) in Span::operator[] 2021-02-21 14:21:20 +01:00
Brian Gianforcaro df73a86875 AK: Add an implementation of Array<T, Size>::fill(...) 2021-02-21 12:54:39 +01:00
Brian Gianforcaro 21a959e29b AK: Add Span<T> constructor for arrays
The array constructor allows arrays to be easily treated
as generic span of data.
2021-02-21 12:54:39 +01:00
Brian Gianforcaro 5e84320ecb AK: Add safe memset() wrapper to ByteBuffer
In the interest memory safety and of removing as many
of foot guns as possible (like raw memset's which are
notorious for typo's), a zeroing method seems like a
useful utility to have on a buffer class.
2021-02-21 11:52:47 +01:00
AnotherTest 074e2ffdfd LibLine: Avoid refreshing the entire line when inserting at the end
This patchset allows the editor to avoid redrawing the entire line when
the changes cause no unrecoverable style updates, and are at the end of
the line (this applies to most normal typing situations).
Cases that this does not resolve:
- When the cursor is not at the end of the buffer
- When a display refresh changes the styles on the already-drawn parts
  of the line
- When the prompt has not yet been drawn, or has somehow changed

Fixes #5296.
2021-02-20 22:28:23 +01:00
Andreas Kling 81c6d8e98e AK: Make Nonnull*PtrVector use size_t for indexes
This was weird. It turns out these class were using int indexes and
sizes despite being derived from Vector which uses size_t.

Make the universe right again by using size_t here as well.
2021-02-20 18:34:32 +01:00
Andreas Kling 4d9ce42532 AK: Remove unused kprintf macro
This hasn't been used for quite some time.
2021-02-20 17:21:03 +01:00
Andreas Kling 8d98051551 AK+LibC: Remove dbgprintf() :^)
Everything has been moved to dbgln() or other AK::Format-based APIs.
We can finally get rid of this old thing.
2021-02-20 17:17:30 +01:00
Itamar 7ecb21afa7 AK: Add LexicalPath::relative_path 2021-02-20 15:53:37 +01:00
Andreas Kling 1f401def18 AK: Publish all_of() 2021-02-17 15:22:21 +01:00
Brian Gianforcaro 3356f438ca AK: Mark Optional getters as [[nodiscard]]
There is no reason to call a getter without observing the result, doing
so indicates an error in the code. Mark these methods as [[nodiscard]]
to find these cases.
2021-02-15 09:34:52 +01:00
AnotherTest 3fe7ac0924 LibCrypto: Make a better ASN.1 parser
And use it to parse RSA keys.
As a bonus, this one shouldn't be reading out of bounds or messing with
the stack (as much) anymore.
2021-02-14 13:30:10 +01:00
AnotherTest 4d40864b9d AK: Make the Bitmap::size_in_bytes() member function public
It's annoying to calculate it when it's already a member function.
2021-02-14 13:30:10 +01:00
Paul Scharnofske 35a1e12459 AK+Format: Don't cast to size_t when you want u64.
In Serenity, size_t is defined as u32, thus static_cast<size_t>(value)
truncates the value.
2021-02-13 19:47:06 +01:00
Ben Wiederhake 5963f2084e Utilities: Make syscall(1) explain what it's doing 2021-02-13 00:40:31 +01:00
Linus Groh feb66564d2 AK: Set DBGLN_NO_COMPILETIME_FORMAT_CHECK for any clang, not just < 12
This currently breaks the OSS-Fuzz build, and attempts to make it build
with clang >= 12 were unsuccessful, so let's just disable dbgln() checks
for any clang version.
2021-02-12 19:19:43 +01:00
Linus Groh ca69cab532 Revert "AK: Fix build with Clang>=12"
This reverts commit 338bb73289.

This didn't work, the OSS-Fuzz build (using clang 12) is still failing.
We'll just disable dbgln() checks when compiling with any clang for now.
2021-02-12 19:19:43 +01:00
Andreas Kling acf341862a AK: Remove operators && and || from DistinctNumeric
These don't do short-circuit evaluation, and so I ran into some
some very subtle side-effects when converting code to DistinctNumeric.

In code like this:

    MyDistinctNumeric n;
    if (n && check_thing(n))
        return;

There would be no short-circuit evaluation if the return type of
check_thing() was implicitly convertible to MyDistinctNumeric.

Ran into this while making Ext2FS::GroupIndex a DistinctNumeric.
2021-02-12 13:27:48 +01:00
Andreas Kling e00f519cdd AK: Add formatter for DistinctNumeric 2021-02-12 12:31:09 +01:00