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

[pull] master from MusicPlayerDaemon:master #17

Merged
merged 5 commits into from
Jan 21, 2025

Conversation

pull[bot]
Copy link

@pull pull bot commented Jan 21, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by Sourcery

Chores:

  • Replace FMT_STRING with fmt::format.

heitbaum and others added 5 commits January 13, 2025 06:17
When compiling with libfmt-11.1.0 and newer the following compile errors occur:

In file included from ../src/decoder/DecoderPrint.cxx:23:
../src/client/Response.hxx: In instantiation of 'bool Response::Fmt(const S&, Args&& ...) [with S = decoder_plugin_print(Response&, const DecoderPlugin&)::<lambda()>::FMT_COMPILE_STRING; Args = {const char* const&}]':
../src/decoder/DecoderPrint.cxx:38:7:   required from here
   38 |         r.Fmt(FMT_STRING("plugin: {}\n"), plugin.name);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/client/Response.hxx:86:28: error: cannot convert 'const decoder_plugin_print(Response&, const DecoderPlugin&)::<lambda()>::FMT_COMPILE_STRING' to 'fmt::v11::string_view' {aka 'fmt::v11::basic_string_view<char>'}
   86 |                 return VFmt(format_str,
      |                        ~~~~^~~~~~~~~~~~
   87 |                             fmt::make_format_args(args...));
      |                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/client/Response.hxx:81:36: note: initializing argument 1 of 'bool Response::VFmt(fmt::v11::string_view, fmt::v11::format_args)'
   81 |         bool VFmt(fmt::string_view format_str, fmt::format_args args) noexcept;
      |                   ~~~~~~~~~~~~~~~~~^~~~~~~~~~
../src/client/Response.hxx: In instantiation of 'bool Response::Fmt(const S&, Args&& ...) [with S = decoder_plugin_print(Response&, const DecoderPlugin&)::<lambda()>::FMT_COMPILE_STRING; Args = {const char* const&}]':

The error is due to the use of FMT_STRING. The libfmt team shared the following:

    The correct way of using FMT_STRING is to wrap a format string when passing to a
    function with compile-time checks (i.e. that takes format_string) as documented
    in https://fmt.dev/11.1/api/#legacy-compile-time-checks.

    Noting that FMT_STRING is a legacy API and has been superseded by consteval-based
    API starting from version 8: https://github.com/fmtlib/fmt/releases/tag/8.0.0. It
    looks like MPD is trying to emulate {fmt}'s old way of implementing compile-time
    checks which was never properly documented because it was basically a hack. So the
    correct fix is to switch to format_string and, possibly, remove usage of FMT_STRING.

    The old way of doing compile-time checks (fmt::make_args_checked) was documented
    in https://fmt.dev/7.1/api.html#argument-lists but it looks like MPD is not using
    that API so the problematic uses of FMT_STRING have no effect and can just be removed.

The FMT_STRING has been removed in this change based on the fmt-7.1 API and now MPD is
successfully compile against the current libfmt-11.1.0 which highlighted the issue that
had been present in the codebase as it is now triggering the error, is legacy and was
not using the API for which FMT_STRING was aligned with.
Minor revert of 9db7144
- no change was to be done to meson.build.
MPD stopped building since fmt 11.1.0; see
<fmtlib/fmt#4304>. The first commit
fixing this was 9db7144, followed by 5de0909 (both on the
unstable branch).

This commit removes what the author believes to be the remaining
uses in the MPD codebase.
@pull pull bot added the ⤵️ pull label Jan 21, 2025
@pull pull bot merged commit 194ecd6 into CartoonFan:master Jan 21, 2025
Copy link

sourcery-ai bot commented Jan 21, 2025

Reviewer's Guide by Sourcery

This pull request refactors the code to use the new fmt library for formatting strings. This change improves code readability and maintainability by using a more modern and type-safe approach to string formatting.

Class diagram showing the Response class changes

classDiagram
    class Response {
        +Write(text: string)
        +WriteBinary(payload: span<byte>)
        +Error(code: ack, msg: string)
        +VFmtError(code: ack, format_str: string_view, args: format_args)
        +Fmt(format_str: string_view, ...args)
        -old_fmt_string FMT_STRING(str) removed
        note for Response "Changed from FMT_STRING macro
to direct string literals for fmt""
    }
Loading

Flow diagram showing string formatting changes

graph TD
    A[Old Format Style] -->|Refactored| B[New Format Style]
    A -->|Uses| C[FMT_STRING macro]
    B -->|Uses| D[Direct string literals]
    C -->|Removed| E[Simplified formatting]
    D -->|Provides| F[Type-safe formatting]
    F -->|Improves| G[Code maintainability]
    F -->|Enhances| H[Code readability]
Loading

File-Level Changes

Change Details Files
Refactor string formatting using the fmt library.
  • Replaced FMT_STRING with direct string literals in r.Fmt calls.
  • Removed redundant FMT_STRING macros.
  • Updated format strings to use the new fmt library syntax.
src/command/PlayerCommands.cxx
src/queue/PlaylistState.cxx
src/SongPrint.cxx
src/SongSave.cxx
src/TagPrint.cxx
src/Stats.cxx
src/command/AllCommands.cxx
src/command/FileCommands.cxx
src/command/OtherCommands.cxx
src/db/DatabasePrint.cxx
src/command/StorageCommands.cxx
src/db/plugins/simple/DirectorySave.cxx
src/output/Print.cxx
src/storage/StorageState.cxx
src/command/DatabaseCommands.cxx
src/decoder/DecoderPrint.cxx
src/queue/Print.cxx
src/db/plugins/simple/DatabaseSave.cxx
src/PlaylistDatabase.cxx
src/PlaylistSave.cxx
src/TagSave.cxx
src/client/ProtocolFeature.cxx
src/client/Response.cxx
src/command/MessageCommands.cxx
src/command/NeighborCommands.cxx
src/command/StickerCommands.cxx
src/command/TagCommands.cxx
src/db/Count.cxx
src/lib/icu/Converter.cxx
src/playlist/Length.cxx
src/queue/Save.cxx
src/TimePrint.cxx
src/client/Idle.cxx
src/command/FingerprintCommands.cxx
src/command/PartitionCommands.cxx
src/command/PlaylistCommands.cxx
src/command/QueueCommands.cxx
src/ls.cxx
src/mixer/Memento.cxx
src/output/State.cxx
src/output/plugins/PipeWireOutputPlugin.cxx
src/playlist/Print.cxx
src/song/PrioritySongFilter.cxx
src/sticker/Print.cxx
src/queue/QueuePrint.cxx

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants