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

Fix %*s handling by formattedRead() #10654

Merged
merged 2 commits into from
Mar 2, 2025

Conversation

nicolo-mn
Copy link
Contributor

@nicolo-mn nicolo-mn commented Mar 1, 2025

This PR addresses issue #10598. The problem lies in the lack of handling for certain specifiers in the skipData function of std/format/internal/read.d. The switch statement only handles %c, %d and %u. Handling of %s was added but the problem is analogous in the case of other specifiers. For example, the program:

import std.format;
import std.stdio;
void main()
{
    string str = "3.14159 0.0 6.28318";
    double pi, tau;
    str.formattedRead("%f %*f %f", pi, tau);
    writeln("Pi is: ", pi , ", Tau is: ", tau);
}

outputs this:

core.exception.AssertError@/home/nick/dlang/dmd/generated/linux/release/64/../../../../../phobos/std/format/internal/read.d(43): Format specifier not understood: %f
----------------
??:? _d_assert_msg [0x55af8fd75528]
??:? pure @safe void std.format.internal.read.skipData!(immutable(char)[], char).skipData(ref immutable(char)[], scope ref const(std.format.spec.FormatSpec!(char).FormatSpec)) [0x55af8fd4f58d]
??:? pure @safe void std.format.read.formattedRead!(immutable(char)[], char, double).formattedRead(ref immutable(char)[], const(char)[], ref double).skipUnstoredFields() [0x55af8fd51091]
??:? pure @safe uint std.format.read.formattedRead!(immutable(char)[], char, double).formattedRead(ref immutable(char)[], const(char)[], ref double) [0x55af8fd50ffa]
??:? pure @safe uint std.format.read.formattedRead!(immutable(char)[], char, double, double).formattedRead(ref immutable(char)[], const(char)[], ref double, ref double) [0x55af8fd49d4f]
??:? _Dmain [0x55af8fd49918]

Therefore, the remaining specifiers also need to be handled. Should I include them in this PR, or should I open a separate, more general issue and PR for this problem?

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @nicolo-mn! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + phobos#10654"

@thewilsonator thewilsonator linked an issue Mar 1, 2025 that may be closed by this pull request
@thewilsonator
Copy link
Contributor

please add the test case from #10598 as a unittest.

@nicolo-mn
Copy link
Contributor Author

Thank you for your review @thewilsonator. A unittest was added. I remain available for further changes.

@nicolo-mn
Copy link
Contributor Author

@thewilsonator Is it possible that the checks have been interrupted without any errors? I see the message Error: The operation was canceled. but no log errors.

@thewilsonator
Copy link
Contributor

Some of those time out

@nicolo-mn
Copy link
Contributor Author

Thanks for running the tests one more time. Unfortunately, the same check on macOS 13 x64 keeps timing out for some reason. I double-checked my implementation and it seems fine to me. Do you have any ideas on what might be causing this?

@thewilsonator thewilsonator merged commit 0d724aa into dlang:master Mar 2, 2025
9 of 10 checks passed
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.

Incorrect %*s handling by formattedRead()
3 participants