Commit graph

1423 commits

Author SHA1 Message Date
asynts 9d588cc9cc Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-22 22:14:30 +01:00
asynts 5356aae3cc Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-22 22:14:30 +01:00
asynts 663a6141d8 AK: Add set_debug_enabled method. 2021-01-22 22:14:30 +01:00
Tom 7581b64705 AK: Add Vector::remove overload for removing entire ranges 2021-01-17 20:30:31 +01:00
Tom b17a889320 Kernel: Add safe atomic functions
This allows us to perform atomic operations on potentially unsafe
user space pointers.
2021-01-17 20:30:31 +01:00
Andreas Kling 7a0bc2fdb8 LibGfx: Convert all the dbg() in BMPLoader to dbgln()
Also get rid of the awkward IF_BMP_DEBUG macro while we're here.
2021-01-17 15:42:10 +01:00
Andreas Kling 65fa0c2774 AK: Make is<T>(input) use input.fast_is<T>() if available
This allows classes to provide an optimized is<T> via the fast_is<T>()
member function.
2021-01-17 14:42:23 +01:00
Andreas Kling bf0719092f Kernel+Userland: Remove shared buffers (shbufs)
All users of this mechanism have been switched to anonymous files and
passing file descriptors with sendfd()/recvfd().

Shbufs got us where we are today, but it's time we say good-bye to them
and welcome a much more idiomatic replacement. :^)
2021-01-17 09:07:32 +01:00
Andreas Kling 05dbfe9ab6 Kernel: Remove sys$shbuf_seal() and userland wrappers
There are no remaining users of this syscall so let it go. :^)
2021-01-17 00:18:01 +01:00
Andreas Kling b818cf898e Kernel+Userland: Remove sys$shbuf_allow_all() and userland wrappers
Nobody is using globally shared shbufs anymore, so let's remove them.
2021-01-16 22:43:03 +01:00
Andreas Kling de31e82f97 Kernel: Remove sys$shbuf_set_volatile() and userland wrappers
There are no remaining users of this syscall so let's remove it! :^)
2021-01-16 14:52:04 +01:00
asynts 94bb544c33 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.

This commit touches some dbg() calls which are enclosed in macros. This
should be fine because with the new constexpr stuff, we ensure that the
stuff actually compiles.
2021-01-16 11:54:35 +01:00
asynts 4953c73fc1 AK: Add enabled template parameter to dbgln. 2021-01-16 11:54:35 +01:00
Linus Groh 7ad9b116f7 AK: Add String::join() helper function
This is a simple wrapper around StringBuilder::join().
2021-01-15 23:26:47 +01:00
Linus Groh e83799dc02 AK: Add JsonArray(const Vector<T>) constructor
This simplifies creating a JsonArray from a Vector<T> (when there's a
JsonValue(T) constructor overload for T, that is).
2021-01-15 23:26:47 +01:00
Lenny Maiorani 6d6b3f9523 Badge: Access to underlying type
Problem:
- Access to the underlying type is not provided. This limits
  metaprogramming and usage in function templates.

Solution:
- Provide public access to the underlying type.
- Add test to ensure the underlying type is accessible.
2021-01-15 09:44:21 +01:00
Lenny Maiorani 53afdc0106 StringView: Implement find_first_of in terms of AK::find
Problem:
- The implementation of `find_first_of` is coupled to the
  implementation of `StringView`.

Solution:
- Decouple the implementation of `find_first_of` from the class by
  using a generic `find` algorithm.
2021-01-15 09:42:42 +01:00
Lenny Maiorani d11727ff28 AK: Implement generic any_of algorithm
Problem:
- Raw loops are often written to validate that any values in a
  container meet a predicate, but raw loops are not as expressive as
  functions implementing well-named algorithms and are error-prone.

Solution:
- Implement a very generic form of `any_of`.
2021-01-15 09:42:42 +01:00
AnotherTest 4fe27ec2a7 AK: Use StringView::find() in StringView::split_view()
This fixes #4926.
2021-01-12 23:36:20 +01:00
AnotherTest 39442e6d4f AK: Add String{View,}::find(StringView)
I personally mistook `find_first_of(StringView)` to be analogous to this
so let's add a `find()` method that actually searches the string.
2021-01-12 23:36:20 +01:00
Andreas Kling 1a08ac72ad LibC+Everywhere: Remove open_with_path_length() in favor of open()
This API was a mostly gratuitous deviation from POSIX that gave up some
portability in exchange for avoiding the occasional strlen().

I don't think that was actually achieving anything valuable, so let's
just chill out and have the same open() API as everyone else. :^)
2021-01-12 23:34:01 +01:00
Lenny Maiorani e6f907a155 AK: Simplify constructors and conversions from nullptr_t
Problem:
- Many constructors are defined as `{}` rather than using the ` =
  default` compiler-provided constructor.
- Some types provide an implicit conversion operator from `nullptr_t`
  instead of requiring the caller to default construct. This violates
  the C++ Core Guidelines suggestion to declare single-argument
  constructors explicit
  (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit).

Solution:
- Change default constructors to use the compiler-provided default
  constructor.
- Remove implicit conversion operators from `nullptr_t` and change
  usage to enforce type consistency without conversion.
2021-01-12 09:11:45 +01:00
AnotherTest 7029a8f605 AK: Specialise convert_to_uint<T> and to_uint<T> for 'long' variants 2021-01-11 21:09:36 +01:00
Sahan Fernando ccf4368ca5 AK: Enable format string warnings for AK printf wrappers 2021-01-11 21:06:32 +01:00
Lenny Maiorani 1b2364846f SinglyLinkedList: Implement find in terms of AK::find
Problem:
- The implementation of `find` is coupled to the implementation of
  `SinglyLinkedList`.

Solution:
- Decouple the implementation of `find` from the class by using a
  generic `find` algorithm.
2021-01-11 19:45:05 +01:00
Lenny Maiorani 853cb8af5c DoublyLinkedList: Implement find in terms of AK::find
Problem:
- The implementation of `find` is coupled to the implementation of
  `DoublyLinkedList`.
- `append` and `prepend` are implemented multiple times so that
  r-value references can be moved from into the new node. This is
  probably not called very often because a pr-value or x-value needs
  to be used here.

Solution:
- Decouple the implementation of `find` from the class by using a
  generic `find` algorithm.
- Make `append` and `prepend` be function templates so that they can
  have binding references which can be forwarded.
2021-01-11 19:45:05 +01:00
Lenny Maiorani f99d1d3bd7 Vector: Implement find, find_if, find_first_matching in terms of AK::find*
Problem:
- The implementation of `find` is coupled to the implementation of `Vector`.
- `Vector::find` takes the predicate by value which might be expensive.

Solution:
- Decouple the implementation of `find` from `Vector` by using a
  generic `find` algorithm.
- Change the name of `find` with a predicate to `find_if` so that a
  binding reference can be used and the predicate can be forwarded to
  avoid copies.
- Change all the `find(pred)` call sites to use `find_if`.
2021-01-11 19:45:05 +01:00
Lenny Maiorani 4333a9a8d6 AK: Find a value in any container offering iterators
Problem:
- `find` is implemented inside of each container. This coupling
  requires that each container needs to individually provide `find`.

Solution:
- Decouple the `find` functionality from the container. This allows
  provides a `find` algorithm which can work with all
  containers. Containers can still provide their own `find` in the
  case where it can be optimized.
- This also allows for searching sub-ranges of a container rather than
  the entire container as some of the container-specific member
  functions enforced.

Note:
- @davidstone's talk from 2015 C++Now conference entitled "Functions
  Want to be Free" encourages this style:
  (https://www.youtube.com/watch?v=_lVlC0xzXDc), but it does come at
  the cost of composability.
- A logical follow-on to this is to provide a mechanism to use a
  short-hand function which automatically searches the entire
  container. This could automatically use the container-provided
  version if available so that functions which provide their own
  optimized version get the benefit.
2021-01-11 19:45:05 +01:00
asynts 723effd051 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.Everything:
2021-01-11 11:55:47 +01:00
Lenny Maiorani 700f213011 TestTypeTraits: Fix incorrectly namespaced nullptr_t
Problem:
- Clang ToT fails to build `AK/Tests/TestTypeTraits.cpp` because
  `nullptr_t` is missing the `std` namespace qualifier.

Solution:
- Prepend the namespace qualifier.
2021-01-10 18:20:14 +01:00
Andreas Kling 2f3b901f7f AK: Make MappedFile heap-allocated and ref-counted
Let's adapt this class a bit better to how it's actually being used.

Instead of having valid/invalid states and storing an error in case
it's invalid, a MappedFile is now always valid, and the factory
function that creates it will return an OSError if mapping fails.
2021-01-10 16:49:13 +01:00
Andreas Kling a8681da4bf AK: Add AK::OSError, a wrapper for errno codes
This is a strongly typed carrier for "errno" error codes, intended for
use in return types, e.g Result<String, OSError>.
2021-01-10 16:46:13 +01:00
Tom 1fc7d65aad AK: Add static Singleton::get function to allow destructible globals
This enable using global raw pointers rather than Singleton objects,
which solves some problems because global Singleton object could
be deleted when destructors are run.
2021-01-09 21:12:31 +01:00
asynts 1160817a9e AK: Add Formatter<FormatString> as helper class. 2021-01-09 21:11:09 +01:00
Andreas Kling 4a83a37f79 AK: Add release_value() and release_error() to AK::Result
These are nice when you want to move something out of the result,
and match the API we already have for Optional.
2021-01-09 19:57:50 +01:00
Tom fb84f0ec9c AK: Add default memory order as template argument for Atomic<T>
This is useful for collecting statistics, e.g.
Atomic<unsigned, MemoryOrder::memory_order_relaxed> would allow
using operators such as ++ to use relaxed semantics throughout
without having to explicitly call fetch_add with the memory order.
2021-01-04 19:13:52 +01:00
Tom a6c459dd29 AK: Decorate RefCountedBase::try_ref with nodiscard
Because try_ref only increments the ref count if it returned true,
it is important that any caller properly acts upon the return value.
2021-01-04 19:13:52 +01:00
AnotherTest f3ecea1fb3 AK: Add String{,View}::is_whitespace()
+Tests!
2021-01-03 10:47:29 +01:00
asynts 2927656d85 AK: Use size_t in methods of Utf8View. 2021-01-02 01:37:22 +01:00
asynts 3aaece8733 AK: Remove redundant compare() functions. 2021-01-02 01:37:22 +01:00
asynts 632ff01e17 Piggyback: AK: Add formatter for std::nullptr_t. 2021-01-02 01:37:22 +01:00
Andrew Kaster 986544600a AK: Add Result<void, ErrorType> specialization, cleanup
Add a specialization for a void ValueType. This is useful if a generic
function wants to return a Result<T, E> where the user might not
actually care abut the T, and default it to void. In this case it
basically becomes Unexpected<E> instead of Result, but hey, it works :)
2021-01-01 23:01:48 +01:00
Liav A d22d29a29a AK: Add the UUID container
This container represents a universally unique identifier. This will be
used later in the kernel for GUID partitions.
2021-01-01 22:59:48 +01:00
asynts e77031ce67 AK: Deal with unsigned integers in binary search. 2021-01-01 22:23:13 +01:00
Andreas Kling 865f524d5b AK+LibGUI+LibWeb: Remove AK::TypeTraits in favor of RTTI-based helpers
Now that we have RTTI in userspace, we can do away with all this manual
hackery and use dynamic_cast.

We keep the is<T> and downcast<T> helpers since they still provide good
readability improvements. Note that unlike dynamic_cast<T>, downcast<T>
does not fail in a recoverable way, but will assert if the object being
casted is not a T.
2021-01-01 15:33:30 +01:00
Linus Groh bbe787a0af Everywhere: Re-format with clang-format-11
Compared to version 10 this fixes a bunch of formatting issues, mostly
around structs/classes with attributes like [[gnu::packed]], and
incorrect insertion of spaces in parameter types ("T &"/"T &&").
I also removed a bunch of // clang-format off/on and FIXME comments that
are no longer relevant - on the other hand it tried to destroy a couple of
neatly formatted comments, so I had to add some as well.
2020-12-31 21:51:00 +01:00
Linus Groh a8ac8c6a8f AK: Add missing 'template' keywords in TypeList
This caused the AK build to be broken on OpenBSD (and possibly other
platforms / compiler versions).
Fixes #4692.
2020-12-31 16:16:07 +01:00
asynts a7c014125f AK: Add operator* and operator-> overloads in Optional. 2020-12-31 00:51:12 +01:00
Tom 34b3d92a13 AK: Fix some WeakPtr copy constructor variants not copying the link 2020-12-31 00:39:43 +01:00
Tom 54eeb8ee9a AK: Fix a race condition with WeakPtr<T>::strong_ref and destruction
Since RefPtr<T> decrements the ref counter to 0 and after that starts
destructing the object, there is a window where the ref count is 0
and the weak references have not been revoked.

Also change WeakLink to be able to obtain a strong reference
concurrently and block revoking instead, which should happen a lot
less often.

Fixes a problem observed in #4621
2020-12-31 00:39:43 +01:00
AnotherTest 6422a04cda AK+ProtocolServer: Properly close download stream fd's
This makes the issue of running out of openable pipes in the
ProtocolServer process much less likely (but still possible).
2020-12-30 20:37:41 +01:00
asynts 7e62ffbc6e AK+Format: Remove TypeErasedFormatParams& from format function. 2020-12-30 20:33:53 +01:00
AnotherTest 4e203f7e2d AK: Add {Input,Output}FileStream
Unlike the ones in LibCore, these only wrap an stdio FILE* (or an fd,
which they close when destroyed).
2020-12-30 13:31:55 +01:00
AnotherTest bf7cda414f AK: Add a ByteBuffer::copy(ReadonlyBytes) overload 2020-12-30 13:31:55 +01:00
Andrew Kaster 7d49ea9836 AK: Replace some SFINAE with requires clauses, clean up existing ones
Add requires clauses to constraints on InputStream and OutputStream
operator<< / operator>>. Make the constraint on String::number a
requires clause instead of SFINAE. Also, fix some unecessary IsSame in
Trie where specialized traits exist for the given use cases.
2020-12-30 13:28:49 +01:00
Andrew Kaster 0c51778510 AK: Move String::number entirely to header file
Use SFINAE to enforce the fact that it's supposed to only be called for
Arithmetic types, rather than counting on the linker to tell us that an
instantiation of String::number(my_arg) was not found. This also adds
String::number for floating point types as a side-effect.
2020-12-30 11:32:20 +01:00
Andrew Kaster b4eb734204 AK: Add tests for type traits and IndexSequence
Use TypeLists to add test for IsIntegral, IsFloatingPoint, IsVoid,
IsNullPointer, IsArithmetic, IsFundamental, and AddConst type traits.

More can "easily" be added once the TypeList and macro magic is squinted
at for long enough :).
2020-12-30 11:32:20 +01:00
Andrew Kaster 3bf77f01a7 AK: Add a TypeList class for expanded compile-time tools
Also add IndexSequence and associated helpers. The TypeList class can be
queried for what type is at a certain index, and there are two helper
functions: for_each_type, and for_each_type_zipped.

for_each_type will invoke a lambda with a TypeWrapper object for
each type in the type list. The original type can be obtained by
extracting the ::Type from the type of your generic lambda's one
argument.

for_each_type_zipped will walk two TypeLists in lockstep and pass a
TypeWrapper object for the current index in each list to a generic
lambda. The original type from the TypeList can again be extracted via
the ::Type of the generic lambda's two parameters.
2020-12-30 11:32:20 +01:00
Andrew Kaster fe4b44b489 AK: Add IsArithmetic and IsFundamental type traits
Also, make sure to using AK::IsNullPointer
2020-12-30 11:32:20 +01:00
Andrew Kaster 874df07ffd AK: Correct name in TestMain for TestTrie
Copy paste error :)
2020-12-30 11:32:20 +01:00
Andrew Kaster 06b6f838d6 AK: Use MacOS pthread_get_stacksize_np to get stack size for StackInfo
Seems Rust and OpenJDK both had issues with getting accurate stack size
for the main thread with MacOS Maverick and above. Apply a variant of
their workarounds. We could probably assume 8MB in all cases just to
be safe, as the only user of AK::StackInfo right now is lib JS's heap
for determining possible pointer candidates. But, this approach should
work if userspace apps start trying to add custom guard pages, as well.
2020-12-30 11:28:50 +01:00
asynts 50d24e4f98 AK: Make binary_search signature more generic. 2020-12-30 02:13:30 +01:00
Linus Groh 1ed72cc580 AK: Add HashMap(std::initializer_list<Entry>) constructor
This allows us to construct a HashMap from an initializer list like so:

    HashMap<K, V> hash_map = { { K, V }, { K, V } { K, V } };
2020-12-29 15:22:15 +01:00
asynts 620b73b3d5 AK+Format: Accept unsigned long in replacement fields.
I ran into this exact but at least twenty times in Serenity alone. The
C++ Standard dictates that 'unsigned long' and 'unsigned long long' are
distinct types even though on most platforms they are usually both 64
bit integers.

Also it wasn't possible to evaluate IsIntegral<T> for types that were
not integers since it used MakeUnsigned<T> internally.
2020-12-29 02:36:32 +01:00
AnotherTest cbe0a8b403 AK: Allow trailing '*'s in a glob pattern to match nothing
Fixes part of #4607.
2020-12-29 02:35:52 +01:00
Andreas Kling 13594b7146 LibGfx+AK: Make text elision work with multi-byte characters
This was causing WindowServer and Taskbar to crash sometimes when the
stars aligned and we tried cutting off a string ending with "..." right
on top of an emoji. :^)
2020-12-28 23:54:10 +01:00
Andrew Kaster 8ce7df73fb AK: Enable AK::SharedBuffer for all platforms
A future patch could do some MacOS specific things for
set_volatile/set_nonvolatile. For now, swap out the defined(__linux__)
branches for simple not __serenity__ branches.
2020-12-28 19:35:32 +01:00
Andrew Kaster 02fcf3974e AK/Userland: Use AK/Endian.h for portable byte swapping in ntpquery
Create macros for the byte swap operations one would expect to be in
endian.h or byteswap.h in AK/Endian.h. It's likely a similar/different
change will be needed for BSDs, but there's no github action for those
added to the project yet.
2020-12-28 19:35:32 +01:00
Andrew Kaster 1219c65249 AK: Add CLOCK_*_COARSE aliases for darwin and BSD variants
The coarse clocks in time.h are a linux extension that we've adopted.
MacOS and the BSDs don't have it, so we need an alias in a platform
header for Lagom builds.
2020-12-28 19:35:32 +01:00
Andreas Kling 20e2700952 Kernel: Allow Userspace<T> pointers with invalid content
It's not an error to create a Userspace<T> that points to kernel memory
as the point of Userspace<T> is not to validate the address, but rather
to choose safe overloads that do validation before any data transfer
takes place.

Fixes #4581.
2020-12-27 23:43:15 +01:00
Nathan Lanza d1891f67ac
AK: Use direct-list-initialization for Vector::empend() (#4564)
clang trunk with -std=c++20 doesn't seem to properly look for an
aggregate initializer here when the type being constructed is a simple
aggregate (e.g. `struct Thing { int a; int b; };`). This template fails
to compile in a usage added 12/16/2020 in `AK/Trie.h`.

Both forms of initialization are supposed to call the
aggregate-initializers but direct-list-initialization delegating to
aggregate initializers is a new addition in c++20 that might not be
implemented yet.
2020-12-27 23:06:37 +01:00
Stephan Unverwerth d3524f47a0 LibJS: Implement (mostly) spec compliant version of Number.toString() 2020-12-27 23:04:09 +01:00
Brian Gianforcaro 21a5524d01 AK: Add NO_DISCARD macro to allow clang-format friendly class annotations
clang-format seems to barf on these attributes, to make it easier to
use these attributes and have clang-format not mangle the following code
we can hide them behind a macro so clang-format doesn't have to handle it.
2020-12-27 11:09:30 +01:00
AnotherTest 1c9d28d212 AK: Fix busted Trie test
This wasn't testing anything ^^'
2020-12-26 12:32:27 +01:00
AnotherTest ad646420dd AK: Make AK::IsSame<T, U>::value a constexpr bool
It being an enum value was preventing it from being used without `!!` in
requires clauses (bool also makes more sense anyway).
2020-12-26 12:32:27 +01:00
AnotherTest cb3348191b AK: Add a prefix tree implementation
`AK::Trie` can be keyed by any given hashable type, and can store any
metadata (including nothing at all).
Also adds a test.
2020-12-26 11:54:54 +01:00
Lenny Maiorani b2316701a8 Everywhere: void arguments to C functions
Problem:
- C functions with no arguments require a single `void` in the argument list.

Solution:
- Put the `void` in the argument list of functions in C header files.
2020-12-26 10:10:27 +01:00
Sahan Fernando 6b01d1cf14 LibC: Enable compiler warnings for printf format strings 2020-12-26 10:05:50 +01:00
Andreas Kling ed5c26d698 AK: Remove custom %w format string specifier
This was a non-standard specifier alias for %04x. This patch replaces
all uses of it with new-style formatting functions instead.
2020-12-25 17:05:05 +01:00
Andreas Kling cb2c8f71f4 AK: Remove custom %b format string specifier
This was a non-standard specifier alias for %02x. This patch replaces
all uses of it with new-style formatting functions instead.
2020-12-25 17:04:28 +01:00
Lenny Maiorani e4ce485309 CMake: Decouple cmake utility functions from top-level CMakeLists.txt
Problem:
- These utility functions are only used in `AK`, but are being defined
  in the top-level. This clutters the top-level.

Solution:
- Move the utility functions to `Meta/CMake/utils.cmake` and include
  where needed.
- Also, move `all_the_debug_macros.cmake` into `Meta/CMake` directory
  to consolidate the location of `*.cmake` script files.
2020-12-24 11:02:04 +01:00
Lenny Maiorani 8e1af483be CMake: Remove file globbing in AK/Tests
Problem:
- File globbing is performed at the time of build system
  generation. Any files which are not there at that time are not
  included. So, when a new file is added it is not built unless the
  build system is recreated.

Solution:
- Remove globbing from AK/Tests directory in favor of explicitly
  listing the files.
2020-12-23 20:51:29 +01:00
Andreas Kling eaa63fdda5 Kernel: Don't assert on PT_PEEK with kernelspace address
We were casting the address to Userspace<T> without validating it first
which is no good and will trap an assertion soon after.

Let's catch this sooner with an ASSERT in the Userspace<T> constructor
and update the PT_PEEK and PT_POKE handlers to avoid it.

Fixes #4505.
2020-12-23 14:50:20 +01:00
Sahan Fernando b37139e111 AK: Make JsonParser::parse_number properly parse >32bit ints 2020-12-21 00:15:44 +01:00
Sahan Fernando 1a12f964d4 AK: Test StringUtils::convert_to_int for different types 2020-12-21 00:15:44 +01:00
Sahan Fernando f469f44cc6 AK: Check for overflow in StringUtils::convert_to_int 2020-12-21 00:15:44 +01:00
Sahan Fernando 37df4bbd90 AK: Generalize AK::String::to_int() for more types 2020-12-21 00:15:44 +01:00
Lenny Maiorani 765936ebae
Everywhere: Switch from (void) to [[maybe_unused]] (#4473)
Problem:
- `(void)` simply casts the expression to void. This is understood to
  indicate that it is ignored, but this is really a compiler trick to
  get the compiler to not generate a warning.

Solution:
- Use the `[[maybe_unused]]` attribute to indicate the value is unused.

Note:
- Functions taking a `(void)` argument list have also been changed to
  `()` because this is not needed and shows up in the same grep
  command.
2020-12-21 00:09:48 +01:00
Lenny Maiorani 4421d98e30 AllOf: Common iterator types
Problem:
- Interface is too permissive. It permits iterators of different types
  as long as they are comparable.

Solution:
- Require iterators be the same type.
2020-12-20 21:13:10 +01:00
asynts 72cbca892a AK: Remove bogus test case for CircularDuplexStream. 2020-12-19 23:29:40 +01:00
Andreas Kling 6b2a178a7f AK: Remove awkward ByteBuffer construction modes (wrap & adopt)
ByteBuffer previously had a flag that determined whether it owned the
bytes inside it or not (m_owned.) Owned ByteBuffers would free() on
destruction and non-owned ones would not.

This was a huge source of confusion and made it hard to reason about
lifetimes since there were no compile-time clues about whether a buffer
was owned or non-owned.

The adopt mode was used at some point to take over ownership of a
random malloc'ed buffer, but nothing was using it so this patch removes
that as well.
2020-12-19 18:29:13 +01:00
Andreas Kling 050eb5afa8 AK: Mark some Span functions with [[nodiscard]]
I was confused by the trim() API, thinking it would mutate the span it
was called on. Mark all const functions that return a new span with
[[nodiscard]] so we can catch such mistakes.
2020-12-19 18:29:13 +01:00
Andreas Kling f82b0a78ef LibTLS+LibCrypto: More ByteBuffer -> Span conversion 2020-12-19 18:29:13 +01:00
Andreas Kling 8e20208dd6 LibTLS+LibCrypto: Replace a whole bunch of ByteBuffers with Spans 2020-12-19 18:29:13 +01:00
Sahan Fernando fb9a71bd6a AK: Add hash implementations for i16 and i64 2020-12-19 10:20:15 +01:00
Itamar b4842d33bb Kernel: Generate a coredump file when a process crashes
When a process crashes, we generate a coredump file and write it in
/tmp/coredumps/.

The coredump file is an ELF file of type ET_CORE.
It contains a segment for every userspace memory region of the process,
and an additional PT_NOTE segment that contains the registers state for
each thread, and a additional data about memory regions
(e.g their name).
2020-12-14 23:05:53 +01:00
Conrad Pankoff a01d11ac19 AK: Add {encode,decode}_hex similar to {encode,decode}_base64 2020-12-13 11:00:20 +01:00
Conrad Pankoff 13f13a9e59 AK: Fix urlencode() with high byte values
Previously urlencode() would encode bytes above 127 incorrectly, printing
them as negative hex values.
2020-12-12 23:50:23 +01:00
xspager dd198e1a29 AK::URL: Fix setting the port number in the case it was the last element of the URL 2020-12-12 20:09:42 +01:00
Andreas Kling 5d0fda3d39 AK: Add String::substring(start)
This is a convenience API when you just want the rest of the string
starting at some index. We already had substring_view() in the same
flavor, so this is a complement to that.
2020-12-10 20:42:11 +01:00