Commit Graph

880 Commits

Author SHA1 Message Date
Andreas Kling
ca2052ae4a AK: Add a simple NumericLimits<T> template
This provides min(), max() and is_signed() for the basic integer types.
2020-04-15 16:58:46 +02:00
Andreas Kling
b237ba57ea AK: Add a little test for String::split()
Just to verify that the parts are all null-terminated.
2020-04-14 15:36:25 +02:00
Itamar
e207de8449 LibELF: Add find_demangled_function
Also, added AK::String::index_of and fixed a bug in ELF::Loader::symbol_ptr
2020-04-13 23:20:59 +02:00
Andreas Kling
02e0fab19a AK: Let FlyString::hash() assume that the string was already hashed
Since the FlyString deduplication mechanism uses a HashTable, we know
that any StringImpl inside a non-null FlyString will already have its
lazily computed hash.
2020-04-13 12:27:05 +02:00
Andreas Kling
26a8984d03 AK: Inline Optional functions more aggressively
This turns into much less code in the most common cases, here's why:
The normal Optional usage pattern is something like:

    auto foo = get_me_an_optional();
    if (foo.has_value())
        do_stuff_with(foo.value());

In this typical scenario, we check has_value() before calling value().
Without inlining, value() will double-check has_value() itself and
assert if it fails. Inlining allows the compiler to optimize all of
this away.
2020-04-12 20:37:51 +02:00
Andreas Kling
3bbc2c7300 AK: Add LogStream operator<< overloads for float and double 2020-04-12 19:23:39 +02:00
Linus Groh
c8d0a2eb3c AK: Parse query and fragment in URL::parse() 2020-04-12 01:18:39 +02:00
Linus Groh
21a61b276b AK: Support fragment in URL 2020-04-12 01:18:39 +02:00
Andreas Kling
b1555381ee AK: Recompute URL validity after changing protocol/host/path
This allows you to build URLs by calling setters on an empty URL and
actually get a valid URL at the end.
2020-04-11 23:11:10 +02:00
Andreas Kling
c993c7e3dc AK: String::contains() should say no if needle or haystack is null 2020-04-11 14:33:05 +02:00
Andreas Kling
8cbb8491cb AK: Add FlyString::hash() 2020-04-10 16:26:59 +02:00
Paul Redmond
a9779e12ea
AK: Appending 0 bytes to a ByteBuffer should be a no-op (#1699)
- inserting an empty string into LibLine Editor triggered an assertion
  trying to grow a ByteBuffer by 0 bytes.
2020-04-08 17:04:37 +02:00
Andreas Kling
19be842b5b AK: Disable the consumable annotation checking to fix Clang build
Clang keeps whining that NonnullFooPtrs are in "unknown" state and I'm
not sure how to resolve that right now. Disable the checking until we
can figure it out.
2020-04-07 17:30:16 +02:00
Andreas Kling
f8942411ac AK: Add forward() overload that refuses to forward lvalue as rvalue
This matches what other forward() implementations do.
2020-04-07 15:56:19 +02:00
Emanuel Sprung
154dcd1ed6 AK: Allow %m.nf specifier for double/float in printf to set fraction with
This patch adds the missing part for the printf of double values to specify
the length of the fraction part. For GVariant, a default of %.2 is used.
2020-04-07 09:02:02 +02:00
Andreas Kling
20e58c5513 AK: Make dbgprintf() and dbgputstr() go to stderr on non-Serenity hosts 2020-04-06 10:49:27 +02:00
Andreas Kling
0d48fb9a87 AK: Add out() and warn() streams that forward to stdout and stderr
Our C++ code generator tools have been relying on host-side dbg() being
forwarded to stdout until now. Now they use out() instead.

Hopefully this will make it easier and more enticing to use streams in
userspace programs as well. :^)
2020-04-06 10:49:27 +02:00
nimelehin
c0a4cf5e8d Kernel: Support best fit allocation policy in kmalloc()
Add find_best_fit() which implements best fit allocation algorithm.
Kmalloc now uses a best fit allocation policy for large allocations.
2020-04-06 08:33:13 +02:00
nimelehin
fbcc798f3f Bitmap: Add Bitmap::find_next_range_of_unset_bits()
AK::Bitmap is extended with find_next_range_of_unset_bits().
The function is implemented using count_trailing_zeroes_32(), which is
optimized on many platforms, that gives a huge performance boost.
Functions find_longest_range_of_unset_bits() and find_first_fit() are
implemented with find_next_range_of_unset_bits(). According to
benchmarks, they are 60-100% faster.
2020-04-06 08:31:01 +02:00
nimelehin
471db7ce0a AK: Add count_trailing_zeroes_32()
Add count_trailing_zeroes_32() which is implemented with builtins
if available, otherwise there's a generic fallback.
2020-04-06 08:28:57 +02:00
nimelehin
8137ef6252 AK: Add Bitmap::find_first_fit()
Add find_first_fit() which implements first fit algorithm.
2020-04-06 08:27:39 +02:00
nimelehin
73901c9b2b AK: Add Bitmap::set_range()
Add set_range() which sets a range of bits to requested value.
Fix code style.
2020-04-06 08:27:17 +02:00
Andreas Kling
76bb0fab2d AK: Make FlyString a little less hilariously unoptimized :^) 2020-04-06 08:26:26 +02:00
Andreas Kling
4f200def9c AK: Stop allowing implicit downcast with OwnPtr and NonnullOwnPtr
Same issue here as we had with RefPtr and NonnullRefPtr.

Since we can't make copies of an owning pointer, we don't get quite the
same static_ptr_cast<T> here. Instead I've only added a new templated
version of OwnPtr::release_nonnull() in this patch, to solve the only
issue that popped up.

I'm not sure what the best solution here is, but this works for now.
2020-04-05 11:32:30 +02:00
Andreas Kling
1d468ed6d3 AK: Stop allowing implicit downcast with RefPtr and NonnullRefPtr
We were allowing this dangerous kind of thing:

RefPtr<Base> base;
RefPtr<Derived> derived = base;

This patch changes the {Nonnull,}RefPtr constructors so this is no
longer possible.

To downcast one of these pointers, there is now static_ptr_cast<T>:

RefPtr<Derived> derived = static_ptr_cast<Derived>(base);

Fixing this exposed a ton of cowboy-downcasts in various places,
which we're now forced to fix. :^)
2020-04-05 11:19:00 +02:00
AnotherTest
7d0bf9b5a9 Kernel+AK: Separate out MACAddress and move it into AK 2020-04-05 09:50:48 +02:00
Tibor Nagy
1bf93d504f AK: Break on end of input in JsonParser::consume_quoted_string
Fixes #1599
2020-04-04 10:31:01 +02:00
AnotherTest
df7062aac5 AK: Add an overwrite API to ByteBuffer
Since ByteBuffer is a Buffer, it should allow us to overwrite parts of
it that we have allocated.
This comes in useful in handling unsequenced writes like handling
fragmented ip packets :^)
2020-04-03 09:42:13 +02:00
Emanuel Sprung
d0d093fef5 AK: Remove relative path in AK testsuite
With relative filenames in the executable code, the executable is basically not
relocatable. This makes out-of-source builds unneccesery hard. This patchset moves
the relative link into the filesystem: that can be handled much easier :^)
2020-04-03 09:07:19 +02:00
Emanuel Sprung
b995a499d3 AK: Add equals method to JsonValue to semantically compare two values.
This patchsets adds the semantic check of two values. One first approach
was to compare the (generated) json strings of the two values. This works
out in the most cases, but not with numbers, where "1.0" and "1" in JSON
format are semantically the same. Therefore, this patch adds deep (recursive)
check of two JsonValues.
2020-04-01 22:12:19 +02:00
Emanuel Sprung
2577712a1c AK: Add String::replace() functionality
This adds a replace functionality that replaces a string that contains
occurences of a "needle" by a "replacement" value. With "all_occurences"
enabled, all occurences are being replaced, otherwise only the first
occurence is being replaced.
2020-04-01 21:47:23 +02:00
Andreas Kling
806d3d8e79 AK: Add adopt_own() to create a NonnullOwnPtr<T> from a T& 2020-04-01 21:05:35 +02:00
Emanuel Sprung
c54855682c AK: A few JSON improvements
* Add double number to object serializer

* Handle negative double numbers correctly

* Handle \r and \n in quoted strings independently
  This improves the situation when keys contain \r or \n that currently
  has the effect that "a\rkey" and "a\nkey" in an JSON object are the
  same key value.
2020-03-31 13:42:39 +02:00
Emanuel Sprung
c925aaceb2 AK: Print double numbers with printf
This patchset allows double numbers to be printed with the printf function.
The fraction will always be printed as 6 digit number. This can be improved :^)
2020-03-31 13:42:39 +02:00
Itamar
6b74d38aab Kernel: Add 'ptrace' syscall
This commit adds a basic implementation of
the ptrace syscall, which allows one process
(the tracer) to control another process (the tracee).

While a process is being traced, it is stopped whenever a signal is
received (other than SIGCONT).

The tracer can start tracing another thread with PT_ATTACH,
which causes the tracee to stop.

From there, the tracer can use PT_CONTINUE
to continue the execution of the tracee,
or use other request codes (which haven't been implemented yet)
to modify the state of the tracee.

Additional request codes are PT_SYSCALL, which causes the tracee to
continue exection but stop at the next entry or exit from a syscall,
and PT_GETREGS which fethces the last saved register set of the tracee
(can be used to inspect syscall arguments and return value).

A special request code is PT_TRACE_ME, which is issued by the tracee
and causes it to stop when it calls execve and wait for the
tracer to attach.
2020-03-28 18:27:18 +01:00
Andreas Kling
95cc4c7e74 AK: Add some string comparison operators
Some of these are very inefficient. It's nice to have some optimization
opportunities in the future though. :^)
2020-03-28 09:11:13 +01:00
Sergey Bugaev
5bb18bf548 AK: Use print_string() for %c formatting
Instead of simply outputting the character. This way, we get proper padding
support and other niceties strings enjoy.
2020-03-26 08:01:16 +01:00
Andreas Kling
e34fe556ca AK: Fix JsonParser kernel build (no floats/doubles in kernel code) 2020-03-24 22:37:24 +01:00
Emanuel Sprung
bca5762542 AK: Add parsing of JSON double values
This patch adds the parsing of double values to the JSON parser.
There is another char buffer that get's filled when a "." is present
in the number parsing. When number finished, a divider is calculated
to transform the number behind the "." to the actual fraction value.
2020-03-24 22:20:07 +01:00
Emanuel Sprung
45921328e4 AK: Add get_or() method to JsonObject
This allows to retrieve a default value for items thare are not
available in the json object.
2020-03-24 22:20:07 +01:00
Andreas Kling
404de10a15 AK: Add FlyString::is_null() 2020-03-24 16:14:10 +01:00
Andreas Kling
7d862dd5fc AK: Reduce header dependency graph of String.h
String.h no longer pulls in StringView.h. We do this by moving a bunch
of String functions out-of-line.
2020-03-23 13:48:44 +01:00
Andreas Kling
c4a6d6ae9f AK: Add FlyString::to_lowercase() and LogStream operator<<(FlyString) 2020-03-22 19:07:02 +01:00
Andreas Kling
26bc3d4ea0 AK: Add FlyString::equals_ignoring_case(StringView)
And share the code with String by moving the logic to StringUtils. :^)
2020-03-22 13:07:45 +01:00
Andreas Kling
0efa47b7ef AK: Run clang-format on StringUtils.{cpp,h} 2020-03-22 13:04:04 +01:00
Andreas Kling
4f72f6b886 AK: Add FlyString, a simple flyweight string class
FlyString is a flyweight string class that wraps a RefPtr<StringImpl>
known to be unique among the set of FlyStrings. The class is very
unoptimized at the moment.

When to use FlyString:

- When you want O(1) string comparison
- When you want to deduplicate a lot of identical strings

When not to use FlyString:

- For strings that don't need either of the above features
- For strings that are likely to be unique
2020-03-22 13:03:43 +01:00
Andreas Kling
4eef3e5a09 AK: Add StringBuilder::join() for joining collections with a separator
This patch adds a generic StringBuilder::join(separator, collection):

    Vector<String> strings = { "well", "hello", "friends" };
    StringBuilder builder;
    builder.join("+ ", strings);
    builder.to_string(); // "well + hello + friends"
2020-03-20 14:41:23 +01:00
howar6hill
e07f50c398 AK: Add begin() and end() to String and StringView
Now it's possible to use range-based for loops with String and StringView.
2020-03-10 10:25:21 +01:00
Andreas Kling
b956e2d939 AK: Remove all the AK .host.o files on "make clean" in AK/Tests
This is a bit hackish, but sometimes these files stick around and mess
up rebuilds.
2020-03-08 21:40:40 +01:00
howar6hill
6da131d5db AK: Reduce code duplication in StringBuilder 2020-03-08 17:08:18 +01:00
howar6hill
d8df9c510c AK: Improve the API of StringBuilder 2020-03-08 17:08:18 +01:00
Liav A
0433c0780d AK: Use default constructor of Optional if an unset bit is not found 2020-03-08 14:13:30 +01:00
Andreas Kling
32f15f3c45 AK: Remove unused InlineLRUCache template
This was not used by anyone. If we ever need it, we can bring it back.
2020-03-08 13:13:34 +01:00
Andreas Kling
900f51ccd0 AK: Move memory stuff (fast memcpy, etc) to a separate header
Move the "fast memcpy" stuff out of StdLibExtras.h and into Memory.h.
This will break a ton of things that were relying on StdLibExtras.h
to include a bunch of other headers. Fix will follow immediately after.

This makes it possible to include StdLibExtras.h from Types.h, which is
the main point of this exercise.
2020-03-08 13:06:51 +01:00
Andreas Kling
35d88f536c AK: Use __builtin_memset() and such to reduce header dependencies
We can use __builtin_memset() without including <string.h>.
This is pretty neat, as it will allow us to reduce the header deps
of AK templates a bit, if applied consistently.

Note that this is an enabling change for an upcoming #include removal.
2020-03-08 13:06:51 +01:00
Andreas Kling
b1058b33fb AK: Add global FlatPtr typedef. It's u32 or u64, based on sizeof(void*)
Use this instead of uintptr_t throughout the codebase. This makes it
possible to pass a FlatPtr to something that has u32 and u64 overloads.
2020-03-08 13:06:51 +01:00
Andreas Kling
b98d8ad5b0 AK: Add a Conditional<condition, TrueType, FalseType> template
This allows you to select a type based on a compile-time condition.
2020-03-08 13:06:51 +01:00
Andreas Kling
b866582d98 AK: Fix all the warnings in the AK tests 2020-03-06 11:22:23 +01:00
Andreas Kling
8bb361889c AK: Remove Optional::operator bool()
This was causing some obvious-in-hindsight but hard to spot bugs where
we'd implicitly convert the bool to an integer type and carry on with
the number 1 instead of the actual value().
2020-03-06 10:32:58 +01:00
Andreas Kling
dc039fdc7e AK: Simplify JsonObject and JsonArray API a little bit
Instead of set(const JsonValue&) and set(JsonValue&&), just do
set(JsonValue) and let callers move() if they want. This removes some
ambiguity and the compiler is smart enough to optimize it anyway.
2020-03-06 08:51:22 +01:00
Andreas Kling
783c99516a AK: LogStream should handle being passed a null const char* 2020-03-04 21:04:06 +01:00
Andreas Kling
686ade6b5a AK: Make quick_sort() a little more ergonomic
Now it actually defaults to "a < b" comparison, instead of forcing you
to provide a trivial less-than comparator. Also you can pass in any
collection type that has .begin() and .end() and we'll sort it for you.
2020-03-03 16:02:58 +01:00
Liav A
9440c45d6e AK: Add support for Kernel Log Stream 2020-03-02 22:23:39 +01:00
Andreas Kling
214f934465 Meta: Adjust some copyright dates by Fei Wu 2020-03-02 14:24:25 +01:00
Andreas Kling
f5b78c2a1c AK: Add missing copyright headers to StringUtils.{cpp,h} 2020-03-02 14:23:11 +01:00
howar6hill
d75fa80a7b
AK: Move to_int(), to_uint() implementations to StringUtils (#1338)
Provide wrappers in String and StringView. Add some tests for the
implementations.
2020-03-02 14:19:33 +01:00
howar6hill
055344f346 AK: Move the wildcard-matching implementation to StringUtils
Provide wrappers in the String and StringView classes, and add some tests.
2020-03-02 10:38:08 +01:00
howar6hill
2a30a020c1
AK: Add enqueue_begin() for the CircularDeque class (#1320)
Also add tests for CircularDeque.
2020-03-02 09:50:43 +01:00
howar6hill
4ed2ba264d
AK: Remove superfluous explicit in Bitmap (#1337) 2020-03-02 09:50:22 +01:00
Andreas Kling
22d0a6d92f AK: Remove unnecessary casts to size_t, after Vector changes
Now that Vector uses size_t, we can remove a whole bunch of redundant
casts to size_t.
2020-03-01 12:58:22 +01:00
Andreas Kling
dcd619bd46 Kernel: Merge the shbuf_get_size() syscall into shbuf_get()
Add an extra out-parameter to shbuf_get() that receives the size of the
shared buffer. That way we don't need to make a separate syscall to
get the size, which we always did immediately after.
2020-02-28 12:55:58 +01:00
Andreas Kling
a1514369d7 LibC: Move shbuf_* API's to <serenity.h> 2020-02-28 12:55:58 +01:00
Andreas Kling
f72e5bbb17 Kernel+LibC: Rename shared buffer syscalls to use a prefix
This feels a lot more consistent and Unixy:

    create_shared_buffer()   => shbuf_create()
    share_buffer_with()      => shbuf_allow_pid()
    share_buffer_globally()  => shbuf_allow_all()
    get_shared_buffer()      => shbuf_get()
    release_shared_buffer()  => shbuf_release()
    seal_shared_buffer()     => shbuf_seal()
    get_shared_buffer_size() => shbuf_get_size()

Also, "shared_buffer_id" is shortened to "shbuf_id" all around.
2020-02-28 12:55:58 +01:00
howar6hill
a19967d5c3 Tests: Fix a typo inTestRefPtr 2020-02-27 21:16:02 +01:00
William McPherson
121e7306c3 AK: Expose SinglyLinkedListIterator constructor
This commit replaces SinglyLinkedListIterator::universal_end() with an
empty SinglyLinkedListIterator(). Piano needs this in order to
initialize a member array of iterators without 84 lines of
universal_end().
2020-02-27 10:21:13 +01:00
howar6hill
a57f074187 CircularQueue: Move construct a T object instead of copy constructing it 2020-02-26 15:22:45 +01:00
Andreas Kling
6824cb17a6 AK: Have AK/kmalloc.h #include <new> on other platforms
This should make stuff like placement new work correctly when building
outside of Serenity. This stuff is a bit delicate due to the weirdly
staged toolchain build at the moment. Hopefully we can unify this stuff
in the future.
2020-02-25 15:58:24 +01:00
Andreas Kling
00e744c263 AK: Provide a ptr_hash(const void*) overload 2020-02-25 15:37:07 +01:00
joshua stein
7e6ac544f7 AK: Add ptr_hash to use int_hash or u64_hash depending on pointer size 2020-02-25 15:32:58 +01:00
Andreas Kling
960cae924a AK: Some more int => size_t in Bitmap 2020-02-25 15:11:15 +01:00
Andreas Kling
fbe4081f4b AK: Make Queue use size_t for its size 2020-02-25 14:55:04 +01:00
Andreas Kling
ceec1a7d38 AK: Make Vector use size_t for its size and capacity 2020-02-25 14:52:35 +01:00
Emanuel Sprung
074d935c6e AK, LibGfx, LibGUI: Initialize various variables to zero.
The not initialized variables can lead to compiler warnings that
become errors with the -Werror flag.
2020-02-25 10:18:46 +01:00
Andreas Kling
17846dd063 AK: Zero-initialize the internal storage of Optional 2020-02-24 10:22:27 +01:00
Andreas Kling
0763f67043 AK: Make Bitmap use size_t for its size
Also rework its API's to return Optional<size_t> instead of int with -1
as the error value.
2020-02-24 09:56:07 +01:00
Andreas Kling
b813b2f871 AK: Make HashTable and HashMap use size_t for size and capacity 2020-02-24 09:42:52 +01:00
Shannon Booth
ba9313111f AK: Add StringBuilder::is_empty() 2020-02-22 21:36:54 +01:00
Shannon Booth
854f0b9e1a AK: Add StringView::starts_with(char) & StringView::ends_with(char)
This is simply meant to be a more efficient implementation in the
case that we only need to check a single character.
2020-02-22 21:36:54 +01:00
Andreas Kling
c4c1ad2289 Toolchain: Build demangling into LibC except during toolchain build 2020-02-21 18:54:57 +01:00
Andreas Kling
7592f9afd5 AK: Use size_t for CircularQueue and CircularDeque 2020-02-20 13:20:34 +01:00
Andreas Kling
88b9fcb976 AK: Use size_t for ByteBuffer sizes
This matches what we already do for string types.
2020-02-20 13:20:34 +01:00
Andreas Kling
23a54636ea AK: Fix bug where "%s" with field width would print too many characters
I introduced this while implementing "%.*s", oops.
2020-02-19 23:02:15 +01:00
Andreas Kling
151467b569 AK: Support "%.*s" in format strings
Work towards #623.
2020-02-19 22:08:13 +01:00
Liav A
01ae3e9c85 AK: Use endianness flags to determine if conversion is necessary 2020-02-19 16:08:28 +01:00
Andreas Kling
a7dbb3cf96 Kernel: Use a FixedArray for a process's extra GIDs
There's not really enough of these to justify using a HashTable.
2020-02-18 11:35:47 +01:00
Sergey Bugaev
bf8dacf0c1 Kernel: Add placement new[] operator 2020-02-18 11:23:27 +01:00
Andreas Kling
48f7c28a5c Kernel: Replace "current" with Thread::current and Process::current
Suggested by Sergey. The currently running Thread and Process are now
Thread::current and Process::current respectively. :^)
2020-02-17 15:04:27 +01:00
Andreas Kling
a6e69bda71 AK: Add basic Traits for RefPtr
This allows RefPtr to be stored in a HashTable<RefPtr<T>> :^)

It's unfortunate about the const_casts. We'll need to fix HashMap::get
to play nice with non-const Traits<T>::PeekType at some point.
2020-02-16 21:58:17 +01:00
Andreas Kling
02e199a9cb AK: Don't construct a String every time we LogStream<< a number 2020-02-16 12:48:58 +01:00
Kaif Mavani
fa21c7e8bf
AK: Fixed a typo in NeverDestroyed.h (#1228) 2020-02-16 09:32:18 +01:00
Andreas Kling
e61cdf5c39 AK: Add HashMap, HashTable and Traits to Forward.h 2020-02-16 02:01:18 +01:00
Andreas Kling
a356e48150 Kernel: Move all code into the Kernel namespace 2020-02-16 01:27:42 +01:00
Andreas Kling
d42f0f4661 AK: Add missing include in CircularQueue.h 2020-02-16 01:27:25 +01:00
Andreas Kling
f27a646bf5 AK: Don't bring in LibBareMetal's kstdio.h in userspace 2020-02-15 19:18:56 +01:00
Andreas Kling
b515ea454f AK: Make sure that Weakable always has the same memory layout
Weakable objects ended up with differing memory layouts in some ports
since they don't build with the DEBUG macro defined.

Instead of forcing ports to define DEBUG, just put this behind a custom
WEAKABLE_DEBUG macro and leave it always-on for now.
2020-02-15 14:49:57 +01:00
Andreas Kling
175cd4d9c2 AK: Fix broken #include statement 2020-02-15 13:28:33 +01:00
Andreas Kling
dc417ada6d AK: Add BufferStream to Forward.h 2020-02-15 12:10:48 +01:00
Shannon Booth
9920d17342 AK: Add String starts_with(char) & ends_with(char)
This is simply meant to be a more efficient implementation in the
case that we only need to check a single character.
2020-02-15 11:40:05 +01:00
Andreas Kling
d85b09893d AK: Add Utf8View to Forward.h 2020-02-14 23:31:18 +01:00
Andreas Kling
22b41a0fa3 AK: Add LogStream and DebugLogStream to Forward.h 2020-02-14 23:31:18 +01:00
Andreas Kling
184475d45a AK: Add SharedBuffer to Forward.h 2020-02-14 23:31:18 +01:00
Andreas Kling
8f7333f080 LibCore: Add a forward declaration header
This patch adds <LibCore/Forward.h> and uses it in various places to
shrink the header dependency graph.
2020-02-14 23:31:18 +01:00
Andreas Kling
3bbf4610d2 AK: Add a forward declaration header
You can now #include <AK/Forward.h> to get most of the AK types as
forward declarations.

Header dependency explosion is one of the main contributors to compile
times at the moment, so this is a step towards smaller include graphs.
2020-02-14 23:31:18 +01:00
Andreas Kling
3e486f75ff AK: Move escape_html_entities() from LibHTML to AK
This sort of thing can be useful to things that don't want to link with
all of LibHTML.
2020-02-13 08:46:00 +01:00
Andreas Kling
6cbd72f54f AK: Remove bitrotted Traits::dump() mechanism
This was only used by HashTable::dump() which I used when doing the
first HashTable implementation. Removing this allows us to also remove
most includes of <AK/kstdio.h>.
2020-02-10 11:55:34 +01:00
Liav A
8bdb08c354 AK: Apply changes for the Bootstrapper environment 2020-02-09 19:38:17 +01:00
Andreas Kling
80b1af2352 AK: Make StringBuilder::to_string() non-destructive
This was an artifact of an earlier design of StringBuilder where I had
attempted to preserve the same allocation from build to final String.
2020-02-09 14:15:55 +01:00
Andreas Kling
745ea2a0ef AK: Add JsonObjectSerializer::add(key, bool) overload
Without this, bools will get implicitly converted to integers, which is
usually not what we want.
2020-02-08 02:48:27 +01:00
Andreas Kling
a7e72f78cd AK: Make PrintfImplementation treat %lld as 64-bit 2020-02-08 01:43:05 +01:00
Andreas Kling
28a5e33134 AK: Add LogStream overloads for long and long long 2020-02-08 01:41:43 +01:00
Andreas Kling
9afda55d73 AK: Add some missing "inline" keywords in JsonObject.h 2020-02-06 19:32:17 +01:00
Andreas Kling
939a605334 AK: Add missing StdLibExtras.h include in Optional.h 2020-02-06 11:55:19 +01:00
Andreas Kling
0cff25ac78 AK+IPCCompiler: Get rid of BufferStream overloads for size_t
Since BufferStream is about creating specific binary stream formats,
let's not have a flaky type like size_t in there. Instead, clients of
BufferStream can cast their size_t to the binary size they want to use.

Account for this in IPCCompiler by making String lengths always 32-bit.
2020-02-05 19:13:44 +01:00
Andreas Kling
be0034d2ca AK: Break LogStream::operator<< overloads into i/l/ll and u/ul/ull 2020-02-05 19:13:44 +01:00
Andreas Kling
90b1dafeff AK: Break String::number() overloads into i/l/ll and u/ul/ull
Now that we're trying to be more portable, we can't only rely on using
i32/u32 and i64/u64 since different systems have different combinations
of int/long/long long and unsigned/unsigned long/unsigned long long.
2020-02-05 19:13:44 +01:00
joshua stein
0c4c5b5eb7 AK: Support 64-bit integers in BufferStream 2020-02-05 18:39:45 +01:00
joshua stein
dc93ed4368 AK: Add support for 64-bit size_t 2020-02-05 18:39:45 +01:00
Andreas Kling
c600280dde AK: The <cxxabi.h> header is not available during Toolchain build
This will need some refinement, but basically since we build LibC
during the toolchain build, we don't have libstdc++ headers yet.
2020-02-03 06:27:54 +01:00
Andreas Kling
8ccf0e16a9 AK: Turn demangling back on for userspace
This didn't work at some point, but now it apparently works again. :^)
2020-02-02 20:15:58 +01:00
Andreas Kling
ab57db2bf1 AK: #ifdef out the contents of SharedBuffer on other platforms 2020-02-01 20:18:53 +01:00
Andreas Kling
268000e166 AK: Always inline StringView(const char*)
Also use strlen() instead of manually walking the string. This allows
GCC to optimize away the strlen() entirely for string literals. :^)
2020-02-01 13:54:13 +01:00
Andreas Kling
276b6a4372 AK: Add some integer overloads to JsonObjectSerializer
This avoids constructing a temporary JsonValue just to append an int.
2020-02-01 10:56:17 +01:00
William McPherson
ddefb95b21 AK: Add FixedArray::data() 2020-01-31 13:13:04 +01:00
Marios Prokopakis
da296f5865 Ext2FS: allocate_blocks allocates contiguous blocks (#1095)
This implementation uses the new helper method of Bitmap called
find_longest_range_of_unset_bits. This method looks for the biggest 
range of contiguous bits unset in the bitmap and returns the start of
the range back to the caller.
2020-01-26 09:48:24 +01:00
Andreas Kling
603bf6fb4a Build: Remove -fno-sized-deallocation -Wno-sized-deallocation
Add sized variants of the global operator delete functions so we don't
have to use these GCC options anymore.
2020-01-25 16:59:21 +01:00
Andreas Kling
003d52ce6e AK: Vector::is_null() should always return false
This is only used by the somewhat dubious templated String::copy().
An empty Vector should generate an empty String when copied, never
a null String.
2020-01-25 12:14:59 +01:00
Andreas Kling
3f52cee595 AK: Assert if trying to create a WeakPtr to an object being destroyed
Trying to make_weak_ptr() on something that has begun destruction is
very unlikely to be what you want. Let's assert if that scenario comes
up so we can catch it immediately.
2020-01-25 10:34:32 +01:00
Sergey Bugaev
c0b32f7b76 Meta: Claim copyright for files created by me
This changes copyright holder to myself for the source code files that I've
created or have (almost) completely rewritten. Not included are the files
that were significantly changed by others even though it was me who originally
created them (think HtmlView), or the many other files I've contributed code to.
2020-01-24 15:15:16 +01:00
Andreas Kling
ca413a5b50 AK: Use swap-based assignment in OwnPtr
Also provide a specialized swap(OwnPtr, OwnPtr) that allows swapping
an OwnPtr with itself.
2020-01-24 09:35:55 +01:00
Andreas Kling
3de5439579 AK: Let's call decrementing reference counts "unref" instead of "deref"
It always bothered me that we're using the overloaded "dereference"
term for this. Let's call it "unreference" instead. :^)
2020-01-23 15:14:21 +01:00
Andreas Kling
d66bbc21ce AK: Unbreak FileSystemPath after String::split() changes
FileSystemPath(".") should not have a title(). This was caught by the
unit test for FileSystemPath, yay! :^)
2020-01-22 22:35:12 +01:00
Sergey Bugaev
6a64077ed7 AK: Also add a keep_empty argument to String::split[_limit]()
Just like String[View]::split_view() has already.
2020-01-22 21:22:23 +01:00
Andreas Kling
f38cfb3562 Kernel: Tidy up debug logging a little bit
When using dbg() in the kernel, the output is automatically prefixed
with [Process(PID:TID)]. This makes it a lot easier to understand which
thread is generating the output.

This patch also cleans up some common logging messages and removes the
now-unnecessary "dbg() << *current << ..." pattern.
2020-01-21 16:16:20 +01:00
Andreas Kling
2309029cb4 AK: Allow clamp() with min==max 2020-01-20 13:49:05 +01:00
Andreas Kling
e07b34b9b8 Kernel+AK: Add/fix uintptr_t and intptr_t definitions
We should move towards using uintptr_t instead of u32 for pointers
everywhere, to prepare for an eventual 64-bit port.
2020-01-20 13:13:03 +01:00
Shannon Booth
de74458f13 AK: Add clamp() function
This function can be used to more cleanly write the common operation of
clamping a value between two values.
2020-01-20 10:35:12 +01:00
Andreas Kling
d394267f50 AK: Add NonnullOwnPtr::swap() as well for symmetry 2020-01-19 16:03:57 +01:00
Andreas Kling
ad3f931707 Kernel: Optimize VM range deallocation a bit
Previously, when deallocating a range of VM, we would sort and merge
the range list. This was quite slow for large processes.

This patch optimizes VM deallocation in the following ways:

- Use binary search instead of linear scan to find the place to insert
  the deallocated range.

- Insert at the right place immediately, removing the need to sort.

- Merge the inserted range with any adjacent range(s) in-line instead
  of doing a separate merge pass into a list copy.

- Add Traits<Range> to inform Vector that Range objects are trivial
  and can be moved using memmove().

I've also added an assertion that deallocated ranges are actually part
of the RangeAllocator's initial address range.

I've benchmarked this using g++ to compile Kernel/Process.cpp.
With these changes, compilation goes from ~41 sec to ~35 sec.
2020-01-19 13:29:59 +01:00
Andreas Kling
502626eecb AK: Teach Vector::insert() to use memmove() for trivial types 2020-01-19 12:15:43 +01:00
Andreas Kling
109727082c AK: Support '+' qualifier in printf() to force sign for positive %d's 2020-01-19 11:00:02 +01:00