Commit graph

1022 commits

Author SHA1 Message Date
Nico Weber 064159d215 LibWeb: Use GenericLexer in WrapperGenerator 2020-08-21 16:01:48 +02:00
AnotherTest 9cc996b1e5 AK: Add Stream::offset_of(ReadonlyBytes) 2020-08-21 16:00:42 +02:00
AnotherTest 67f7f6840d AK+LibC+Kernel: Move the implementation of memmem to AK 2020-08-21 16:00:42 +02:00
asynts 8bbb7e25e6 LibCompress: Turn the DEFLATE implementation into a stream.
Previously, the implementation would produce one Vector<u8> which
would contain the whole decompressed data. That can be a lot and
even exhaust memory.

With these changes it is still necessary to store the whole input data
in one piece (I am working on this next,) but the output can be read
block by block. (That's not optimal either because blocks can be
arbitrarily large, but it's good for now.)
2020-08-20 16:28:31 +02:00
asynts 30abadcff9 AK: Add DuplexMemoryStream class.
This class is similar to BufferStream because it is possible to both
read and write to it. However, it differs in the following ways:

  - DuplexMemoryStream keeps a history of 64KiB and discards the rest,
    BufferStream always keeps everything around.

  - DuplexMemoryStream tracks reading and writing seperately, the
    following is valid:

        DuplexMemoryStream stream;
        stream << 42;
        int value;
        stream >> value;

    For BufferStream it would read:

        BufferStream stream;
        stream << 42;
        int value;
        stream.seek(0);
        stream >> value;

In the future I would like to replace all usages of BufferStream with
InputMemoryStream, OutputMemoryStream (doesn't exist yet) and
DuplexMemoryStream. For now I just add DuplexMemoryStream though.
2020-08-20 16:28:31 +02:00
asynts a15556638d AK: Remove unnecessary FIXME comments from Stream.h. 2020-08-20 16:28:31 +02:00
asynts bc332aca33 AK: Rename error() to has_error() for streams. 2020-08-20 16:28:31 +02:00
asynts 6d15318560 AK: Remove fatal() from InputStream.
Fatal errors can not be handeled and lead to an assertion error when the
stream is destroyed. It makes no sense to delay the assertion failure,
instead of setting m_fatal, an assertion should be done directly.
2020-08-20 16:28:31 +02:00
asynts 31e7f435cb AK: Rename TestMemoryStream.cpp to TestStream.cpp. 2020-08-20 16:28:31 +02:00
asynts ebce4ead40 AK: Add StringView(ReadonlyBytes) constructor. 2020-08-20 16:28:31 +02:00
asynts b1fc8d2b38 AK: Span: Fix signature of copy_to() and copy_trimmed_to().
Two changes were made

 1. copy_to() and copy_trimmed_to() now return how many bytes were
    copied.

 2. The argument was changed to Span<typename RemoveConst<T>::Type>
    because the following would not work:

        ReadonlyBytes bytes0;
        Bytes bytes1;

        // Won't work because this calls Span<const u8>::copy_to(Span<u8>)
        // but the method was defined as Span<const u8>::copy_to(Span<const u8>)
        bytes0.copy_to(bytes1);
2020-08-20 16:28:31 +02:00
asynts df21487794 AK: Span: Allow slicing with zero length.
Previously, the following would not work:

    Bytes{}.slice(0);

because it was asserted that `start < size()`.
2020-08-20 16:28:31 +02:00
Brian Gianforcaro ff0c7da75d AK: Add SFINAE fallback for AK C++ concepts use, for Coverity compiler
The Coverity compiler doesn't support C++2a yet, and thus doesn't
even recognize concept keywords. To allow serenity to be built and
analyzed on such compilers, add a fallback underdef to perform
the same template restriction based on AK::EnableIf<..> meta
programming.

Note: Coverity does seem to (annoyingly) define __cpp_concepts, even
though it doesn't support them, so we need to further check for
__COVERITY__ explicitly.
2020-08-17 09:17:57 +02:00
asynts aef6f00195 AK: Always call memmove in Span instead of memcpy.
https://github.com/SerenityOS/serenity/pull/3166#discussion_r471031704
2020-08-17 00:00:14 +02:00
Nico Weber f47dbb6a58 AK: Use IEC prefixes in human_readable_format
Windows uses "KB", "MB", "GB" as powers of two.
macOS uses "kB", "MB", "GB" as powers of ten.

"k", "M", "G" are standard SI prefixes that normally refer to powers of
ten.

The IEC introduced "KiB", "MiB", "GiB" to unambiguously refer to
powers of two. It admittedly hasn't caught on that much, but it
does have the advantage that it's unabigious what it means.
So let's use it for user-visible sizes in SerenityOS.

(Linux does all of the above in different places, depending on app and
toolkit.)
2020-08-16 16:33:28 +02:00
Nico Weber aa97166739 Everywhere: Consolidate human_readable_size() implementations
Let's use the one in AK/NumberFormat.h everywhere.

It has slightly different behavior than some of the copies this
removes, but it's probably nice to have uniform human readable
size outputs across the system.
2020-08-16 16:33:28 +02:00
Nico Weber 430b265cd4 AK: Rename KB, MB, GB to KiB, MiB, GiB
The SI prefixes "k", "M", "G" mean "10^3", "10^6", "10^9".
The IEC prefixes "Ki", "Mi", "Gi" mean "2^10", "2^20", "2^30".

Let's use the correct name, at least in code.

Only changes the name of the constants, no other behavior change.
2020-08-16 16:33:28 +02:00
Muhammad Zahalqa a68650a7b4
AK: HashTable add a constructor that allows preallocation of capacity + Use in CppLexer. (#3147)
1. Add general utility to get array number of elements.
2. Add Needed API to AK::HashTable
3. Refactor CppLexer initialization
2020-08-16 11:04:00 +02:00
asynts fff581cd72 AK: Rename span() to bytes() when appropriate.
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-15 21:21:18 +02:00
asynts 525d51bbb5 AK: Add slice() overload to Span. 2020-08-15 21:21:18 +02:00
asynts 36080c5964 AK: Add fill() method to Span. 2020-08-15 21:21:18 +02:00
asynts 78849bbb48 AK: Add copy_to() and move_to() methods to AK::Span. 2020-08-15 21:21:18 +02:00
asynts 8e7dfebf11 AK: Add bytes() method to FixedArray. 2020-08-15 21:21:18 +02:00
asynts d4fe63d2ce AK: Remove incorrect static assert in Span.h.
This assertion was added to prevent accitentally using stuff like
Span<int*> instead of Span<int>. But there can be spans of pointers.
2020-08-15 21:21:18 +02:00
Itamar 310063fed8 Meta: Install source files at /usr/src/serenity 2020-08-15 15:06:35 +02:00
Andreas Kling 6b8807be6e AK: Fix obvious bad vector access in IPv4Address::from_string()
Fixes #3137.
2020-08-14 15:10:58 +02:00
Andreas Kling 28c68fb241 AK: Fix bad vector access in two-part IPv4 address parsing 2020-08-13 21:12:59 +02:00
Panagiotis Vasilopoulos dcfc54d767 AK: Add initial support for obscure IPv4 address notations
This change aims to add support for obscure IPv4 address notations, such as 1.1 (which should be equal to 1.0.0.1), or the hypothetical address 1 (which is equal to 0.0.0.1). This is supported on other platforms as well, such as Linux, Windows, *BSD, and even Haiku.
2020-08-13 19:02:47 +02:00
Ben Wiederhake 5fe6ca75ca AK: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, add forgotten
header to Base64.cpp, which would cause an issue later when we enable -Wmissing-declarations.
2020-08-12 20:40:59 +02:00
AnotherTest caedd05bd8 AK: Span<T>::operator=(const T&) => Span<T>::operator=(const Span<T>&) 2020-08-11 21:37:10 +02:00
Linus Groh 62ea2c5437 AK: Add test case for duplicate JsonObject keys 2020-08-10 14:48:45 +02:00
Linus Groh f649009887 AK: Don't keep equal JsonObject keys in the order vector twice
Fixes #3069.
2020-08-10 14:48:45 +02:00
Ben Wiederhake cc6d5242d1 AK: Implement and test DistinctNumeric class
This template class allows for easy generation of incompatible numeric types.
This is useful whenever code has to handle heterogenous data (like meters and
seconds) but the underlying data types are compatible (like int and int).

The motivation comes from the Kernel's inconsistent use of pid_t for process and
thread IDs even though the ID spaces are incompatible, and translating forth/back
is nontrivial.

Other uses could be units (as described above), or incompatible index systems.
A popular use in real life is image manipulation, when there are multiple
coordinate systems.
2020-08-10 11:51:45 +02:00
Ben Wiederhake 54c6886108 AK: TestSuite's main should return 0 2020-08-10 11:51:45 +02:00
Nico Weber 6613a4cb8c disasm: Insert symbol names in disassembly stream
The symbol name insertion scheme is different from objdump -d's.
Compare the output on Build/Userland/id:

* disasm:

        ...
        _start (08048305-0804836b):
        08048305  push ebp
        ...
        08048366  call 0x0000df56

        0804836b  o16 nop
        0804836d  o16 nop
        0804836f  nop

        (deregister_tm_clones (08048370-08048370))

        08048370  mov eax, 0x080643e0
        ...
        _ZN2AK8Utf8ViewC1ERKNS_6StringE (0805d9b2-0805d9b7):
        _ZN2AK8Utf8ViewC2ERKNS_6StringE (0805d9b2-0805d9b7):
        0805d9b2  jmp 0x00014ff2

        0805d9b7  nop

* objdump -d:

        08048305 <_start>:
         8048305:	55                   	push   %ebp
        ...
         8048366:	e8 9b dc 00 00       	call   8056006 <exit>
         804836b:	66 90                	xchg   %ax,%ax
         804836d:	66 90                	xchg   %ax,%ax
         804836f:	90                   	nop

        08048370 <deregister_tm_clones>:
         8048370:	b8 e0 43 06 08       	mov    $0x80643e0,%eax
        ...
        0805d9b2 <_ZN2AK8Utf8ViewC1ERKNS_6StringE>:
         805d9b2:	e9 eb f6 ff ff       	jmp    805d0a2 <_ZN2AK10StringViewC1ERKNS_6StringE>
         805d9b7:	90                   	nop

Differences:

1. disasm can show multiple symbols that cover the same instructions.
   I've only seen this happen for C1/C2 (and D1/D2) ctor/dtor pairs,
   but it could conceivably happen with ICF as well.

2. disasm separates instructions that do not belong to a symbol with
   a newline, so that nop padding isn't shown as part of a function
   when it technically isn't.

3. disasm shows symbols that are skipped (due to having size 0)
   in parenthesis, separated from preceding and following instructions.
2020-08-10 11:48:10 +02:00
Nico Weber 0586924bbd LibELF+Lagom: Work towards getting LibELF in Lagom
Mostly -Wformat fixes, some of which pointed out real (if benign) bugs.
2020-08-09 21:12:54 +02:00
Benoît Lormeau 7b356c33cb
AK: Add a GenericLexer and extend the JsonParser with it (#2696) 2020-08-09 11:34:26 +02:00
Brian Gianforcaro 9f685ac30a AK: Add static_ptr_cast support for the Userspace<T> pointer type
When using Userspace<T> there are certain syscalls where being able
to cast between types is needed. You should be able to easily cast
away the Userspace<T> wrapper, but it's perfectly safe to be able to
cast the internal type that is being wrapped.
2020-08-07 16:18:36 +02:00
asynts 3fb62e8c63 AK: Remove unnecessary clang-format off comments. 2020-08-07 15:57:51 +02:00
Andreas Kling 3055f73d48 AK+Kernel+LibC: Add vdbgprintf()
This is like dbgprintf() except it takes a va_list instead of ...
2020-08-06 13:36:06 +02:00
Andreas Kling 0d6597df2b AK: Remove Stream::operator bool()
This was only used in one place, and that caused a bug, so I'm removing
this for now since there are no more uses.
2020-08-06 11:37:33 +02:00
asynts b3d1a05261 Refactor: Expose const_cast by removing ByteBuffer::warp(const void*, size_t)
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-08-06 10:33:16 +02:00
asynts ac9f6fd1f8 LibDebug: Use InputMemoryStream instead of BufferStream.
This removes another call to ByteBuffer::wrap(const void*, size_t).
2020-08-06 10:33:16 +02:00
asynts 5bfa7749c3 AK: Add InputStream abstraction and InputMemoryStream implementation. 2020-08-06 10:33:16 +02:00
asynts 75cde94c6a AK: Add String constructor from ReadonlyBytes. 2020-08-06 10:33:16 +02:00
asynts 42b4880653 AK: Rename Tests/Span.cpp to Tests/TestSpan.cpp. 2020-08-06 10:33:16 +02:00
asynts 5f7427ba4b AK: Add Integral and FloatingPoint concepts. 2020-08-06 10:33:16 +02:00
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