Commit Graph

962 Commits

Author SHA1 Message Date
Brian Gianforcaro
efb0805d8e AK: Add SinglyLinkedListWithCount<T>, a singulary linked list with count
There are use cases where a linked list is useful but it's also worth
the overhead to maintain a count so you can quickly answer queries of
the size of the list.
2020-08-05 09:34:22 +02:00
Andreas Kling
000ef0ec3d Revert "AK: Let the compiler provide the default new and delete operators"
This reverts commit 45b05e9734.

I forgot about the Toolchain build again. :^(
2020-08-04 21:16:07 +02:00
Andreas Kling
45b05e9734 AK: Let the compiler provide the default new and delete operators
...except in kernelspace.
2020-08-04 19:05:48 +02:00
Uma Sankar
e799da1fb6
AK: Remove an unused variable in the Span test (#2985) 2020-08-04 10:26:45 +02:00
Andreas Kling
ea9ac3155d Unicode: s/codepoint/code_point/g
Unicode calls them "code points" so let's follow their style.
2020-08-03 19:06:41 +02:00
Tom
df52061cdb AK: Add more time convenience functions and comparison operators 2020-08-03 18:23:00 +02:00
Tom
df3c8267d4 AK: Fix adding timeval/timespec
tv_usec and tv_nsec should always be less than one second.
2020-08-03 15:59:11 +02:00
Muhammad Zahalqa
615ba0f368
AK: Fix overflow and mixed-signedness issues in binary_search() (#2961) 2020-08-02 21:10:35 +02:00
Brian Gianforcaro
6e54d0c072 AK: Remove relative_paths test from TestLexicalPath
This test appears to be testing functionality that doesn't
exist. Just remove it.

Closes old bug #2388

CC @bugaevc
2020-08-02 20:48:37 +02:00
Andreas Kling
9bcf0b70cb AK: Hack Userspace<T> to not break Qt Creator syntax highlighting
This is a very cheesy patch and I don't like it, but as Qt Creator does
not grok C++20 concepts yet, this makes it possible to still use syntax
highlighting.

We'll remove this hack the moment it stops being a problem. Note that
it doesn't actually affect the build since we use GCC, not Clang.
2020-08-02 11:01:00 +02:00
Emanuele Torre
6c1ba09fbd AK: In Userspace.h, #if defined(KERNEL) => #ifdef KERNEL 2020-08-01 10:44:42 +02:00
Emanuele Torre
5bf994d2d9 AK: Use C++20 concepts to only allow Userspace wrappers of pointers
It was a bit odd that you could create a Userspace<int> and that
Userspace<int>::ptr() returned an int instead of an int*.

Let's use C++20 concepts to only allow creating Userspace objects with
pointer types. :^)
2020-08-01 10:44:42 +02:00
AnotherTest
6131417904 AK: Make MappedFile store why it is invalid
This makes AK::MappedFile save the errno either open() or mmap() failed
with.
2020-08-01 08:39:26 +02:00
AnotherTest
fd64be02e0 AK: Add StringView::contains(StringView) 2020-08-01 08:39:26 +02:00
Andreas Kling
628b3badfb Kernel+AK: Add and use Userspace<T>::unsafe_userspace_ptr()
Since we already have the type information in the Userspace template,
it was a bit silly to cast manually everywhere. Just add a sufficiently
scary-sounding getter for a typed pointer.

Thanks @alimpfard for pointing out that I was being silly with tossing
out the type.

In the future we may want to make this API non-public as well.
2020-07-31 20:56:48 +02:00
Andreas Kling
e39a410546 AK: Add Userspace<T>, a wrapper for userspace pointers
This will be used in the kernel to wrap pointers into userspace memory
without convenient direct access. The idea is to use the compiler to
enforce that we don't dereference userspace pointers.
2020-07-31 16:26:44 +02:00
Ben Wiederhake
17248ab6fe AK: On failed mmap, don't claim that there's a readable page 2020-07-31 11:34:06 +02:00
AnotherTest
681bb1fb23 AK: Add (more) tests for String(View)::split*
This patchset adds some tests for String(View)::split*, hopefully
documenting their behaviour in some cases.
2020-07-30 18:47:41 +02:00
Andreas Kling
ebd2e7d9f5 AK: Tweak String::is_one_of() and FlyString::is_one_of()
Switch the comparisons from "other == *this" to "*this == other".
2020-07-28 18:55:47 +02:00
Peter Elliott
e57a432118 AK: Make String::substring() return non-null for 0-length strings
This also makes String::split() give non-null strings when keep_empty is
true.
2020-07-28 17:07:22 +02:00
asynts
abe925e4b0 AK: Change the signature of AK::encode_base64() to use Span. 2020-07-27 19:58:09 +02:00
asynts
5fa0fdb219 AK: Rename Span::subspan() to Span::slice(). 2020-07-27 19:58:09 +02:00
asynts
8d2dba022e AK: Add offset() method to Span. 2020-07-27 19:58:09 +02:00
asynts
a922abd9d7 AK: Add span() / bytes() methods to container types. 2020-07-27 19:58:09 +02:00
asynts
c42450786c AK: Add implicit conversion from nullptr to Span. 2020-07-27 19:58:09 +02:00
asynts
2b57891e07 AK: Add constructors to Bytes and ReadonlyBytes that take void pointers. 2020-07-27 19:58:09 +02:00
asynts
7036a9b6f7 AK: Define conversion from Span<T> to Span<const T> correctly.
I accidently wrote `Span<RemoveConst<T>>` when I meant
`Span<RemoveConst<T>::Type>`.

Changing that wouldn't be enough though, this constructor can only be
defined if T is not const, otherwise it would redefine the copy
constructor.  This can be avoided by overloading the cast operator.
2020-07-27 19:58:09 +02:00
Andreas Kling
1366557094 AK+LibC: Always use REP MOVSB/STOSB for memcpy()/memset()
There's no great advantage to using MMX instructions here on modern
processors, since REP MOVSB/STOSB are optimized in microcode anyway
and tend to run much faster than MMX/SSE/AVX variants.

This also makes it much easier to implement high-level emulation of
memcpy/memset in UserspaceEmulator once we get there. :^)
2020-07-27 15:54:39 +02:00
Andreas Kling
ce2c5b375c AK: Add global is<T>() and downcast<T>()
Let's unify the is<T>/to<T> implementations that currently exist in
separate versions in LibCore and LibWeb.
2020-07-26 17:51:00 +02:00
asynts
707d92db61 Refactor: Change the AK::binary_search signature to use AK::Span. 2020-07-26 16:49:06 +02:00
asynts
ac9c2bc492 AK: Implement Span which represents a contiguous sequence of objects.
This makes it possible to pass one object rather than pointer and length
individually.
2020-07-26 16:49:06 +02:00
Ben Wiederhake
8c14219fb1 AK: Fix print_double
Fixes #2776.

This fixes, among other things, JSON serialization.

The underlying bug was that 'print_double' defined fraction_length
as a function argument with a default value, whereas
printf_internal *always* provided a value, even if nothing was read.
The 'use 6 by default' logic has been moved to printf_internal instead.
2020-07-25 12:32:55 +02:00
Andreas Kling
cd4bc81dbb AK: Add a couple more helper templates to StdLibExtras 2020-07-24 02:38:17 +02:00
Nico Weber
3f45e9ab1e Lagom: Add LibGemini, LibGfx
They are dependencies of LibWeb and might be useful for
running test-web on GitHub actions one day.
2020-07-23 23:02:28 +02:00
Nico Weber
5ba8aba197 AK: Make encode_base64 take a ByteBuffer and return a String
That makes the interface symmetric with decode_base64 and it's
what all current callers want (except for one, which is buggy).
2020-07-22 19:22:00 +02:00
Luke
a5ecb9bd6b AK: Add case insensitive version of starts_with 2020-07-21 01:08:32 +02:00
Andreas Kling
70cb4491d7 AK: Use "signed char" as the opposite of "unsigned char"
I totally forgot about the C++ basics here. There are three distinct
types: "char", "signed char" and "unsigned char". Whether "char" is
signed or unsigned is implementation specific.
2020-07-18 17:57:40 +02:00
Nico Weber
59596ff816 LexicalPath: Simplify a loop
No behavior change.
2020-07-15 20:16:38 +02:00
Matthew Olsson
c831fb17bf LibJS: Add StringIterator 2020-07-13 15:07:29 +02:00
Nico Weber
552789902a AK: Make LexicalPath keep everything before the last dot as title
Previously, TextEditor would put "foo.txt" in the Save As dialog
for files named "foo.bar.txt". Now, it puts "foo.bar.txt" instead.
2020-07-13 15:00:14 +02:00
Nico Weber
97cea9e61c AK: Give String::index_of() an optional second "start" argument 2020-07-13 15:00:14 +02:00
Tom
dadd53e4f2 AK: HashTable/HashMap return whether action was performed for set/remove
This allows performing an action based on whether something
was actually added or removed without having to look it up
prior to calling set() or remove().
2020-07-09 21:58:07 +02:00
Andreas Kling
ecd4c6718e AK: Fix JsonValue copy constructor behavior for 64-bit values
The fact that JsonValues can contain 64-bit values isn't a JavaScript
compatible behavior in the first place, but as long as we're supporting
this, we should make sure it works correctly.
2020-07-06 18:38:08 +02:00
Andreas Kling
2c4a168404 AK: Remove debug spam in SharedBuffer::create_from_shbuf_id() 2020-07-05 16:36:28 +02:00
Sergey Bugaev
6111cfda73 AK: Make Vector::unstable_remove() return the removed value
...and rename it to unstable_take(), to align with other take...() methods.
2020-07-05 12:26:27 +02:00
Andreas Kling
11c4a28660 Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
Andreas Kling
f7577585a6 AK: Add Weakable::revoke_weak_ptrs()
This allows you to clear all the WeakPtrs pointing at a Weakable *now*
instead of waiting until the Weakable is destroyed.
2020-07-04 16:23:52 +02:00
Tom
038dd9f30e AK: Serialize entire log statements
Prior to this, we wrote to the log every time the << operator
was used, which meant that only these parts of the log statement
were serialized. If the thread was preempted, or especially with
multiple CPUs the debug output was hard to decipher. Instead, we
buffer up the log statements. To avoid allocations we'll attempt
to use stack space, which covers most log statements.
2020-07-03 19:32:34 +02:00
Tom
137e1dc7bd AK: Fixes for atomic pointers 2020-07-03 19:32:34 +02:00
Tom
16783bd14d Kernel: Turn Thread::current and Process::current into functions
This allows us to query the current thread and process on a
per processor basis
2020-07-01 12:07:01 +02:00