summaryrefslogtreecommitdiff
path: root/AK
AgeCommit message (Collapse)Author
2021-05-13AK: Introduce adopt_ref_if_nonnull(..) to aid in Kernel OOM hardeningBrian Gianforcaro
Unfortunately adopt_ref requires a reference, which obviously does not work well with when attempting to harden against allocation failure. The adopt_ref_if_nonnull() variant will allow you to avoid using bare pointers, while still allowing you to handle allocation failure.
2021-05-13AK: Introduce adopt_own_if_nonnull(..) to aid in Kernel OOM hardeningBrian Gianforcaro
Unfortunately adopt_own requires a reference, which obviously does not work well with when attempting to harden against allocation failure. The adopt_own_if_nonnull() variant will allow you to avoid using bare pointers, while still allowing you to handle allocation failure.
2021-05-12AK: Add LexicalPath::append and LexicalPath::joinsin-ack
This patch adds two new methods to LexicalPath. LexicalPath::append appends a new path component to a LexicalPath, and LexicalPath::join constructs a new LexicalPath from one or more components. Co-authored-by: Gunnar Beutner <gunnar@beutner.name>
2021-05-12Kernel+LibC: Make get_dir_entries syscall retriableMart G
The get_dir_entries syscall failed if the serialized form of all the directory entries together was too large to fit in its temporary buffer. Now the kernel uses a fixed size buffer, that is flushed to an output buffer when it is full. If this flushing operation fails because there is not enough space available, the syscall will return -EINVAL. That error code is then used in userspace as a signal to allocate a larger buffer and retry the syscall.
2021-05-11AK: Add a Tuple implementationAli Mohammad Pur
Please don't use this outside of metaprogramming needs, *please*.
2021-05-11AK/Variant: Deduplicate the contained typesAli Mohammad Pur
This allows the construction of `Variant<int, int, int>`. While this might not seem useful, it is very useful for making variants that contain a series of member function pointers, which I plan to use in LibGL for glGenLists() and co.
2021-05-11AK: Avoid the use of typeinfo in VariantAli Mohammad Pur
typeid() and RTTI was a nice clutch to implement this, but let's move away from the horrible slowness and implement variants using type indices for faster variants.
2021-05-10LibPDF: Parse page structuresMatthew Olsson
This commit introduces the ability to parse the document catalog dict, as well as the page tree and individual pages. Pages obviously aren't fully parsed, as we won't care about most of the fields until we start actually rendering PDFs. One of the primary benefits of the PDF format is laziness. PDFs are not meant to be parsed all at once, and the same is true for pages. When a Document is constructed, it builds a map of page number to object index, but it does not fetch and parse any of the pages. A page is only parsed when a caller requests that particular page (and is cached going forwards). Additionally, this commit also adds an object_cast function which logs bad casts if DEBUG_PDF is set. Additionally, utility functions were added to ArrayObject and DictObject to get all types of objects from the collections to avoid having to manually cast.
2021-05-10AK: Add missing 'const' in SpanMatthew Olsson
2021-05-08LibWasm: Start implementing a basic WebAssembly binary format parserAli Mohammad Pur
This can currently parse a really simple module. Note that it cannot parse the DataCount section, and it's still missing almost all of the instructions. This commit also adds a 'wasm' test utility that tries to parse a given webassembly binary file. It currently does nothing but exit when the parse fails, but it's a start :^)
2021-05-08AK: Let Result<T, E> know its Value and Error typesAli Mohammad Pur
It's much easier to ask for T::ValueType than for RemoveReference<decltype(declval<T>().release_value())>
2021-05-08AK+LibCpp: Remove DEBUG_SPAM in favour of per-application definesAli Mohammad Pur
What happens if one file defines DEBUG_SPAM, and another doesn't, then we link them together and get ODR violations? -- @ADKaster
2021-05-08AK: Add an optional 'extra' descriptive field to ScopeLoggerAli Mohammad Pur
Often it's easier to know what the functions are doing with a unique name next to the function's name :)
2021-05-08AK: Add missing GenericTraits<NonnullRefPtr>Itamar
This enables us to use keys of type NonnullRefPtr in HashMaps and HashTables. This commit also includes fixes in various places that used HashMap<T, NonnullRefPtr<U>>::get() and expected to get an Optional<NonnullRefPtr<U>> and now get an Optional<U*>.
2021-05-08AK: Add constructors to Optional that accept non const qualified inputsItamar
2021-05-08AK: Add a non-const overload to HapMap::get()Itamar
Additionally, the const version of get() returns Optional<ConstPeekType> for smart pointers. For example, if the value in the HashMap is OwnPtr<u32>, HashMap::get() const returns Optional<const u32*>.
2021-05-08AK: Add ConstPeekType to TraitsItamar
Also, the PeekType of smart pointers is now T* instead of const T*. Note: This commit doesn't compile, it breaks HashMap::get() for some types. Fixed in the next commit.
2021-05-08LibGL: Implement a basic OpenGL 1.x compatible libraryJesse Buhagiar
This currently (obviously) doesn't support any actual 3D hardware, hence all calls are done via software rendering. Note that any modern constructs such as shaders are unsupported, as this driver only implements Fixed Function Pipeline functionality. The library is split into a base GLContext interface and a software based renderer implementation of said interface. The global glXXX functions serve as an OpenGL compatible c-style interface to the currently bound context instance. Co-authored-by: Stephan Unverwerth <s.unverwerth@gmx.de>
2021-05-08AK: Add epsilon() to NumericLimits for float, double, long doubleStephan Unverwerth
2021-05-07AK: Remove StringBuilder::appendf()Andreas Kling
All users have been converted to using AK::Format via appendff().
2021-05-07AK: Implement Span::starts_with()Valtteri Koskivuori
Useful for checking for contents at the start of a span.
2021-05-07AK: Make Checked<T> check for division overflow as wellAli Mohammad Pur
Signed integer overflow can occur with division when the RHS is -1, as the negative values' range is one larger than the positives.
2021-05-06Tests: Move AK tests to Tests/AKBrian Gianforcaro
2021-05-06AK: Implement printf fraction length specification for stringsAnotherTest
This adds support for '%.20s' and friends :^)
2021-05-05AK: Add a Variant<Ts...> implementationAli Mohammad Pur
Also adds an AK::Empty struct, because 'empty' variants are useful, but this implementation leaves that to the user (i.e. a variant cannot actually be empty, but it can contain an instance of Empty - i.e. a byte). Note that this is more of a constrained Any type, but they basically do the same things anyway :^)
2021-05-05AK: Export integer_sequence_generate_array()Ali Mohammad Pur
2021-05-05AK: Add min() and max() methods to Array<T, N>Ali Mohammad Pur
...That are only defined when min() and max() are defined on the elements.
2021-05-04AK: Make LEB128 capable of reading into any typeAli Mohammad Pur
And not just ssize_t/size_t. This is useful in cases where the output size is supposed to be larger than size_t.
2021-05-04AK: Move the LEB128 logic to AK and make it usable with InputStreamAli Mohammad Pur
2021-05-04AK: Make DistinctNumeric constexpr-capableAli Mohammad Pur
2021-05-03AK: Silence -Wmaybe-uninitialized warningGunnar Beutner
Adding -fno-semantic-interposition to the GCC command line caused this new warning. I don't see how output.data() could be uninitialized here. Also, commenting out the ensure_capacity() call for the Vector also gets rid of this warning.
2021-05-01AK: Move bijective-base-conversion into AK/StringTobias Christiansen
This allows everybody to create a String version of their number in a arbitrary bijective base. Bijective base meaning that the mapping doesn't have a 0. In the usual mapping to the alphabet the follower after 'Z' is 'AA'. The mapping using the (uppercase) alphabet is used as a standard but can be overridden specifying 'base' and 'map'. The code was directly yanked from the Spreadsheet.
2021-04-29AK: Make dbgln log the thread IDGunnar Beutner
This makes debugging multi-threaded programs easier.
2021-04-29Everywhere: "indexes" => "indices"Andreas Kling
I've wasted a silly amount of time in the past fretting over which of these words to use. Let's just choose one and use it everywhere. :^)
2021-04-29Everywhere: "file name" => "filename"Andreas Kling
2021-04-29AK: Make AK::Vector expose allocation failures in APISahan Fernando
2021-04-29Everywhere: Use "the SerenityOS developers." in copyright headersLinus Groh
We had some inconsistencies before: - Sometimes "The", sometimes "the" - Sometimes trailing ".", sometimes no trailing "." I picked the most common one (lowecase "the", trailing ".") and applied it to all copyright headers. By using the exact same string everywhere we can ensure nothing gets missed during a global search (and replace), and that these inconsistencies are not spread any further (as copyright headers are commonly copied to new files).
2021-04-28AK: Guarantee a maximum stack depth for dual_pivot_quick_sortMart G
When the two chosen pivots happen to be the smallest and largest elements of the array, three partitions will be created, two of size 0 and one of size n-2. If this happens on each recursive call to dual_pivot_quick_sort, the stack depth will reach approximately n/2. To avoid the stack from deepening, iteration can be used for the largest of the three partitions. This ensures the stack depth will only increase for partitions of size n/2 or smaller, which results in a maximum stack depth of log(n).
2021-04-28AK: Change pivot selection of dual_pivot_quick_sortMart G
Picking the first and last elements as pivots makes it so that a sorted array is the worst-case input for the algorithm. This change instead picks pivots at approximately 1/3 and 2/3 in the array. This results in desired performance for sorted arrays. Of course this only changes which inputs result in worst-case performance, but hopefully those inputs occur less frequently than already sorted arrays.
2021-04-27Userland: Move non-standard math constants from math.hJean-Baptiste Boric
2021-04-26AK: Fix argument type for JsonArray::at and JsonArray::operator[]Gunnar Beutner
2021-04-25Everywhere: Remove empty line after function body opening curly braceLinus Groh
2021-04-25Tests: Remove 4chan catalog JSON from treesin-ack
According to kling, it was "an early stress test for the JSON decoder" and can be removed now.
2021-04-25AK: Add default constructor to SourceLocationBrian Gianforcaro
2021-04-25AK+Userland: Move AK/TestSuite.h into LibTest and rework Tests' CMakeAndrew Kaster
As many macros as possible are moved to Macros.h, while the macros to create a test case are moved to TestCase.h. TestCase is now the only user-facing header for creating a test case. TestSuite and its helpers have moved into a .cpp file. Instead of requiring a TEST_MAIN macro to be instantiated into the test file, a TestMain.cpp file is provided instead that will be linked against each test. This has the side effect that, if we wanted to have test cases split across multiple files, it's as simple as adding them all to the same executable. The test main should be portable to kernel mode as well, so if there's a set of tests that should be run in self-test mode in kernel space, we can accomodate that. A new serenity_test CMake function streamlines adding a new test with arguments for the test source file, subdirectory under /usr/Tests to install the test application and an optional list of libraries to link against the test application. To accomodate future test where the provided TestMain.cpp is not suitable (e.g. test-js), a CUSTOM_MAIN parameter can be passed to the function to not link against the boilerplate main function.
2021-04-25Tests: Add environment variable for tests onlyAndrew Kaster
This is useful for CI where we don't want to spend a minute and a half benchmarking Vector::append, and we don't have a good way to pass test-specific arguments yet. :)
2021-04-25LibCpp: Convert ScopeLogger to use AK:SourceLocationBrian Gianforcaro
Utilize AK::SourceLocation to get function information into the scope logger, instead of relying on pre-processor macros.
2021-04-25AK: Add a AK::Formatter implementation for AK::SourceLocationBrian Gianforcaro
2021-04-24AK: Add SourceLocation supportBrian Gianforcaro
C++20 added std::source_location, which lets you capture the callers __FILE__ / __LINE__ / __FUNCTION__ etc as a default argument to functions. See: https://en.cppreference.com/w/cpp/utility/source_location During a bug investigation @ADKaster suggested we could use this to make the LOCK_DEBUG feature of the kernel more user friendly and allow it to automatically instrument all call sites. We then implemented / tested it over discord. :^) Co-Authored-by: Andrew Kaster <andrewdkaster@gmail.com>
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.)