Commit Graph

2211 Commits

Author SHA1 Message Date
Hendiadyoin1
b429f9c7aa AK: Add implied const qualifiers to the Json interface
As specified by clang-tidy.
2021-12-15 23:35:14 -08:00
Hendiadyoin1
b39c4c62d0 AK: Use StringView as key-type when removing a Value from an JsonObject 2021-12-15 23:35:14 -08:00
Hendiadyoin1
e35709cbd2 AK: Return bool in JsonValue::as_bool() 2021-12-15 23:35:14 -08:00
Andrew Kaster
db33cdbc2f AK+LibSanitizer: Add method to zero out a UBSAN SourceLocation
This is the same strategy that LLVM's compiler-rt uses to make sure that
each UBSAN error is only reported once, when UBSAN is *not* deadly.

Otherwise, each time we head through a UB codepath, we will log the same
error over and over. That behavior just adds noise to the logs and makes
it nearly impossible to run binaires that have some common code path
with flagged UB in them.

compiler-rt goes the extra step to make sure the "clear" action is
atomic, but we don't really have that many multi-threaded apps gettting
tested with UBSAN yet, so we can add that later.
2021-12-15 10:30:32 -08:00
Hendiadyoin1
422b624743 AK: Convert JsonObject to use StringViews for lookup
Most of the Keys we use are compile-time strings anyway, there is no
need to use the heap to pass them around.
2021-12-15 13:09:49 +03:30
Hendiadyoin1
d50360f5dd AK: Allow hash-compatible key types in Hash[Table|Map] lookup
This will allow us to avoid some potentially expensive type conversion
during lookup, like form String to StringView, which would allocate
memory otherwise.
2021-12-15 13:09:49 +03:30
Hendiadyoin1
c8bee92fb9 AK: Add the concept of hash-compatible types 2021-12-15 13:09:49 +03:30
Hendiadyoin1
92e824afa1 AK: Add a Concept for any String type 2021-12-15 13:09:49 +03:30
Hendiadyoin1
6c6e917cf0 AK: Add dedicated Traits for c-strings 2021-12-15 13:09:49 +03:30
Hendiadyoin1
ceb0e28ea5 AK: Add helper to test for pointer and cv-pointer at the same time 2021-12-15 13:09:49 +03:30
Hendiadyoin1
dfe2cf3a40 AK: Add a Decay helper for Concepts 2021-12-15 13:09:49 +03:30
Martin Blicha
c4c8f59284 AK: Fix preprocessor OS check
Instead of checking __linux__ macro directly, the code should check if
this macro is defined. This is already done correctly a couple of lines
above.

I ran into this when trying to build libjs-test262 on MacOS where I got
the following error message
   error: "__linux__" is not defined, evaluates to 0 [-Werror=undef]
2021-12-12 11:10:34 -08:00
Jelle Raaijmakers
bc36e39d07 AK: Simplify Array::back() by checking for Size > 0
We do not want `Array::max()` to be used here at all - we know the
size at compile-time, after all.
2021-12-11 23:15:24 +01:00
Andreas Kling
c9a35e104b AK: Add RefCountForwarder<T>
This is a convenience template that implements reference count
forwarding. This means that an object forwards ref() and unref() to
another object.

We can use this when two ref-counted objects need to keep each other
alive. This situation poses two problems:

- Using 2x RefPtr would cause a ref cycle and leak both objects.
- Using 2x WeakPtr would allow one of them to be destroyed early.

With RefCountForwarder, only one of the objects has a ref count. The
object with the ref count points to the forwarding object by using a
non-counting smart pointer (OwnPtr or NonnullOwnPtr). Thus, both objects
are kept alive by the same ref count, and they can safely point to each
other without worrying about disjoint lifetimes.
2021-12-09 21:28:52 +01:00
Tim Schumacher
5c511de4cc AK: Zero-pad automatically if formatting with precision 2021-12-07 20:13:59 -08:00
Ben Wiederhake
6f37510a71 AK: Implement missing const getters in AK::Error, fix typo
Note that the return type for the non-const method error() changed. This
is most likely an accident, hidden by the fact that ErrorType typically
is Error.
2021-12-05 22:59:09 +01:00
Ben Wiederhake
dbd60f9ff4 AK: Implement Formatter for ErrorOr<>
As the Formatter for Error already exists, this apparently was just
accidentally omitted.
2021-12-05 22:59:09 +01:00
Sam Atkins
5013a6480d AK: Mark smart pointer classes as [[nodiscard]]
This makes it an error to not do something with a returned smart
pointer, which should help prevent mistakes. In cases where you do need
to ignore the value, casting to void will placate the compiler.

I did have to add comments to disable clang-format on a couple of lines,
where it wanted to format the code like this:

```c++
private : NonnullRefPtr() = delete;
```
2021-12-05 15:31:03 +01:00
James Mintram
ef52fe7d2f Kernel: Add VALIDATE_IS_X86 macro 2021-12-01 11:22:04 -08:00
Andreas Kling
cb9cac4e40 LibIPC+IPCCompiler+AK: Make IPC value decoders return ErrorOr<void>
This allows us to use TRY() in decoding helpers, leading to a nice
reduction in line count.
2021-11-28 23:14:19 +01:00
kleines Filmröllchen
295eec2d49 AK: Stop Vector::extend from unnecessary reallocation
Previously, Vector::extend for a moved vector would move the other
vector into this vector if this vector was empty, thereby throwing away
existing allocated capacity. Therefore, this commit allows the move to
only happen if this vector's capacity is too small to fit the other
vector. This will also alleviate bugs where callers relied on the
capacity to never shrink with calls to unchecked_append, extend and the
like.
2021-11-28 13:33:51 -08:00
kleines Filmröllchen
05cb499d58 AK: Add Vector::unchecked_append for data pointers
This mirrors the existence of append() for data pointers and is very
useful when the program needs to have a guarantee of no allocations,
as is necessary for real-time audio.
2021-11-28 13:33:51 -08:00
kleines Filmröllchen
cbb2b4fe71 AK: Expose Buffered's buffer size and underlying stream 2021-11-28 13:33:51 -08:00
Hendiadyoin1
6f74c1bb11 AK: Allow to "get a result" from Result<void>
This is to make Result<void> work inside TRY
2021-11-28 13:33:51 -08:00
Ben Wiederhake
b1982267b2 AK: Remove unused static member of Bitmap
This is a remnant of the Bitmap/BitmapView split.
2021-11-28 13:16:41 -08:00
csb6
d55dfe2418 AK: On macOS host builds, wrap unistd.h with missing extern "C"
During the build process on macOS, multiple versions of <unistd.h> were
being included (Apple's version and GCC's version). It appears that
all other places #include the version from GCC, but in Platform.h the
Apple header was being used. GCC's <unistd.h> is wrapped in
`extern "C"`, while Apple's is not. This causes a conflicting
declaration, so we need to wrap the #include with extern "C".

Issue has been observed on macOS Mojave.

See https://github.com/microsoft/vcpkg/issues/11320 for a similar issue.
2021-11-23 18:48:59 +00:00
Andreas Kling
58fb3ebf66 LibCore+AK: Move MappedFile from AK to LibCore
MappedFile is strictly a userspace thing, so it doesn't belong in AK
(which is supposed to be user/kernel agnostic.)
2021-11-23 11:33:36 +01:00
Andreas Kling
4e530135d5 AK+LibSystem+LibMain: Add Error::from_syscall() for syscall failures
This creates an error that contains the name of the syscall that failed.
This allows error handlers to print out the name of the call if they
want to. :^)
2021-11-22 19:28:31 +01:00
Tim Schumacher
07351762c7 AK: Add LexicalPath::prepend() 2021-11-22 09:03:47 +01:00
Andrew Kaster
bf33a14081 AK: Mark MemMem header-only functions as inline rather than static
Avoid including a per-translation unit copy of all these functions.

Also, drive-by two clang-tidy fixes for readability-qualified-auto and
readability-implicit-bool-conversion.
2021-11-22 05:23:24 +03:30
James Mintram
bcd518a228 Kernel: Wrap format timespec assignment in a check for !AARCH64
Currently TimeManagement wont compile on AARCH64, so it is not included.
This creates a link error since format.cpp now relies on functionality
in TimeManagement.cpp to add timestamps to log lines.

This PR disables that functionality for AARCH64 builds until
TimeManagement will compile.
2021-11-21 09:12:16 +01:00
Andreas Kling
0f22ba5bf2 AK: Make RedBlackTree::try_insert() return ErrorOr<void> instead of bool 2021-11-18 21:11:30 +01:00
Jelle Raaijmakers
dfbdd035da AK: Implement acos<T> correctly
This is a naive implementation based on the symmetry with `asin`.

Before, I'm not really sure what we were doing, but it was returning
wildly incorrect results.
2021-11-18 21:10:30 +01:00
Andreas Kling
8fe1c1f788 AK: Add missing return in Formatter<unsigned char[Size]>::format()
Caught by ENABLE_ALL_THE_DEBUG_MACROS.
2021-11-17 07:45:10 +01:00
Andreas Kling
216e21a1fa AK: Convert AK::Format formatting helpers to returning ErrorOr<void>
This isn't a complete conversion to ErrorOr<void>, but a good chunk.
The end goal here is to propagate buffer allocation failures to the
caller, and allow the use of TRY() with formatting functions.
2021-11-17 00:21:13 +01:00
Andreas Kling
008355c222 AK: Add failable try_* functions to StringBuilder
These will allow us to start using TRY() with StringBuilder operations.
2021-11-17 00:21:13 +01:00
Andreas Kling
11aad74dce AK: Forward declare Error and ErrorOr in AK/Forward.h 2021-11-17 00:21:12 +01:00
Andreas Kling
587f9af960 AK: Make JSON parser return ErrorOr<JsonValue> (instead of Optional)
Also add slightly richer parse errors now that we can include a string
literal with returned errors.

This will allow us to use TRY() when working with JSON data.
2021-11-17 00:21:10 +01:00
Hendiadyoin1
6cb42d8a40 AK: Verify that we are not overreaching in StringView's substring_view() 2021-11-16 00:49:48 +00:00
Andrew Kaster
f1d8978804 AK+Kernel: Remove implicit conversion from Userspace<T*> to FlatPtr
This feels like it was a refactor transition kind of conversion. The
places that were relying on it can easily be changed to explicitly ask
for the ptr() or a new vaddr() method on Userspace<T*>.

FlatPtr can still implicitly convert to Userspace<T> because the
constructor is not explicit, but there's quite a few more places that
are relying on that conversion.
2021-11-16 00:13:22 +01:00
Andrew Kaster
6f580f2047 AK: Resolve clang-tidy readability-const-return-type warning in Bitmap
Returning a const BitmapView doesn't make much sense :^)
2021-11-14 22:52:35 +01:00
Andrew Kaster
f32e185269 AK: Suppress false positive readability-non-const-parameter in Function
In AK::Function::CallableWrapper::init_and_swap(), clang-tidy wants us
to mark the destination argument as pointer to const, which doesn't work
because we use placement new to construct a move'd *this into.
2021-11-14 22:52:35 +01:00
Andrew Kaster
7014d37dd6 AK+Kernel: Suppress clang-tidy warnings from the cert-* category
cert-dcl50-cpp: No variadic functions, suppressed in RefCounted and
ThreadSafeRefCounted for implementing the magic one_ref_left and
will_be_destroyed functions.

cert-dcl58-cpp: No opening ::std, suppressed in the places we put names
in ::std to aid tools (move, forward, nullptr_t, align_val_t, etc).
2021-11-14 22:52:35 +01:00
Andrew Kaster
2b16ee742e AK: Avoid implicit conversion clang-tidy warnings in AK::Time 2021-11-14 22:52:35 +01:00
Andrew Kaster
2c4f7fae1e AK: Move StandardFormatter argument into base class initializer
Subclasses of StandardFormatter don't need to use the formatter argument
in their constructor, so move() it into the base class initializer.
2021-11-14 22:52:35 +01:00
Andrew Kaster
74e8aa73e5 AK: Avoid implicit conversions in TypeErasedParameter::to_size()
Refactor to a visitor+functor pattern that does an explicit static_cast
to size_t after performing suitable range checks for each type.
2021-11-14 22:52:35 +01:00
Andrew Kaster
762b92c650 AK: Resolve clang-tidy readability-qualified-auto warnings
... In files included by Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-14 22:52:35 +01:00
Andrew Kaster
64edf17eb2 AK: Mark StringView::find_any_of() as const 2021-11-14 22:52:35 +01:00
Andrew Kaster
163367da39 AK: Resolve clang-tidy warnings about unusual assignment operators
Either not returning *this, or in the case of Variant, not checking for
self assignment. In AK::Atomic, we can't return *this due to the wrapper
semantics Atomic implements.
2021-11-14 22:52:35 +01:00
Andrew Kaster
22feb9d47b AK: Resolve clang-tidy readability-bool-conversion warnings
... In files included by Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-14 22:52:35 +01:00