Skip to content

Conversation

@boberfly
Copy link
Collaborator

Fmt : When using Fmt 10.x it is more strict about types passed to fmt::format, ensure it is a std::string or c-string

Generally describe what this PR will do, and why it is needed

  • When building against fmt 10 there were a few cases where the type sent to fmt::format needed a template specialisation, but in just about all cases they could be simply converted to a known type like std::string, c-string or int. Some cases needed a specific enumerator to string function conversion. In the case of ONNX I couldn't find a function which could reflect back a string form for element types so I just put them in myself...

Related issues

  • NA

Dependencies

  • Eventually there will be an update to fmt so this would help here, but it'll work still with fmt 9.x (well, lets see how the CI goes...)

Breaking changes

  • Shouldn't have any

Checklist

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable.
  • I have tested my change(s) in the test suite, and added new test cases where necessary.
  • My code follows the Gaffer project's prevailing coding style and conventions.

…::format, ensure it is a std::string or c-string
Copy link
Member

@johnhaddon johnhaddon left a comment

Choose a reason for hiding this comment

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

Thanks Alex! What sort of timeframe are you hoping to get this merged in? As I've noted inline, I think it'd be better if we approached this with custom formatters in several cases, meaning some of the solution at least would be in Cortex. Cortex doesn't currently have a fmtlib dependency although I would love to replace boost::format with it throughout (as we've already done for Gaffer). Would the 1.7 timeframe be acceptable, so we can introduce the dependency in Cortex?

if( !std::filesystem::is_regular_file( kernelFile ) )
{
IECore::msg( IECore::Msg::Error, "IECoreCycles::init", fmt::format( "File \"{}\" not found", kernelFile ) );
IECore::msg( IECore::Msg::Error, "IECoreCycles::init", fmt::format( "File \"{}\" not found", kernelFile.string() ) );
Copy link
Member

Choose a reason for hiding this comment

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

I think we can #include "fmt/std.h" to get automatically formatting of paths.

{
spec.channelnames.push_back(
fmt::format( "{}{}{}", layerName, layerName.size() ? "." : "", g_channels[i] )
fmt::format( "{}{}{}", layerName, layerName.size() ? "." : "", g_channels[i].string() )
Copy link
Member

Choose a reason for hiding this comment

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

I think we should have Cortex provide a formatter for InternedString, so we don't need to do this at all call sites.

fmt::format(
"{} attribute edit{} required geometry to be regenerated",
m_failedAttributeEdits, m_failedAttributeEdits > 1 ? "s" : ""
m_failedAttributeEdits.load(), m_failedAttributeEdits > 1 ? "s" : ""
Copy link
Member

Choose a reason for hiding this comment

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

I think this is another one that would be dealt with by #include "fmt/std.h"

if( !a )
{
msg( Msg::Warning, messageContext, fmt::format( "Unable to create array from data of type \"{}\" for parameter \"{}\"", value->typeName(), name ) );
msg( Msg::Warning, messageContext, fmt::format( "Unable to create array from data of type \"{}\" for parameter \"{}\"", value->typeName(), name.c_str() ) );
Copy link
Member

Choose a reason for hiding this comment

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

There are enough of these that perhaps it would be better to register a formatter for AtString? I think format_as allows us to do that quite simply?

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.

2 participants