Commit graph

975 commits

Author SHA1 Message Date
asynts 05abfc0e1f AK: Rename MakeUnsigned::type to MakeUnsigned::Type.
Also renames MakeSigned::type to MakeSigned::Type.
2020-08-06 10:33:16 +02:00
Muhammad Zahalqa 9495eeb075
AK: Make min/max behave like the STL for equivalent inputs (#2976)
min(a, b) now returns a if both are equivalent.
max(a, b) now returns a if both are equivalent.
2020-08-06 09:58:45 +02:00
Andreas Kling 3ba0164ce0 AK: Fix broken symlink used by JSON test 2020-08-06 00:05:52 +02:00
Nico Weber ce95628b7f Unicode: Try s/codepoint/code_point/g again
This time, without trailing 's'. Ran:

    git grep -l 'codepoint' | xargs sed -ie 's/codepoint/code_point/g
2020-08-05 22:33:42 +02:00
Nico Weber 19ac1f6368 Revert "Unicode: s/codepoint/code_point/g"
This reverts commit ea9ac3155d.
It replaced "codepoint" with "code_points", not "code_point".
2020-08-05 22:33:42 +02:00
Brian Gianforcaro a7ea7b3a66 AK: Decorate AK::Result<V, E> with [[nodiscard]] 2020-08-05 17:29:44 +02:00
Brian Gianforcaro adb83d3adc AK: Decorate AK::TriState with [[nodiscard]]
TriState is another type of return code, it's value should always be
observed.
2020-08-05 17:29:01 +02:00
Brian Gianforcaro 3319803bd9 AK: Decorate atomic compare exchange operations with [[nodiscard]]
All CAS operations should always check return values, so they are
robust to failure in the event of conflict in parallel operation.
2020-08-05 17:28:44 +02:00
Brian Gianforcaro f34fcdedef AK: Decorate AK::NonnullOwnPtr::leak_ptr() with [[nodiscard]] 2020-08-05 16:12:00 +02:00
Brian Gianforcaro fa625a2690 AK: Decorate AK::OwnPtr::leak_ptr() with [[nodiscard]]
We should always leak to an observed variable, otherwise
it's an actual leak. This is similar to AK::RefPtr::leak_ref()
which is also marked as [[nodiscard]].
2020-08-05 16:12:00 +02:00
Brian Gianforcaro a7a7e6245f AK: Decorate Optional<T> with [[nodisard]] 2020-08-05 12:27:15 +02:00
Brian Gianforcaro 125eab998f AK: Fix StringUtils tests to actually observe return value.
Noticed this while playing around with making Optional<T>
nodiscard.
2020-08-05 12:18:54 +02:00
Brian Gianforcaro 88092376f3 AK: Use AK relative include style for InlineLinkedList.h
This is the style that seems to be used in the rest of AK.
2020-08-05 12:13:50 +02:00
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