Commit graph

337 commits

Author SHA1 Message Date
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
Andreas Kling 01d1aee922 AK: Make RetainPtr and Retained more friendly towards const pointers.
Also add operator T&'s to Retained since it's nice to be able to pass them
to a function that takes a T&.
2019-06-15 18:45:44 +02:00
Andreas Kling bfaa74f076 AK/Tests: Test Queue<String> with large number of elements. 2019-06-15 10:39:19 +02:00
Andreas Kling c699d9d79d AK: Add a simple Queue<T> class.
The underlying data structure is a singly-linked list of Vector<T>.
We never shift any of the vector contents around, but we batch the memory
allocations into 1000-element segments.
2019-06-15 10:35:35 +02:00
Andreas Kling 9443957c14 PaintBrush: Speed up the bucket tool with smarter use of Vector.
Put together a pretty well-performing queue using a Vector and an offset.
By using the new Vector::shift_left(int) instead of Vector::take_first()
we can avoid shifting the vector contents every time and instead only
do it every so often.

Maybe this could be generalized into a separate class, I'm not sure if it's
the best algorithm though, it's just what I came up with right now. :^)
2019-06-14 21:50:28 +02:00
Andreas Kling a12751695e AK/Tests: Add a simple EXPECT_EQ macro and use it for the String test. 2019-06-14 17:52:51 +02:00
Andreas Kling 3557f277f6 AK/Tests: Add some macros for testing. 2019-06-14 17:38:17 +02:00
Andreas Kling 0589ef2886 AK/Tests: Add a couple more String tests. 2019-06-14 07:40:36 +02:00
Andreas Kling 255c7562ba AK: Massage it into building on my host system without breaking Serenity. 2019-06-14 06:43:56 +02:00