Age | Commit message (Collapse) | Author |
|
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.
|
|
This gives us better error messages when dereferencing null RefPtrs.
|
|
Many of the RefPtr assignment operators would cause ref leaks when we
call them to assign a pointer that's already the one kept.
|
|
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.
|
|
We would leak a ref when assigning a T& to a NonnullRefPtr that already
contains that same T.
|
|
This will make it immediately obvious what the problem is when you're
dereferencing a null OwnPtr.
|
|
Ideally we should also verify that the assertion actually happens,
but we need some support in the TestSuite framework for that.
|
|
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.
|
|
Also remove an unused variable.
|
|
|
|
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!)
|
|
|
|
OwnPtr's must move around, they can't be copy constructed.
|
|
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. :^)
|
|
We were falling back to an incorrect compiler-generated copy ctor for
this class, and let's not do that.
Found by PVS-Studio.
|
|
|
|
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.
|
|
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.
|
|
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.
|
|
These will, when building with clang, prevent using Optional::value
without first checking Optional::has_value() - at compile time.
|
|
When we save-as in the text editor we now auto-populate GFilePicker /w
the current name & extension.
|
|
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.
|
|
|
|
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.
|
|
|
|
|
|
This can be used if you change your mind about what value we should roll
back to. :^)
|
|
Qt had a pretty good name for this concept, so let's steal it. :^)
|
|
This is pretty ugly but I don't want to *not* use open_with_path_length()
so let's just shim it.
|
|
|
|
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.
|
|
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. :^)
|
|
These can just inherit from a shared base template. Thanks to Robin for the
sweet idea :^)
|
|
|
|
This allows HashMap::get() to be used for value types that cannot be default
constructed (e.g NonnullOwnPtr.)
|
|
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.
|
|
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 (->) :^)
|
|
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.
|
|
|
|
This is like value() but with a fallback in case there's no value set.
|
|
I was using this for a makeshift queue, but now there is AK::Queue.
|
|
This is very handy for the DebugLogStream implementation, among others. :^)
|
|
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.
|
|
Caught by valgrind's uninitialized access checks on the Vector unit test.
Yay for finding bugs with valgrind on the unit tests! :^)
|
|
Same as the RefPtr issue I just fixed. This makes it possible to assign a
NonnullRefPtr<Derived>&& to a NonnullRefPtr<Base>.
|
|
Makes checking for leaks more straightforward
|
|
To be more consistent with the rest of the codebase
|
|
Otherwise it's not possible to assign a RefPtr<Derived>&& to a RefPtr<Base>.
|
|
It's good to verify that complex objects can be moved nicely by Vector.
|
|
|