Commit graph

29316 commits

Author SHA1 Message Date
Leandro Pereira
314b8a374b SoundPlayer: Implement playlist shuffle mode
The shuffling algorithm uses a naïve bloom filter to provide random
uniformity, avoiding items that were recently played.  With 32 bits,
double hashing, and an error rate of ~10%, this bloom filter should
be able to hold around ~16 keys, which should be sufficient to give the
illusion of fairness to the shuffling algorithm.

This avoids having to shuffle the playlist itself (user might have
spent quite a bit of time to sort them, so it's not a good idea to mess
with it), or having to create a proxy model that shuffles (that could
potentially use quite a bit of memory).
2021-10-25 23:37:18 +02:00
Leandro Pereira
0812965f50 SoundPlayer: Make M3UParser more idiomatic
Let's use the nice APIs we have, and make the M3U parser a bit more
readable, shorter, and resilient.
2021-10-25 23:37:18 +02:00
Leandro Pereira
3126b78903 SoundPlayer: Fix inconsistencies and code duplication
This is a first pass at refactoring SoundPlayer so that the View widget
is decoupled from the player itself.

In doing so, this fixed a couple of issues, including possibly
inconsistent states (e.g. player could be paused and stopped at the
same time).

With the change, Player actually controls the show, and calls methods
overriden by its subclasses to perform actions, such as update the Seek
bar; the hard work of massaging the raw data is done by the Player
class, so subclasses don't need to reimplement any of these things.

This also removes some copies of playlist management code that happened
to be copied+pasted inside callbacks of buttons -- it now lives inside
a neatly packaged Playlist class, and the Player only asks for the next
song to play.

In addition, the menu bar has been slightly rearranged.
2021-10-25 23:37:18 +02:00
Leandro Pereira
73924f9416 LibCore: Add File::size()
Returns the size in bytes for a file path given its filename. Useful
when file size is needed without having to open the file to query it
using fstat() or seeking to the end.
2021-10-25 23:37:18 +02:00
Leandro Pereira
368e74fdf8 AK: Allow seed value to be specified in string_hash()
For some algorithms, such as bloom filters, it's possible to reuse a
hash function (rather than having different hashing functions) if the
seed is different each time the hash function is used.

Modify AK::string_hash() to take a seed parameter, which defaults to 0
(the value the hash value was originally initialized to).
2021-10-25 23:37:18 +02:00
Daniel Bertalan
5241c5f219 Ports: Enable history handling in bc
An oversight in the TTY defaults caused bc to reach an assertion failure
when it tried to set up raw mode for printing the history.

Now that this is fixed, we can finally enable history handling.
2021-10-25 21:42:26 +02:00
Daniel Bertalan
5f6030b13c Kernel+LibC: Default to 8-bit characters in TTY
Some ports (like `bc` with history enabled) sensibly set the termios
character size to 8 bits.

Previously, we left the character size value (given by the bitmask
CSIZE) as zero by default (meaning 5 bits per character), and returned
ENOTIMPL whenever someone modified it. This was dumb.
2021-10-25 21:42:26 +02:00
Andrew Pardoe
0e68550c05 MouseSettings: Add option to reverse buttons
Add option to reverse primary and secondary buttons in Mouse Settings.
- WindowServer.ini: add default entry
- switch-mouse-buttons.png: new icon for settings entry
- Mouse.gml/MouseWidget.*: new settings dialog
- ClientConnection/WindowManager/Server: window message for settings
- EventLoop.cpp: swap buttons 1 and 2 if settings are on
2021-10-25 19:20:33 +03:00
Andreas Kling
5599d22744 LibJS: Support calling result of a computed MemberExpression in bytecode
This patch adds support for calls of the form o.f[expr]()
2021-10-25 16:05:04 +02:00
Andreas Kling
a2a8b97c11 LibJS: Simplify MemberExpression::generate_bytecode()
Use the get-from-reference helper in BytecodeGenerator.
2021-10-25 16:04:31 +02:00
Andreas Kling
72cd31d033 LibJS: Tweak Value::to_property_key() fast path for Int32
Move the check for Int32 *before* we call to_primitive().
2021-10-25 15:37:28 +02:00
Andreas Kling
cfbb69a9cd LibJS: Support more assignment expressions in the bytecode VM
Use the new reference get/put helpers in BytecodeGenerator to support
assignment expressions other than just plain assignment.
2021-10-25 15:29:52 +02:00
Andreas Kling
72736f9e93 LibJS: Generate bytecode for UpdateExpression with MemberExpression arg 2021-10-25 15:17:41 +02:00
Andreas Kling
1dc60b028f LibJS: Add BytecodeGenerator helpers for reference get/put
This allows code sharing between all AST nodes that want to get and/or
put through a reference.
2021-10-25 15:16:22 +02:00
Andreas Kling
b63d17e2f8 LibJS: Add fast paths for <, >, <=, and >= with Int32 on both sides
This gives us a ~5% speed-up on Kraken's ai-astar.js
2021-10-25 14:35:23 +02:00
Andreas Kling
b4c0e27d26 AK: Always inline Optional::release_value()
This allows the compiler to optimize away the VERIFY(m_has_value) in
many cases.
2021-10-25 14:31:46 +02:00
Andreas Kling
765ed9677b DHCPClient: Simplify DHCPv4PacketBuilder
Instead of creating a temporary ByteBuffer to hold the packet while
building it, we can just create the DHCPv4Packet struct directly.
2021-10-25 14:31:11 +02:00
Andreas Kling
d203a86900 LibJS: Always inline the bytecode instruction iterator's operator++ 2021-10-25 13:37:02 +02:00
Andreas Kling
a97d75bb63 LibJS: Add default constructor for PrivateName
This avoids a round-trip through FlyString("") for every Reference.
2021-10-25 13:29:44 +02:00
Andreas Kling
b2f15537bb AK: Add fast path for constructing StringImpl from "" literal 2021-10-25 13:29:44 +02:00
Brendan Coles
518b8fb292 Ports: Bump bc from version 2.5.1 to 5.1.1 2021-10-25 13:01:40 +02:00
Karol Kosek
d40c36a16e Assistant: Fix adding sequential bonus in Fuzzy Match
It was comparing if they both had the same index position (which was
always false).
2021-10-25 13:00:32 +02:00
Karol Kosek
5e10cd364b Assistant: Save match all match points in Fuzzy Match
From what I think, the array should consist of point indexes that have
been matched instead of just the last one.

For example, these are the array contents after searching 'file' for
'File Manager':
- Before: [ 3 ]
- Now: [ 0, 1, 2, 3 ]

Besides that, this greatly improves the scoring logic, as it can now
calculate bonuses.

Closes: #8310
2021-10-25 13:00:32 +02:00
Karol Kosek
e7eccf3de2 Assistant: Simplify the logic of calculating bonus points
This does not change the results, but makes the code clearer.
2021-10-25 13:00:32 +02:00
Karol Kosek
ee17614e34 Assistant: Move score calculation logic to separate function 2021-10-25 13:00:32 +02:00
Karol Kosek
5ddd1555bc Assistant: Make strings const referenced
Found by clazy.
2021-10-25 13:00:32 +02:00
Jan de Visser
7496f17620 LibSQL Tests: Add tests for SELECT ... WHERE ... 2021-10-25 12:59:42 +02:00
Jan de Visser
9022cf99ff LibSQL: Add better error handling to evaluate and execute methods
There was a lot of `VERIFY_NOT_REACHED` error handling going on. Fixed
most of those.

A bit of a caveat is that after every `evaluate` call for expressions
that are part of a statement the error status of the `SQLResult` return
value must be called.
2021-10-25 12:59:42 +02:00
Jan de Visser
0cfb5eec32 LibSQL: First cut of SQL WHERE clause
Filters matching rows by doing a table scan and evaluating the `WHERE`
expression for every row.

Does not use indexes, for one because they do not exist yet.
2021-10-25 12:59:42 +02:00
Jan de Visser
9d1e27d8a8 LibSQL: Implement evaluate() method of BinaryOperatorExpression
Mostly just calls the appropriate methods on the Value objects.
Exception are the `Concatenate` (string concat), and the logical `and`
and `or` operators which are implemented directly in
`BinaryOperatorExpression::evaluate`
2021-10-25 12:59:42 +02:00
Jan de Visser
73fc023652 LibSQL: Implement binary operators for Value objects
The behaviour of the various operators is supposed to mimic that of
the same operators in PostgreSQL; the '+' operator for example will
successfully add '98' (string) and 2 (integer), but not 'foo' and 2.

Also removed some redundant const& parameter declarations for
intrinsic types (ints and doubles etc). Passing those by const& doesn't
make a lot of sense.
2021-10-25 12:59:42 +02:00
Andreas Kling
3618ca2420 LibJS: Propagate exceptions across bytecode executable boundaries
To support situations like this:

    function foo() { throw 1; }

    try {
        foo();
    } catch (e) {
    }

Each unwind context now keeps track of its origin executable.

When an exception is thrown, we return from run() immediately if the
nearest unwind context isn't in the current executable.

This causes a natural unwind to the point where we find the
catch/finally block(s) to jump into.
2021-10-25 12:57:21 +02:00
Andreas Kling
5a099b98cd LibJS: Make eval() code run in the bytecode VM
If we have an active bytecode interpreter, let's make eval() use it.
2021-10-25 12:57:21 +02:00
Andreas Kling
049b755123 LibJS: Make bytecode interpreter leave unwind context immediately
We were missing some "break" statements, causing us to actually finish
executing everything within "try" blocks before actually jumping to the
"catch" and/or "finally" blocks.
2021-10-25 12:57:21 +02:00
Andreas Kling
a831cd9cc7 LibJS: Make bytecode VM throw TypeError on attempt to call non-callable
This isn't perfect, but allows us to progress instead of crashing in
the TODO().
2021-10-25 12:57:21 +02:00
Andreas Kling
6fc3c14b7a LibJS: Fix bogus bytecode codegen for "catch" parameters
Add a missing '!' so that catch clauses with a named parameter actually
generate a SetVariable opcode.
2021-10-25 12:57:21 +02:00
Daniel Bertalan
ac1cac286b Profiler: Fix disassembling objects with a non-zero .text vaddr
Previously, we assumed that the `.text` segment was loaded at vaddr 0 in
shared object, which is not the case with `-z separate-code` enabled.
Because we didn't do the right calculations to translate an address from
a performance event into its value within the ELF file, Profiler would
try to disassemble out-of-bounds memory locations, leading to a crash.

This commit also changes `LibraryMetadata` to apply to a loaded library
as a whole, not just to one of its segments (like .text or .data). This
lets us simplify the interface, as we no longer have to worry about
`text_base`.

Fixes #10628
2021-10-25 12:14:26 +02:00
Daniel Bertalan
15a14d3d21 LibX86: Take load base address into consideration during disassembly
Since our executables are position-independent, the address values
extraced from processes don't correspond to their values within the ELF
file. We have to offset the absolute addresses by the load base address
to get the relative symbol that we need for disassembly.
2021-10-25 12:14:26 +02:00
Daniel Bertalan
7c27ba1240 Profiler: Subtract the kernel's base address when searching for symbols
Now that the kernel is compiled as a PIE, all addresses are relative to
the loaded base address, so Symbolication::kernel_base has to be
subtracted off from the absolute addresses if we want to symbolicate
them.
2021-10-25 12:14:26 +02:00
Brendan Coles
c1d915afe6 Ports: byacc+gmp+m4: Split auth_opts strings into array elements 2021-10-25 00:06:43 -07:00
Jelle Raaijmakers
a44978b9b0 LibC: Fix %n conversion specifier in scanf() format
Also add a test to prevent this from happening again. There were two
bugs:

* The number of bytes just after processing the last value was written,
  instead of the number of bytes after skipping remaining whitespace.
  Confirmed by testing against GNU's `scanf()` since the man page
  leaves something to be desired.

* The number of bytes was written to the wrong variable argument; i.e.
  the first argument was overwritten.
2021-10-24 22:43:27 -07:00
Jelle Raaijmakers
00f36fc5ae Tests: Print full 32-byte range of values in TestScanf
We are trying to show 8 u32 values, each of which needs at most 8
hexadecimal characters to be shown entirely.
2021-10-24 22:43:27 -07:00
Jelle Raaijmakers
e71e9de61f Tests: Reword 'output' to 'return value' in TestScanf 2021-10-24 22:43:27 -07:00
Jelle Raaijmakers
e3f17401cb Tests: Use correct argument count for value conformance in TestScanf 2021-10-24 22:43:27 -07:00
Tim Schumacher
65bcee3c62 Tests: Only test truthiness for iswctype 2021-10-24 22:40:11 -07:00
Tim Schumacher
338f80cbf6 LibTest: Introduce a macro to only compare truthiness 2021-10-24 22:40:11 -07:00
Tim Schumacher
9e3e4a692d Tests: Use proper comparison macros for wctype 2021-10-24 22:40:11 -07:00
Brendan Coles
2876aebb32 Ports: Add GNU gperf port 2021-10-24 22:34:02 -07:00
Karol Kosek
78bebb363b LibHTTP: Reset m_content_length if there's a Transfer-Encoding header 2021-10-24 23:54:26 +02:00
Karol Kosek
89c87ff7b9 LibHTTP: Trim the last packet if it exceeded the Content-Length value
Used these commands to test it:

  printf 'HTTP/1.0 200 OK\r\n%s\r\n\r\n%s' 'Content-Length: 4' \
      'well hello friends!' | nc -lN 0.0.0.0 8000
  pro http://0.0.0.0:8000
2021-10-24 23:54:26 +02:00