summaryrefslogtreecommitdiff
path: root/AK
AgeCommit message (Collapse)Author
2021-01-16Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect. This commit touches some dbg() calls which are enclosed in macros. This should be fine because with the new constexpr stuff, we ensure that the stuff actually compiles.
2021-01-16AK: Add enabled template parameter to dbgln.asynts
2021-01-15AK: Add String::join() helper functionLinus Groh
This is a simple wrapper around StringBuilder::join().
2021-01-15AK: Add JsonArray(const Vector<T>) constructorLinus Groh
This simplifies creating a JsonArray from a Vector<T> (when there's a JsonValue(T) constructor overload for T, that is).
2021-01-15Badge: Access to underlying typeLenny Maiorani
Problem: - Access to the underlying type is not provided. This limits metaprogramming and usage in function templates. Solution: - Provide public access to the underlying type. - Add test to ensure the underlying type is accessible.
2021-01-15StringView: Implement `find_first_of` in terms of `AK::find`Lenny Maiorani
Problem: - The implementation of `find_first_of` is coupled to the implementation of `StringView`. Solution: - Decouple the implementation of `find_first_of` from the class by using a generic `find` algorithm.
2021-01-15AK: Implement generic any_of algorithmLenny Maiorani
Problem: - Raw loops are often written to validate that any values in a container meet a predicate, but raw loops are not as expressive as functions implementing well-named algorithms and are error-prone. Solution: - Implement a very generic form of `any_of`.
2021-01-12AK: Use StringView::find() in StringView::split_view()AnotherTest
This fixes #4926.
2021-01-12AK: Add String{View,}::find(StringView)AnotherTest
I personally mistook `find_first_of(StringView)` to be analogous to this so let's add a `find()` method that actually searches the string.
2021-01-12LibC+Everywhere: Remove open_with_path_length() in favor of open()Andreas Kling
This API was a mostly gratuitous deviation from POSIX that gave up some portability in exchange for avoiding the occasional strlen(). I don't think that was actually achieving anything valuable, so let's just chill out and have the same open() API as everyone else. :^)
2021-01-12AK: Simplify constructors and conversions from nullptr_tLenny Maiorani
Problem: - Many constructors are defined as `{}` rather than using the ` = default` compiler-provided constructor. - Some types provide an implicit conversion operator from `nullptr_t` instead of requiring the caller to default construct. This violates the C++ Core Guidelines suggestion to declare single-argument constructors explicit (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit). Solution: - Change default constructors to use the compiler-provided default constructor. - Remove implicit conversion operators from `nullptr_t` and change usage to enforce type consistency without conversion.
2021-01-11AK: Specialise convert_to_uint<T> and to_uint<T> for 'long' variantsAnotherTest
2021-01-11AK: Enable format string warnings for AK printf wrappersSahan Fernando
2021-01-11SinglyLinkedList: Implement `find` in terms of `AK::find`Lenny Maiorani
Problem: - The implementation of `find` is coupled to the implementation of `SinglyLinkedList`. Solution: - Decouple the implementation of `find` from the class by using a generic `find` algorithm.
2021-01-11DoublyLinkedList: Implement `find` in terms of `AK::find`Lenny Maiorani
Problem: - The implementation of `find` is coupled to the implementation of `DoublyLinkedList`. - `append` and `prepend` are implemented multiple times so that r-value references can be moved from into the new node. This is probably not called very often because a pr-value or x-value needs to be used here. Solution: - Decouple the implementation of `find` from the class by using a generic `find` algorithm. - Make `append` and `prepend` be function templates so that they can have binding references which can be forwarded.
2021-01-11Vector: Implement `find`, `find_if`, `find_first_matching` in terms of ↵Lenny Maiorani
`AK::find*` Problem: - The implementation of `find` is coupled to the implementation of `Vector`. - `Vector::find` takes the predicate by value which might be expensive. Solution: - Decouple the implementation of `find` from `Vector` by using a generic `find` algorithm. - Change the name of `find` with a predicate to `find_if` so that a binding reference can be used and the predicate can be forwarded to avoid copies. - Change all the `find(pred)` call sites to use `find_if`.
2021-01-11AK: Find a value in any container offering iteratorsLenny Maiorani
Problem: - `find` is implemented inside of each container. This coupling requires that each container needs to individually provide `find`. Solution: - Decouple the `find` functionality from the container. This allows provides a `find` algorithm which can work with all containers. Containers can still provide their own `find` in the case where it can be optimized. - This also allows for searching sub-ranges of a container rather than the entire container as some of the container-specific member functions enforced. Note: - @davidstone's talk from 2015 C++Now conference entitled "Functions Want to be Free" encourages this style: (https://www.youtube.com/watch?v=_lVlC0xzXDc), but it does come at the cost of composability. - A logical follow-on to this is to provide a mechanism to use a short-hand function which automatically searches the entire container. This could automatically use the container-provided version if available so that functions which provide their own optimized version get the benefit.
2021-01-11Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.Everything:
2021-01-10TestTypeTraits: Fix incorrectly namespaced nullptr_tLenny Maiorani
Problem: - Clang ToT fails to build `AK/Tests/TestTypeTraits.cpp` because `nullptr_t` is missing the `std` namespace qualifier. Solution: - Prepend the namespace qualifier.
2021-01-10AK: Make MappedFile heap-allocated and ref-countedAndreas Kling
Let's adapt this class a bit better to how it's actually being used. Instead of having valid/invalid states and storing an error in case it's invalid, a MappedFile is now always valid, and the factory function that creates it will return an OSError if mapping fails.
2021-01-10AK: Add AK::OSError, a wrapper for errno codesAndreas Kling
This is a strongly typed carrier for "errno" error codes, intended for use in return types, e.g Result<String, OSError>.
2021-01-09AK: Add static Singleton::get function to allow destructible globalsTom
This enable using global raw pointers rather than Singleton objects, which solves some problems because global Singleton object could be deleted when destructors are run.
2021-01-09AK: Add Formatter<FormatString> as helper class.asynts
2021-01-09AK: Add release_value() and release_error() to AK::ResultAndreas Kling
These are nice when you want to move something out of the result, and match the API we already have for Optional.
2021-01-04AK: Add default memory order as template argument for Atomic<T>Tom
This is useful for collecting statistics, e.g. Atomic<unsigned, MemoryOrder::memory_order_relaxed> would allow using operators such as ++ to use relaxed semantics throughout without having to explicitly call fetch_add with the memory order.
2021-01-04AK: Decorate RefCountedBase::try_ref with nodiscardTom
Because try_ref only increments the ref count if it returned true, it is important that any caller properly acts upon the return value.
2021-01-03AK: Add String{,View}::is_whitespace()AnotherTest
+Tests!
2021-01-02AK: Use size_t in methods of Utf8View.asynts
2021-01-02AK: Remove redundant compare() functions.asynts
2021-01-02Piggyback: AK: Add formatter for std::nullptr_t.asynts
2021-01-01AK: Add Result<void, ErrorType> specialization, cleanupAndrew Kaster
Add a specialization for a void ValueType. This is useful if a generic function wants to return a Result<T, E> where the user might not actually care abut the T, and default it to void. In this case it basically becomes Unexpected<E> instead of Result, but hey, it works :)
2021-01-01AK: Add the UUID containerLiav A
This container represents a universally unique identifier. This will be used later in the kernel for GUID partitions.
2021-01-01AK: Deal with unsigned integers in binary search.asynts
2021-01-01AK+LibGUI+LibWeb: Remove AK::TypeTraits in favor of RTTI-based helpersAndreas Kling
Now that we have RTTI in userspace, we can do away with all this manual hackery and use dynamic_cast. We keep the is<T> and downcast<T> helpers since they still provide good readability improvements. Note that unlike dynamic_cast<T>, downcast<T> does not fail in a recoverable way, but will assert if the object being casted is not a T.
2020-12-31Everywhere: Re-format with clang-format-11Linus Groh
Compared to version 10 this fixes a bunch of formatting issues, mostly around structs/classes with attributes like [[gnu::packed]], and incorrect insertion of spaces in parameter types ("T &"/"T &&"). I also removed a bunch of // clang-format off/on and FIXME comments that are no longer relevant - on the other hand it tried to destroy a couple of neatly formatted comments, so I had to add some as well.
2020-12-31AK: Add missing 'template' keywords in TypeListLinus Groh
This caused the AK build to be broken on OpenBSD (and possibly other platforms / compiler versions). Fixes #4692.
2020-12-31AK: Add operator* and operator-> overloads in Optional.asynts
2020-12-31AK: Fix some WeakPtr copy constructor variants not copying the linkTom
2020-12-31AK: Fix a race condition with WeakPtr<T>::strong_ref and destructionTom
Since RefPtr<T> decrements the ref counter to 0 and after that starts destructing the object, there is a window where the ref count is 0 and the weak references have not been revoked. Also change WeakLink to be able to obtain a strong reference concurrently and block revoking instead, which should happen a lot less often. Fixes a problem observed in #4621
2020-12-30AK+ProtocolServer: Properly close download stream fd'sAnotherTest
This makes the issue of running out of openable pipes in the ProtocolServer process much less likely (but still possible).
2020-12-30AK+Format: Remove TypeErasedFormatParams& from format function.asynts
2020-12-30AK: Add {Input,Output}FileStreamAnotherTest
Unlike the ones in LibCore, these only wrap an stdio FILE* (or an fd, which they close when destroyed).
2020-12-30AK: Add a ByteBuffer::copy(ReadonlyBytes) overloadAnotherTest
2020-12-30AK: Replace some SFINAE with requires clauses, clean up existing onesAndrew Kaster
Add requires clauses to constraints on InputStream and OutputStream operator<< / operator>>. Make the constraint on String::number a requires clause instead of SFINAE. Also, fix some unecessary IsSame in Trie where specialized traits exist for the given use cases.
2020-12-30AK: Move String::number entirely to header fileAndrew Kaster
Use SFINAE to enforce the fact that it's supposed to only be called for Arithmetic types, rather than counting on the linker to tell us that an instantiation of String::number(my_arg) was not found. This also adds String::number for floating point types as a side-effect.
2020-12-30AK: Add tests for type traits and IndexSequenceAndrew Kaster
Use TypeLists to add test for IsIntegral, IsFloatingPoint, IsVoid, IsNullPointer, IsArithmetic, IsFundamental, and AddConst type traits. More can "easily" be added once the TypeList and macro magic is squinted at for long enough :).
2020-12-30AK: Add a TypeList class for expanded compile-time toolsAndrew Kaster
Also add IndexSequence and associated helpers. The TypeList class can be queried for what type is at a certain index, and there are two helper functions: for_each_type, and for_each_type_zipped. for_each_type will invoke a lambda with a TypeWrapper object for each type in the type list. The original type can be obtained by extracting the ::Type from the type of your generic lambda's one argument. for_each_type_zipped will walk two TypeLists in lockstep and pass a TypeWrapper object for the current index in each list to a generic lambda. The original type from the TypeList can again be extracted via the ::Type of the generic lambda's two parameters.
2020-12-30AK: Add IsArithmetic and IsFundamental type traitsAndrew Kaster
Also, make sure to using AK::IsNullPointer
2020-12-30AK: Correct name in TestMain for TestTrieAndrew Kaster
Copy paste error :)
2020-12-30AK: Use MacOS pthread_get_stacksize_np to get stack size for StackInfoAndrew Kaster
Seems Rust and OpenJDK both had issues with getting accurate stack size for the main thread with MacOS Maverick and above. Apply a variant of their workarounds. We could probably assume 8MB in all cases just to be safe, as the only user of AK::StackInfo right now is lib JS's heap for determining possible pointer candidates. But, this approach should work if userspace apps start trying to add custom guard pages, as well.