Commit graph

1634 commits

Author SHA1 Message Date
Ali Mohammad Pur 02de813950 AK: Add a Tuple implementation
Please don't use this outside of metaprogramming needs, *please*.
2021-05-11 14:09:17 +01:00
Ali Mohammad Pur 4fdbac236d AK/Variant: Deduplicate the contained types
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-11 14:09:17 +01:00
Ali Mohammad Pur 3038b6b7dc AK: Avoid the use of typeinfo in Variant
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-11 14:09:17 +01:00
Matthew Olsson 8c745ad0d9 LibPDF: Parse page structures
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-10 10:32:39 +02:00
Matthew Olsson af9a7b1374 AK: Add missing 'const' in Span 2021-05-10 10:32:39 +02:00
Ali Mohammad Pur aa4d8d26b9 LibWasm: Start implementing a basic WebAssembly binary format parser
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-08 22:14:39 +02:00
Ali Mohammad Pur 56a6d7924e AK: Let Result<T, E> know its Value and Error types
It's much easier to ask for T::ValueType than for
RemoveReference<decltype(declval<T>().release_value())>
2021-05-08 22:14:39 +02:00
Ali Mohammad Pur 62af7c4bdf AK+LibCpp: Remove DEBUG_SPAM in favour of per-application defines
What happens if one file defines DEBUG_SPAM, and another doesn't,
then we link them together and get ODR violations? -- @ADKaster
2021-05-08 22:14:39 +02:00
Ali Mohammad Pur 080f2c0e3e AK: Add an optional 'extra' descriptive field to ScopeLogger
Often it's easier to know what the functions are doing with a unique
name next to the function's name :)
2021-05-08 22:14:39 +02:00
Itamar 8a01167c7d AK: Add missing GenericTraits<NonnullRefPtr>
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-08 18:10:56 +02:00
Itamar 1da0d402b7 AK: Add constructors to Optional that accept non const qualified inputs 2021-05-08 18:10:56 +02:00
Itamar 484823e9d5 AK: Add a non-const overload to HapMap::get()
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-08 18:10:56 +02:00
Itamar b816bd0806 AK: Add ConstPeekType to Traits
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-08 18:10:56 +02:00
Jesse Buhagiar 4807d32139 LibGL: Implement a basic OpenGL 1.x compatible library
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-08 10:13:22 +02:00
Stephan Unverwerth 0a557d65a0 AK: Add epsilon() to NumericLimits for float, double, long double 2021-05-08 10:13:22 +02:00
Andreas Kling 834b6508d7 AK: Remove StringBuilder::appendf()
All users have been converted to using AK::Format via appendff().
2021-05-07 21:12:09 +02:00
Valtteri Koskivuori 1069979ddf AK: Implement Span::starts_with()
Useful for checking for contents at the start of a span.
2021-05-07 11:46:53 +01:00
Ali Mohammad Pur da68c4580c AK: Make Checked<T> check for division overflow as well
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-07 09:26:11 +02:00
Brian Gianforcaro 67322b0702 Tests: Move AK tests to Tests/AK 2021-05-06 17:54:28 +02:00
AnotherTest ba6c9423b8 AK: Implement printf fraction length specification for strings
This adds support for '%.20s' and friends :^)
2021-05-06 15:20:31 +01:00
Ali Mohammad Pur a51113c58e AK: Add a Variant<Ts...> implementation
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-05 19:02:51 +02:00
Ali Mohammad Pur ab03c6fadf AK: Export integer_sequence_generate_array() 2021-05-05 19:02:51 +02:00
Ali Mohammad Pur b361793ad8 AK: Add min() and max() methods to Array<T, N>
...That are only defined when min() and max() are defined on the
elements.
2021-05-05 19:02:51 +02:00
Ali Mohammad Pur d288f6654e AK: Make LEB128 capable of reading into any type
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-04 22:33:35 +02:00
Ali Mohammad Pur 48260b5054 AK: Move the LEB128 logic to AK and make it usable with InputStream 2021-05-04 22:33:35 +02:00
Ali Mohammad Pur 415fd4d2ec AK: Make DistinctNumeric constexpr-capable 2021-05-04 21:32:15 +02:00
Gunnar Beutner 56ee4a1af2 AK: Silence -Wmaybe-uninitialized warning
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-03 08:42:39 +02:00
Tobias Christiansen 4016e04061 AK: Move bijective-base-conversion into AK/String
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-05-01 01:19:40 +02:00
Gunnar Beutner ad688ffc73 AK: Make dbgln log the thread ID
This makes debugging multi-threaded programs easier.
2021-04-29 23:12:05 +02:00
Andreas Kling 3d4afe7614 Everywhere: "indexes" => "indices"
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-29 22:23:52 +02:00
Andreas Kling 7ae7170d61 Everywhere: "file name" => "filename" 2021-04-29 22:16:18 +02:00
Sahan Fernando c3cf739b94 AK: Make AK::Vector expose allocation failures in API 2021-04-29 09:02:58 +02:00
Linus Groh 649d2faeab Everywhere: Use "the SerenityOS developers." in copyright headers
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-29 00:59:26 +02:00
Mart G c9f3cc6dcc AK: Guarantee a maximum stack depth for dual_pivot_quick_sort
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-28 21:38:48 +02:00
Mart G 67b0d04315 AK: Change pivot selection of dual_pivot_quick_sort
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-28 21:38:48 +02:00
Jean-Baptiste Boric 7d84f09e7e Userland: Move non-standard math constants from math.h 2021-04-27 23:06:16 +02:00
Gunnar Beutner f57c57966b AK: Fix argument type for JsonArray::at and JsonArray::operator[] 2021-04-26 17:13:55 +02:00
Linus Groh dbe72fd962 Everywhere: Remove empty line after function body opening curly brace 2021-04-25 20:20:00 +02:00
sin-ack bb096429ad Tests: Remove 4chan catalog JSON from tree
According to kling, it was "an early stress test for the JSON decoder"
and can be removed now.
2021-04-25 10:15:15 +02:00
Brian Gianforcaro 87724b3d09 AK: Add default constructor to SourceLocation 2021-04-25 09:38:27 +02:00
Andrew Kaster 35c0a6c54d AK+Userland: Move AK/TestSuite.h into LibTest and rework Tests' CMake
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-25 09:36:49 +02:00
Andrew Kaster 89ee38fe5c Tests: Add environment variable for tests only
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-25 09:36:49 +02:00
Brian Gianforcaro 7a73f11005 LibCpp: Convert ScopeLogger to use AK:SourceLocation
Utilize AK::SourceLocation to get function information into
the scope logger, instead of relying on pre-processor macros.
2021-04-25 09:32:03 +02:00
Brian Gianforcaro 357a13b404 AK: Add a AK::Formatter implementation for AK::SourceLocation 2021-04-25 09:32:03 +02:00
Brian Gianforcaro 0ad29bc3c9 AK: Add SourceLocation support
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-24 20:33:00 +02:00
Andreas Kling b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Idan Horowitz f90c224fc5 Revert "AK: Remove virtual destructors from non-virtual classes"
This reverts commit 4378d36f67.
2021-04-23 10:26:14 +02:00
Lenny Maiorani 4378d36f67 AK: Remove virtual destructors from non-virtual classes
Problem:
- Some classes have `virtual` destructors despite not having any
  virtual functions. This causes the classes to have a v-table and
  perform extra jumps at destruction time when there is no need.

Solution:
- Remove `virtual` keyword from destructors where there are no other
  virtual functions.
- Remove the destructor completely when the default destructor can be
  used.
2021-04-23 08:28:25 +02:00
Idan Horowitz 1c512a702a AK+Userland: Use idan.horowitz@serenityos.org for my copyright headers 2021-04-22 22:42:38 +02:00
Ali Mohammad Pur 38418fdfdf AK+Userland: Use mpfard@serenityos.org for my copyright headers 2021-04-22 22:19:09 +02:00