summaryrefslogtreecommitdiff
path: root/AK
AgeCommit message (Collapse)Author
2019-08-02AK: Simplify RefPtr and NonnullRefPtr's leak_ref() functionsAndreas Kling
Use AK::exchange() to switch out the internal storage. Also mark these functions with [[nodiscard]] to provoke an compile-time error if they are called without using the return value.
2019-08-02AK: Add anti-null assertions in RefPtr.Andreas Kling
This gives us better error messages when dereferencing null RefPtrs.
2019-08-02AK: Fix ref leaks in RefPtr assignment operators.Andreas Kling
Many of the RefPtr assignment operators would cause ref leaks when we call them to assign a pointer that's already the one kept.
2019-08-02AK: Explicitly delete NonnullRefPtr::operator=(RefPtr).Andreas Kling
This gives us much better error messages when you try to use them. Without this change, it would complain about the absence of functions named ref() and deref() on RefPtr itself. With it, we instead get a "hey, this function is deleted" error. Change operator=(T&) to operator=T(const T&) also, to keep assigning a const T& to a NonnullRefPtr working.
2019-08-02AK: Fix ref leak in NonnullRefPtr::operator=(T&).Andreas Kling
We would leak a ref when assigning a T& to a NonnullRefPtr that already contains that same T.
2019-08-02AK: Add assertions when dereferencing an OwnPtr.Andreas Kling
This will make it immediately obvious what the problem is when you're dereferencing a null OwnPtr.
2019-08-02AK: Add a test for iterating a HashTable during clear (should assert)Andreas Kling
Ideally we should also verify that the assertion actually happens, but we need some support in the TestSuite framework for that.
2019-08-02TestSuite: Hijack the ASSERT macros during unit tests.Andreas Kling
Instead of aborting the program when we hit an assertion, just print a message and keep going. This allows us to write tests that provoke assertions on purpose.
2019-08-02AK: Fix typo in the WeakPtr test. Behavior was actually correct.Andreas Kling
Also remove an unused variable.
2019-08-02AK: Fix typo in TestVector.cpp, oops.Andreas Kling
2019-08-01AK: Use Vector::empend() a bit in the unit tests, and fix a bug.Andreas Kling
There was a bug in the "prepend_vector_object" test but it was masked by us not printing failures. (The bug was that we were adding three elements to the "objects" vector and then checking that another vector called "more_objects" indeed had three elements. Oops!)
2019-08-01TestSuite: Actually print failed comparions.. :^)Andreas Kling
2019-08-01AK: Don't allow constructing an OwnPtr from a const NonnullOwnPtr&Andreas Kling
OwnPtr's must move around, they can't be copy constructed.
2019-08-01AK: Add Vector::empend().Andreas Kling
This is a complement to append() that works by constructing the new element in-place via placement new and forwarded constructor arguments. The STL calls this emplace_back() which looks ugly, so I'm inventing a nice word for it instead. :^)
2019-08-01AK: Make Bitmap movable but not copyable.Andreas Kling
We were falling back to an incorrect compiler-generated copy ctor for this class, and let's not do that. Found by PVS-Studio.
2019-08-01JsonParser: Merge the parsing of '\n' and '\r' in quoted stringsAndreas Kling
2019-07-31HashTable: Assert on iteration attempt over table during clear/rehashAndreas Kling
It doesn't seem sane to try to iterate over a HashTable while it's in the middle of being cleared. Since this might cause strange problems, this patch adds an assertion if an iterator is constructed during clear() or rehash() of a HashTable.
2019-07-31Add Result<>, to use with/complement ErrorRobin Burchell
An operation often has two pieces of underlying information: * the data returned as a result from that operation * an error that occurred while retrieving that data Merely returning the data is not good enough. Result<> allows exposing both the data, and the underlying error, and forces (via clang's consumable attribute) you to check for the error before you try to access the data.
2019-07-31Add Error<>Robin Burchell
Put simply, Error<> is a way of forcing error handling onto an API user. Given a function like: bool might_work(); The following code might have been written previously: might_work(); // but what if it didn't? The easy way to work around this is of course to [[nodiscard]] might_work. But this doesn't work for more complex cases like, for instance, a hypothetical read() function which might return one of _many_ errors (typically signalled with an int, let's say). int might_read(); In such a case, the result is often _read_, but not properly handled. Like: return buffer.substr(0, might_read()); // but what if might_read returned an error? This is where Error<> comes in: typedef Error<int, 0> ReadError; ReadError might_read(); auto res = might_read(); if (might_read.failed()) { switch (res.value()) { case EBADF: ... } } Error<> uses clang's consumable attributes to force failed() to be checked on an Error instance. If it's not checked, then you get smacked.
2019-07-31Optional: Add consumable checksRobin Burchell
These will, when building with clang, prevent using Optional::value without first checking Optional::has_value() - at compile time.
2019-07-29TextEditor: Include extension during SaveAsrhin123
When we save-as in the text editor we now auto-populate GFilePicker /w the current name & extension.
2019-07-29Kernel+AK: Remove AK/StdLibExtras.cpp, moving kernel stuff to Kernel/.Andreas Kling
We had some kernel-specific gizmos in AK that should really just be in the Kernel subdirectory instead. The only thing remaining after moving those was mmx_memcpy() which I moved to the ARCH(i386)-specific section of LibC/string.cpp.
2019-07-28AK: Add Queue::clear() to clear out a Queue.Andreas Kling
2019-07-27ByteBuffer: Add slice_view(). Works like slice() but makes a wrapper only.Andreas Kling
So we already have ByteBuffer::wrap() which is like a StringView for random data. This might not be the best abstraction actually, but this will be immediately useful so let's add it.
2019-07-26AK: Add RELEASE_ASSERT in non-Serenity builds.Andreas Kling
2019-07-26AK: Fix NonnullRefPtr<T>::operator=(NonnullRefPtr<U>).Andreas Kling
2019-07-25AK: Add ScopedValueRollback::set_override_rollback_value().Andreas Kling
This can be used if you change your mind about what value we should roll back to. :^)
2019-07-25AK: Rename ValueRestorer => ScopedValueRollback.Andreas Kling
Qt had a pretty good name for this concept, so let's steal it. :^)
2019-07-25AK: Shim open_with_path_length() for non-Serenity builds.Andreas Kling
This is pretty ugly but I don't want to *not* use open_with_path_length() so let's just shim it.
2019-07-25AK: Don't compile mmx_memcpy() outside of ARCH(I386).Andreas Kling
2019-07-25AK: Allow NonnullRefPtr::ptr() when in "unknown" typestate.Andreas Kling
Clang loses the typestate when passing NonnullRefPtr's via lambda captures. This is unfortunate, but not much we can do about it. Allowing ptr() makes it possible to use captured NonnullRefPtrs as you'd expect.
2019-07-25AK: Simplify NonnullPtrVector template a bit.Andreas Kling
Add an "ElementType" typedef to NonnullOwnPtr and NonnullRefPtr to allow clients to easily find the pointee type. Then use this to remove a template argument from NonnullPtrVector. :^)
2019-07-25AK: Share code between NonnullOwnPtrVector and NonnullRefPtrVector.Andreas Kling
These can just inherit from a shared base template. Thanks to Robin for the sweet idea :^)
2019-07-25LogStream: Preserve errno for the lifetime of a LogStream object.Andreas Kling
2019-07-24AK: Make HashMap::get(Key) return an Optional<Value>.Andreas Kling
This allows HashMap::get() to be used for value types that cannot be default constructed (e.g NonnullOwnPtr.)
2019-07-24AK: Delete Vector::resize() from Nonnull{Own,Ref}PtrVector.Andreas Kling
It's not possible to grow one of these vectors beyond what's already in them since it's not possible to default-construct Nonnull{Own,Ref}Ptr. Add Vector::shrink() which can be used when you want to shrink the Vector and delete resize() from the specialized Vectors.
2019-07-24AK: Add NonnullOwnPtrVector.Andreas Kling
This works just like NonnullRefPtr, except for NonnullOwnPtr's instead. NonnullOwnPtrVector<T> inherits from Vector<NonnullOwnPtr<T>>, and adds some comforts on top, like making accessors return T& so we can chase dots (.) instead of arrows (->) :^)
2019-07-24AK: Add NonnullOwnPtr.Andreas Kling
This is just like OwnPtr (also single-owner), except it cannot be null. NonnullOwnPtr is perfect as the return type of functions that never need to return nullptr. It's also useful as an argument type to encode the fact that the argument must not be nullptr. The make<Foo>() helper is changed to return NonnullOwnPtr<Foo>. Note: You can move() out of a NonnullOwnPtr, and after that the object is in an invalid state. Internally it will be a nullptr at this point, so we'll still catch misuse, but the only thing that should be done in this state is running the destructor. I've used consumable annotations to generate some warnings when using a NonnullOwnPtr after moving from it, but these only work when compiling with clang, so be aware of that.
2019-07-24AK: Move clang-specific consumable annotation helpers to Platform.hAndreas Kling
2019-07-24AK: Add Optional::value_or(T).Andreas Kling
This is like value() but with a fallback in case there's no value set.
2019-07-21AK: Remove unused Vector::shift_left().Andreas Kling
I was using this for a makeshift queue, but now there is AK::Queue.
2019-07-21Kernel+LibC: Add a dbgputstr() syscall for sending strings to debug output.Andreas Kling
This is very handy for the DebugLogStream implementation, among others. :^)
2019-07-21AK: Run host tests on makeRobin Burchell
Restructure the makefile a little so it only builds objects once, and then run them on make clean. This is a little slower (since we're relinking tests each makeall), but it also ensures that it will work.
2019-07-21AK: Fix off-by-one in Vector::prepend(Vector&&).Andreas Kling
Caught by valgrind's uninitialized access checks on the Vector unit test. Yay for finding bugs with valgrind on the unit tests! :^)
2019-07-21AK: Make NonnullRefPtr::operator=(NonnullRefPtr<U>&&) cast incoming pointer.Andreas Kling
Same as the RefPtr issue I just fixed. This makes it possible to assign a NonnullRefPtr<Derived>&& to a NonnullRefPtr<Base>.
2019-07-21TestSuite: Don't leak the suite instanceRobin Burchell
Makes checking for leaks more straightforward
2019-07-21TestSuite: instance() -> the(), and return a referenceRobin Burchell
To be more consistent with the rest of the codebase
2019-07-21AK: RefPtr::operator=(RefPtr<U>&&) needs to cast the incoming pointer.Andreas Kling
Otherwise it's not possible to assign a RefPtr<Derived>&& to a RefPtr<Base>.
2019-07-21AK: Add a unit test for Vector::prepend(Vector&&) with complex T.Andreas Kling
It's good to verify that complex objects can be moved nicely by Vector.
2019-07-21AK: Add some basic unit tests for WeakPtr.Andreas Kling