Commit graph

1512 commits

Author SHA1 Message Date
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