Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Everywhere: Remove AK::StringView(char const*) :^) #14555

Merged
merged 25 commits into from
Jul 12, 2022

Commits on Jul 12, 2022

  1. AK: Make CheckedFormatString pass the char array size to StringView

    This makes the assumption that we never pass a stack-allocated char
    array to CheckedFormatString arguments (dbgln, outln, warnln). This
    assumption seems to hold true for the current state of Serenity code, at
    least. :^)
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    a4eee80 View commit details
    Browse the repository at this point in the history
  2. AK: Explicitly calculate length of char* when printing

    This moves out the calculation of the char* out to the formatter.
    Additionally, we now print (null) when a null pointer is passed.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    4d5a719 View commit details
    Browse the repository at this point in the history
  3. AK: Add string literal helpers to AK::SourceGenerator

    Since all uses of SourceGenerator are with literal strings, there is no
    need to burden generators with the sv suffix.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    79a7c63 View commit details
    Browse the repository at this point in the history
  4. Meta+Userland: Simplify some formatters

    These are mostly minor mistakes I've encountered while working on the
    removal of StringView(char const*). The usage of builder.put_string over
    Format<FormatString>::format is preferrable as it will avoid the
    indirection altogether when there's no formatting to be done. Similarly,
    there is no need to do format(builder, "{}", number) when
    builder.put_u64(number) works equally well.
    
    Additionally a few Strings where only constant strings were used are
    replaced with StringViews.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    0184889 View commit details
    Browse the repository at this point in the history
  5. LibChess: Add convenience constructor for Chess::Square

    It didn't feel right to add sv suffixes to 2-character strings, so I
    added this convenience constructor.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    7f4f24e View commit details
    Browse the repository at this point in the history
  6. LibJS: Emit StringViews for ErrorType instances

    This removes the need for calculating each string's length during
    ErrorType use at the cost of storing it within the binary.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    2b04aa1 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    fa829f4 View commit details
    Browse the repository at this point in the history
  8. Tests: Convert TestBase64 decode test to use StringViews directly

    Previously it would rely on the implicit StringView conversions. Now the
    decode_equal function will directly use StringViews.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    ad11148 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    5280a74 View commit details
    Browse the repository at this point in the history
  10. Userland: Convert command line arguments to String/StringView

    StringView was used where possible. Some utilities still use libc
    functions which expect null-terminated strings, so String objects were
    used there instead.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    6b3d3e6 View commit details
    Browse the repository at this point in the history
  11. Userland: Remove erroneous String -> char* -> StringView conversions

    These were accidental (or leftover) uses of String::characters() to
    construct StringViews through its StringView(char const*) constructor.
    Since this constructor is due to be removed, this will no longer work.
    Plus this prevents strlen from being run on these strings unnecessarily.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    800d27e View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    4b56df6 View commit details
    Browse the repository at this point in the history
  13. LibCore: Add convenience templates for System::{unveil,pledge}

    These convenience templates allow the following to be written as before:
    
        TRY(Core::System::pledge("promises..."));
        TRY(Core::System::pledge("promises...", "execpromises..."));
        TRY(Core::System::unveil("path", "permissions"));
        TRY(Core::System::unveil(nullptr, nullptr));
    
    Other uses must now append sv to any literal string passed to pledge and
    unveil.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    2fd97ab View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    d80a19d View commit details
    Browse the repository at this point in the history
  15. Everywhere: Explicitly specify the size in StringView constructors

    This commit moves the length calculations out to be directly on the
    StringView users. This is an important step towards the goal of removing
    StringView(char const*), as it moves the responsibility of calculating
    the size of the string to the user of the StringView (which will prevent
    naive uses causing OOB access).
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    178b053 View commit details
    Browse the repository at this point in the history
  16. Everywhere: Split Error::from_string_literal and Error::from_string_view

    Error::from_string_literal now takes direct char const*s, while
    Error::from_string_view does what Error::from_string_literal used to do:
    taking StringViews. This change will remove the need to insert `sv`
    after error strings when returning string literal errors once
    StringView(char const*) is removed.
    
    No functional changes.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    9186d21 View commit details
    Browse the repository at this point in the history
  17. Everywhere: Add sv suffix to strings relying on StringView(char const*)

    Each of these strings would previously rely on StringView's char const*
    constructor overload, which would call __builtin_strlen on the string.
    Since we now have operator ""sv, we can replace these with much simpler
    versions. This opens the door to being able to remove
    StringView(char const*).
    
    No functional changes.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    7a9bbfc View commit details
    Browse the repository at this point in the history
  18. Everywhere: Replace single-char StringView op. arguments with chars

    This prevents us from needing a sv suffix, and potentially reduces the
    need to run generic code for a single character (as contains,
    starts_with, ends_with etc. for a char will be just a length and
    equality check).
    
    No functional changes.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    326099c View commit details
    Browse the repository at this point in the history
  19. Everywhere: Use default StringView constructor over nullptr

    While null StringViews are just as bad, these prevent the removal of
    StringView(char const*) as that constructor accepts a nullptr.
    
    No functional changes.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    e67ba36 View commit details
    Browse the repository at this point in the history
  20. LibCore: Add FIXME note about converting Core::Account to use StringView

    This prevents a bunch of utilities from using StringView for their
    arguments.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    98474cb View commit details
    Browse the repository at this point in the history
  21. LibRegex: Remove RegexStringView(char const*) constructor

    This allowed passing in a nullptr for the StringView which will not be
    possible once StringView(char const*) is removed.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    87d8d26 View commit details
    Browse the repository at this point in the history
  22. AK: Remove String <-> char const* comparison operators

    During the removal of StringView(char const*), all users of these
    functions were removed, and they are of dubious value (relying on
    implicit StringView conversion).
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    c306fee View commit details
    Browse the repository at this point in the history
  23. AK+Userland+Tests: Remove URL(char const*) constructor

    The StringView(char const*) constructor is being removed, and there was
    only a few users of this left, which are also cleaned up in this commit.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    cb75f32 View commit details
    Browse the repository at this point in the history
  24. Tests: Remove StringView char const* initialization test

    We now explicitly disallow this.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    9b21264 View commit details
    Browse the repository at this point in the history
  25. AK: Remove StringView(char const*) :^)

    This constructor relied on running strlen implicitly on its argument,
    thereby potentially causing out-of-bound reads (some of which were
    caught a few days ago). The removal of this constructor ensures that the
    caller must explicitly pass the size of the string by either:
    
    1) Using operator""sv on literal strings; or
    2) Calling strlen explicitly, making it clear that the size of the view
       is being calculated at runtime.
    sin-ack committed Jul 12, 2022
    Configuration menu
    Copy the full SHA
    54094f6 View commit details
    Browse the repository at this point in the history