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

Address fmt::format_to memory_buffer deprecation #1122

Merged
merged 3 commits into from
Oct 20, 2021

Conversation

ischoegl
Copy link
Member

@ischoegl ischoegl commented Oct 17, 2021

Changes proposed in this pull request

The deprecation is addressed by replacing

fmt::memory_buffer b;
format_to(b, "The answer is {}.", 42);

by

fmt::memory_buffer b;
format_to(std::back_inserter(b), "The answer is {}.", 42);

The fix uses std::back_inserter rather than fmt::appender as the latter is not available in older versions of libfmt. The current GH Actions Sundials runners already use libfmt v8.0.1 where the deprecation warnings show up.

Also reformatted affected lines to stay within the 88 character line limits.

If applicable, fill in the issue number this pull request is fixing

Closes #1098

If applicable, provide an example illustrating new features this pull request is introducing

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

@codecov
Copy link

codecov bot commented Oct 17, 2021

Codecov Report

Merging #1122 (6798c57) into main (f46c3bb) will increase coverage by 0.00%.
The diff coverage is 67.14%.

❗ Current head 6798c57 differs from pull request most recent head cf97245. Consider uploading reports for the commit cf97245 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1122   +/-   ##
=======================================
  Coverage   73.45%   73.45%           
=======================================
  Files         364      365    +1     
  Lines       47884    47912   +28     
=======================================
+ Hits        35172    35194   +22     
- Misses      12712    12718    +6     
Impacted Files Coverage Δ
src/thermo/PureFluidPhase.cpp 60.08% <0.00%> (-1.10%) ⬇️
src/transport/GasTransport.cpp 87.52% <0.00%> (ø)
src/thermo/RedlichKwongMFTP.cpp 84.91% <50.00%> (ø)
src/base/AnyMap.cpp 89.51% <76.92%> (-0.11%) ⬇️
src/thermo/MolalityVPSSTP.cpp 75.17% <78.94%> (-0.37%) ⬇️
src/thermo/ThermoPhase.cpp 77.85% <86.84%> (+0.20%) ⬆️
include/cantera/base/fmt.h 100.00% <100.00%> (ø)
src/kinetics/KineticsFactory.cpp 96.84% <100.00%> (ø)
src/kinetics/RxnRates.cpp 88.20% <100.00%> (+0.05%) ⬆️
src/numerics/CVodesIntegrator.cpp 73.27% <100.00%> (+0.10%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f46c3bb...cf97245. Read the comment docs.

@bryanwweber
Copy link
Member

as the latter is not available in older versions of libfmt

What's the oldest version that has fmt::appender? We could consider bumping the minimum version of libfmt.

@ischoegl
Copy link
Member Author

ischoegl commented Oct 17, 2021

What's the oldest version that has fmt::appender?

Hard to tell ... fmt::appender is implied to be preferable over std::back_inserter in fmtlib/fmt#2420, but it is also pointed out that it is undocumented (at least on their official documentation). It certainly isn't part of fmt v6.2.1 which is stock Ubuntu 18.04. There's also no information to be gleaned from the release notes.

@ischoegl ischoegl requested a review from a team October 17, 2021 18:54
@speth
Copy link
Member

speth commented Oct 19, 2021

Writing format_to(std::back_inserter(b), ...) every time gets a little clunky. I wouldn't be opposed adding a simple utility function like

template <typename... Args>
void fmt_append(fmt::memory_buffer& b, Args... args) {
    format_to(std::.back_inserter(b), args...);
}

which probably belongs in include/cantera/base/fmt.h. If you look in that file, you may notice that this isn't the first time that the API for building up a formatted string this way has changed -- we have a workaround to implement format_to using the API that was used before version 5.0.

@ischoegl
Copy link
Member Author

@speth ... thanks for the comment. There are pro's and con's to both options:

  • pro of format_to(std::back_inserter(b), ...) is that it uses fmt directly / con is that it's clunky and doesn't allow fmt::appender
  • pro of the template is that it's more flexible (we get to differentiate between fmt versions) / con is that it's no longer a standard fmt function.

I don't have a strong preference here.

@ischoegl
Copy link
Member Author

ischoegl commented Oct 20, 2021

OK. I added the template version in a separate commit (i.e. should be squashed), where I used fmt::appender (introduced in v8.0.0). Also fixed a minor compilation warning that I noticed.

PS: I noticed a couple of minor alignment glitches, which I'll fix when squashing.

@ischoegl
Copy link
Member Author

@speth / @bryanwweber ... done.

Copy link
Member

@speth speth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @ischoegl! This looks good to me.

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

Successfully merging this pull request may close these issues.

Upcoming fmt::format_to memory_buffer deprecation
3 participants