Commit graph

345 commits

Author SHA1 Message Date
Andreas Kling 4c285f9e1a AK: Add Vector(std::initializer_list<T>) constructor.
This allows us to construct a Vector from an initializer list like so:

Vector<Object> objects = { object1, object2, object3 };
2019-06-28 20:21:23 +02:00
Andreas Kling 2282e89d3f AK: Use a SinglyLinkedList<T> as HashTable's bucket chain storage.
We were using a DoublyLinkedList<T> simply because it supported remove().
This patch consolidates the SinglyLinkedList iterators and adds remove().
2019-06-27 16:36:31 +02:00
Andreas Kling 7f613c79cd AK: Oops, fix typo in RemoveVolatile<T> helper. 2019-06-27 16:01:24 +02:00
Andreas Kling 516d736afe AK: Consolidate iterators for HashTable and DoublyLinkedList respectively.
Get rid of the ConstIterator classes for these containers and use templated
FooIterator<T, ...> and FooIterator<const T, ...> helpers.

This makes the HashTable class a lot easier to read.
2019-06-27 15:57:49 +02:00
Andreas Kling 50700c107f AK: Get rid of ConstVectorIterator.
We can achieve the same with just a VectorIterator<const Vector, const T>.
2019-06-27 14:52:12 +02:00
Andreas Kling ebe108efa6 AK: Simplify HashMap a bit. 2019-06-27 14:27:26 +02:00
Andreas Kling 3bd47a2e09 AK: NonnullRefPtrVector should use Vector<T, inline_capacity> as its base.
We were forgetting to plumb through the inline capacity in the Base typedef.
2019-06-27 13:39:09 +02:00
Andreas Kling 9ab3718266 AK: Allow constructing an empty NonnullRefPtrVector. 2019-06-27 13:23:10 +02:00
Andreas Kling 48108ec474 AK: Support range-for iteration over a NonnullRefPtrVector<T>.
This means you can now do this:

void harmonize(NonnullRefPtrVector<Voice>& voices)
{
    for (auto& voice : voices) {
        voice.sing(); // Look, no "->"!
    }
}

Pretty dang cool :^)
2019-06-27 12:11:58 +02:00
Andreas Kling 25a1bf0c90 AK: Add NonnullRefPtrVector<T>.
This is a slot-in convenience replacement for Vector<NonnullRefPtr<T>> that
makes accessors return T& instead of NonnullRefPtr<T>&.
Since NonnullRefPtr guarantees non-nullness, this allows you to access these
vector elements using dot (.) rather than arrow (->). :^)
2019-06-27 12:04:27 +02:00
Andreas Kling f83263a72b Kernel: Use a raw VM region for sorting ELF symbols instead of a Vector.
This avoids putting pressure on kmalloc() during backtrace symbolication.
Since we dump backtrace for every process that exits, this is actually a
decent performance improvement for things like GCC that chain a lot of
processes together.
2019-06-27 10:49:49 +02:00
Andreas Kling eb129bd730 AK: Use __builtin_bswap() in NetworkOrdered. 2019-06-26 20:01:48 +02:00
Andreas Kling a2e5b821b4 AK: Simplify NetworkOrdered somewhat. 2019-06-26 16:26:59 +02:00
Andreas Kling e9b619c4aa JsonParser: Support basic escaped string characters.
I didn't implement \uXXXX-style escape in this patch. That's a FIXME.
2019-06-25 16:58:30 +02:00
Andreas Kling 583606a2b1 StringImpl: Fix possible uninitialized access in StringImpl::create().
If the provided length is 0, there's no need to dereference the const char*.
2019-06-24 14:38:44 +02:00
Andreas Kling 643a43f278 AK: Add JsonValue::to_string(default_value = {}). 2019-06-24 14:25:45 +02:00
Andreas Kling 266fed8c00 AK: Let's put the JSON parsing in a separate class. 2019-06-24 13:39:45 +02:00
Andreas Kling 8392c549a3 JsonValue: Add as_array() and as_object(). 2019-06-24 12:03:31 +02:00
Andreas Kling dd36f797d5 JsonObject: Let the compiler generate a copy constructor.
This was only needed while HashMap was noncopyable. :^)
2019-06-24 12:03:11 +02:00
Andreas Kling 15003245cd JsonArray: Add for_each() helper. 2019-06-24 12:02:31 +02:00
Andreas Kling 2c1c4ab116 AK: Make it possible to move and copy HashMap and HashTable.
Previously it was only possible to move them, but we should allow copying
as well, since it's gonna be useful for many things.
2019-06-24 11:57:54 +02:00
Andreas Kling 009b9bfd10 AK: Implement a naive JSON parser.
This parser assumes that the JSON is well-formed and will choke horribly
on invalid input.

Since we're primarily interested in parsing our own output right now, this
is less of a problem. Longer-term we're gonna need something better. :^)
2019-06-24 11:28:24 +02:00
Andreas Kling bad8ab697b NonnullRefPtr: Simplify copy constructors. 2019-06-24 10:23:59 +02:00
Andreas Kling 2dd54f062a AK: Mark some helper things constexpr. 2019-06-24 10:13:28 +02:00
Andreas Kling bf97b9589d NonnullRefPtr: Some improvements.
- Delete the default constructor instead of just making it private.
  It's never valid to create an empty NonnullRefPtr.

- Add copy assignment operators. I originally omitted these to force use
  of .copy_ref() at call sites, but the hassle/gain ratio is minuscule.

- Allow calling all the assignment operators in all consumable states.
  This codifies that it's okay to overwrite a moved-from NonnullRefPtr.
2019-06-24 09:58:21 +02:00
Andreas Kling 7e1cb86da7 LibHTML: Make it possible to build LibHTML on the host.
- "make" builds the normal Serenity libhtml.a
- "make -f Makefile.host" builds a test program for the host machine.
2019-06-22 21:21:57 +02:00
Andreas Kling 3ed17b0792 printf: Support %zu (the 'z' is really just ignored.) 2019-06-22 16:30:32 +02:00
Andreas Kling 1277d583ef printf: Oops, '-' is the left padding modifier, not ' '.
It's kinda funny how I can make a mistake like this in Serenity and then
get so used to it by spending lots of time using this API that I start to
believe that this is how printf() always worked..
2019-06-22 15:53:52 +02:00
Andreas Kling d343fb2429 AK: Rename Retainable.h => RefCounted.h. 2019-06-21 18:58:45 +02:00
Andreas Kling 550b0b062b AK: Rename RetainPtr.h => RefPtr.h, Retained.h => NonnullRefPtr.h. 2019-06-21 18:45:59 +02:00
Andreas Kling c26e3ce86b Change "retain" to "ref" in various comments. 2019-06-21 18:40:24 +02:00
Andreas Kling 90b1354688 AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr. 2019-06-21 18:37:47 +02:00
Andreas Kling 77b9fa89dd AK: Rename Retainable => RefCounted.
(And various related renames that go along with it.)
2019-06-21 15:30:03 +02:00
Andreas Kling a7dc1a7d6b AK: Make StringImpl a bit smaller.
There's no need for a member char* m_characters if we always store them
in the inline buffer. So with this patch, we now do.
After that, rearrange the members a bit for ideal packing. :^)
2019-06-20 13:23:48 +02:00
Andreas Kling 8c0ae711d8 Kernel+LibC: Make page fault crashes a bit more readable.
We'll now try to detect crashes that were due to dereferencing nullptr,
uninitialized malloc() memory, or recently free()'d memory.
It's not perfect but I think it's pretty good. :^)

Also added some color to the most important parts of the crash log,
and added some more modes to /bin/crash for exercising this code.

Fixes #243.
2019-06-19 20:52:12 +02:00
Andreas Kling c5d623e048 AK: Add some convenient functions to JsonValue. 2019-06-19 13:08:07 +02:00
Andreas Kling 9149a519f5 printf: Support printing negative values with %f or %g. 2019-06-18 14:47:52 +02:00
Andreas Kling 203f8e5320 AK: Add IPv4Address(NetworkOrdered<dword>) constructor. 2019-06-18 11:40:39 +02:00
Andreas Kling d9a48b5916 AK: Move IPv4Address from Kernel/Net/ to AK/ since it's quite useful. 2019-06-18 11:28:48 +02:00
Andreas Kling 9f7c11710f printf: Treat %g as %f for now. 2019-06-18 09:46:39 +02:00
Andreas Kling aa3df518e7 AK: Rename JsonObject::to_string() and pals to serialized().
And the variant that serializes into a StringBuilder is called serialize().
2019-06-18 09:37:47 +02:00
Andreas Kling 15fa4f1c55 AK: ScopeGuard.h needs StdLibExtras.h 2019-06-18 09:31:14 +02:00
Andreas Kling 4ee39d6292 AK: Override StringImpl's operator delete to silence valgrind. 2019-06-18 09:26:36 +02:00
Andreas Kling 92cda74724 AK: Fix leak in JsonValue::operator=(JsonValue&&).
Amusingly I introduced this leak while explaining that this type of leak is
a common bug, and saying I'm used to looking for it. :^)
2019-06-18 09:22:19 +02:00
Andreas Kling 4147394dcb AK: Add JsonValue(const char*).
This should obviously become a string, but if we don't have it, constructing
from a string literal ends up creating a boolean value.
2019-06-18 09:11:31 +02:00
Andreas Kling 1a761ea4fd AK: Add JsonValue(unsigned) ctor and as_string(). 2019-06-18 08:55:58 +02:00
Andreas Kling 114768562a AK: Including <AK/kstdio.h> should pull in <stdio.h> etc on host builds. 2019-06-18 08:53:26 +02:00
Andreas Kling 28a4963242 AK: Make ASSERT_NOT_REACHED() work nicely in host builds. 2019-06-18 08:52:21 +02:00
Andreas Kling ee347effac AK: Use a single StringBuilder throughout JSON serialization. 2019-06-17 21:36:54 +02:00
Andreas Kling 04a8fc9bd7 AK: Add some classes for JSON encoding.
This patch adds JsonValue, JsonObject and JsonArray. You can use them to
build up a JsonObject and then serialize it to a string via to_string().

This patch only implements encoding, no decoding yet.
2019-06-17 19:47:35 +02:00