Commit Graph

784 Commits

Author SHA1 Message Date
Andreas Kling
2db2b8b0ef AK: Add FlyString::is_empty() 2020-04-16 20:22:54 +02:00
Andreas Kling
63b8c6913c AK: Add Checked<T>::multiplication_would_overflow()
This allows you to comfortably test if multiply 2 or 3 values would
cause arithmetic overflow.
2020-04-15 17:14:18 +02:00
Andreas Kling
9c54bad241 AK: Add a Checked<T> template
A Checked<T> is a boxed integer type that asserts if you try to use its
value after an arithmetic overflow.
2020-04-15 16:58:46 +02:00
Andreas Kling
9a5dba9e09 AK: Add MakeUnsigned<T> helper template 2020-04-15 16:58:46 +02:00
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