summaryrefslogtreecommitdiff
path: root/AK/ByteBuffer.h
AgeCommit message (Collapse)Author
2021-11-14AK: Resolve clang-tidy readability-qualified-auto warningsAndrew Kaster
... In files included by Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-14AK: Resolve clang-tidy readability-bool-conversion warningsAndrew Kaster
... In files included by Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-11Everywhere: Pass AK::ReadonlyBytes by valueAndreas Kling
2021-11-10AK: Make ByteBuffer::try_* functions return ErrorOr<void>Andreas Kling
Same as Vector, ByteBuffer now also signals allocation failure by returning an ENOMEM Error instead of a bool, allowing us to use the TRY() and MUST() patterns.
2021-09-06Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safeAli Mohammad Pur
2021-09-06AK: Add OOM-safe ByteBuffer::try_{resize,append,ensure_capacity}() APIsAli Mohammad Pur
2021-07-11AK: Don't forget to kfree_sized() in ByteBufferAndreas Kling
2021-07-11AK: Don't use realloc() in AK::ByteBufferAndreas Kling
This class is the only reason we have to support krealloc() in the kernel heap, something which adds a lot of complexity. Let's move towards a simpler path and do malloc+memset in the ByteBuffer code (where we know the sizes anyway.)
2021-07-11AK: Use kfree_sized() in AK::ByteBufferAndreas Kling
2021-06-12AK: Add ByteBuffer::append(ReadonlyBytes)Matthew Olsson
2021-06-08LibC+AK: Remove our custom macros from <assert.h>Gunnar Beutner
Other software might not expect these to be defined and behave differently if they _are_ defined, e.g. scummvm which checks if the TODO macro is defined and fails to build if it is.
2021-05-31AK: Split the ByteBuffer::trim method into two methodsGunnar Beutner
This allows us to mark the slow part (i.e. where we copy the buffer) as NEVER_INLINE because this should almost never get called and therefore should also not get inlined into callers.
2021-05-31AK: Remove the public ByteBuffer::trim methodGunnar Beutner
This removes the public trim() method because it is no longer necessary. Callers can instead use resize().
2021-05-31AK: Replace ByteBuffer::grow with resize()/ensure_capacity()Gunnar Beutner
Previously ByteBuffer::grow() behaved like Vector<T>::resize(). However the function name was somewhat ambiguous - and so this patch updates ByteBuffer to behave more like Vector<T> by replacing grow() with resize() and adding an ensure_capacity() method. This also lets the user change the buffer's capacity without affecting the size which was not previously possible. Additionally this patch makes the capacity() method public (again).
2021-05-30Revert "AK: Fix accidentally-quadratic behavior in StringBuilder"Ben Wiederhake
This reverts commit 2d011961c94ac81700c366537f52208a4c55db92.
2021-05-30AK: Fix accidentally-quadratic behavior in StringBuilderBen Wiederhake
Found by OSS Fuzz: #34451 (old bug) Related commit: 3908a49661a00e15621748dcb2b0424f29433571
2021-05-27AK: Convince GCC that m_outline_capacity isn't being readGunnar Beutner
Previously GCC came to the conclusion that we were reading m_outline_capacity via ByteBuffer(ByteBuffer const&) -> grow() -> capacity() even though that could never be the case because m_size is 0 at that point which means we have an inline buffer and capacity() would return inline_capacity in that case without reading m_outline_capacity. This makes GCC inline parts of the grow() function into the ByteBuffer copy constructor which seems sufficient for GCC to realize that m_outline_capacity isn't actually being read.
2021-05-27AK: Explicitly initialize buffer member in ByteBufferAndrew Kaster
When compiling the Kernel with Og, the compiler complains that m_outline_capacity might be uninitialized when calling capacity() Note that this fix is not really what we want. Ideally only outline buffer and outline capacity would need initialized, not the entire inline buffer. However, clang considers the class to not be default-constructible if we make that change, while gcc accepts it.
2021-05-16AK: Don't call memcpy with null argument in ByteBuffer::copy()Andrew Kaster
This was happening in TestBase64.test_decode, while copying an empty string.
2021-05-16AK+Userland: Remove nullability feature for the ByteBuffer typeGunnar Beutner
Nobody seems to use this particular feature, in fact there were some bugs which were uncovered by removing operator bool.
2021-05-16AK: Turn ByteBuffer into a value typeGunnar Beutner
Previously ByteBuffer would internally hold a RefPtr to the byte buffer and would behave like a reference type, i.e. copying a ByteBuffer would not create a duplicate byte buffer, but rather two objects which refer to the same internal buffer. This also changes ByteBuffer so that it has some internal capacity much like the Vector<T> type. Unlike Vector<T> however a byte buffer's data may be uninitialized. With this commit ByteBuffer makes use of the kmalloc_good_size() API to pick an optimal allocation size for its internal buffer.
2021-05-14AK: Avoid allocations in ByteBufferGunnar Beutner
Creating a ByteBuffer involves two allocations: -One for the ByteBufferImpl object -Another one for the actual byte buffer This changes the ByteBuffer and ByteBufferImpl classes so only one allocation is necessary.
2021-05-14AK: Avoid passing nullptr to __buitin_memcpy() in ByteBuffer::grow()Ali Mohammad Pur
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-21AK: Decorate most of ByteBuffer with [[nodiscard]]Andreas Kling
2021-03-15AK: Make ByteBuffer::slice(0, size()) a freebieAndreas Kling
If you want the whole buffer, we can just give you the buffer itself.
2021-03-12Everywhere: Remove klog(), dbg() and purge all LogStream usage :^)Andreas Kling
Good-bye LogStream. Long live AK::Format!
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-21AK: Add safe memset() wrapper to ByteBufferBrian Gianforcaro
In the interest memory safety and of removing as many of foot guns as possible (like raw memset's which are notorious for typo's), a zeroing method seems like a useful utility to have on a buffer class.
2021-02-08Everywhere: Remove unnecessary headers 3/4Ben Wiederhake
Arbitrarily split up to make git bisect easier. These unnecessary #include's were found by combining an automated tool (which determined likely candidates) and some brain power (which decided whether the #include is also semantically superfluous).
2021-01-12AK: Simplify constructors and conversions from nullptr_tLenny Maiorani
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-02AK: Remove redundant compare() functions.asynts
2020-12-30AK: Add a ByteBuffer::copy(ReadonlyBytes) overloadAnotherTest
2020-12-19AK: Remove awkward ByteBuffer construction modes (wrap & adopt)Andreas Kling
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-14Kernel: Generate a coredump file when a process crashesItamar
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-08-30AK: Fix ByteBuffer zero bytes allocationsTom
2020-08-22AK: Prevent confusing silent misuse of ByteBufferBen Wiederhake
Thankfully, this hasn't happened in any other code yet, but it happened while I was trying something out. Using '==' on two ByteBuffers to check whether they're equal seemed straight-forward, so I ran into the trap.
2020-08-15AK: Rename span() to bytes() when appropriate.asynts
I originally defined the bytes() method for the String class, because it made it obvious that it's a span of bytes instead of span of characters. This commit makes this more consistent by defining a bytes() method when the type of the span is known to be u8. Additionaly, the cast operator to Bytes is overloaded for ByteBuffer and such.
2020-08-06Refactor: Expose const_cast by removing ByteBuffer::warp(const void*, size_t)asynts
This function did a const_cast internally which made the call side look "safe". This method is removed completely and call sites are replaced with ByteBuffer::wrap(const_cast<void*>(data), size) which makes the behaviour obvious.
2020-07-27AK: Add span() / bytes() methods to container types.asynts
2020-07-03AK: Serialize entire log statementsTom
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-05-02AK: Correct ByteBuffer::{overwrite,slice*} bounds checkAnotherTest
2020-04-08AK: Appending 0 bytes to a ByteBuffer should be a no-op (#1699)Paul Redmond
- inserting an empty string into LibLine Editor triggered an assertion trying to grow a ByteBuffer by 0 bytes.
2020-04-03AK: Add an overwrite API to ByteBufferAnotherTest
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-03-08AK: Use __builtin_memset() and such to reduce header dependenciesAndreas Kling
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-02-20AK: Use size_t for ByteBuffer sizesAndreas Kling
This matches what we already do for string types.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-09-30ByteBuffer: Remove pointer() in favor of data()Andreas Kling
We had two ways to get the data inside a ByteBuffer. That was silly.
2019-09-11AK: Add LogStream operator<< for ByteBufferAndreas Kling