Skip to content

native/stdio: Explicitly provide getchar #19330

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

Merged
merged 1 commit into from
Feb 28, 2023

Conversation

chrysn
Copy link
Member

@chrysn chrysn commented Feb 27, 2023

Contribution description

This ensures that even when libc does not implement getchar through getc, any custom stdio is still in the loop when getchar is used.

Frankly, I don't know when this broke -- I'm pretty sure custom stdio worked just a few days ago -- but either way, without this patch RIOT on native currently bypasses a configured stdio for me.

Testing procedure

  • make -C examples/saul all debug
  • break stdio_read
  • run

Without this patch, observe how the shell runs w/o ever breaking. After, lots of breakpoint hits.

This is the way it behaves for me (Debian sid, libc6:i386 2.36-8). If it works for you before this patch, we might start bisecting the differences between the systems, but we may also accept that libcs may imlpement getchar in different ways, and not all of them pass by the getc which we're patching.

Issues/PRs references

This is needed for testing #19289.

The implementation stems from the fgetc(3) man page, which states that "getchar() is equivalent to getc(stdin)".

This ensures that even when libc does not implement getchar through
getc, any custom stdio is still in the loop when getchar is used.
@chrysn chrysn requested a review from benpicco February 27, 2023 20:00
@chrysn chrysn added Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Platform: native Platform: This PR/issue effects the native platform labels Feb 27, 2023
@github-actions github-actions bot added the Area: cpu Area: CPU/MCU ports label Feb 27, 2023
@chrysn chrysn added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Feb 27, 2023
@@ -308,6 +308,10 @@ int fgetc(FILE *fp)
return getc(fp);
}

int getchar(void) {
return getc(stdin);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this Linux stdin or RIOT stdin (which might be through a different stdio implementation)?

Copy link
Member Author

@chrysn chrysn Feb 27, 2023

Choose a reason for hiding this comment

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

I'm not sure, but either way, through getc this gets forwarded to _native_read, which runs if (fd == STDIN_FILENO) return stdio_read(buf, count);.

So as long as its fileno() is STDIN_FILENO, it's fine.

[edit: does RIOT even have a dedicated FILE * for stdin?]

@chrysn
Copy link
Member Author

chrysn commented Feb 27, 2023

Thanks

bors merge

@bors
Copy link
Contributor

bors bot commented Feb 27, 2023

🕐 Waiting for PR status (GitHub check) to be set, probably by CI. Bors will automatically try to run when all required PR statuses are set.

@riot-ci
Copy link

riot-ci commented Feb 27, 2023

Murdock results

✔️ PASSED

494942b native/stdio: Explicitly provide getchar

Success Failures Total Runtime
6864 0 6864 10m:46s

Artifacts

@chrysn
Copy link
Member Author

chrysn commented Feb 27, 2023

bors merge

@bors
Copy link
Contributor

bors bot commented Feb 27, 2023

Stopped waiting for PR status (GitHub check) without running due to duplicate requests to run. You may check Bors to see that this PR is included in a batch by one of the other requests.

@bors
Copy link
Contributor

bors bot commented Feb 28, 2023

Build succeeded:

@bors bors bot merged commit 302a809 into RIOT-OS:master Feb 28, 2023
@chrysn chrysn deleted the native-stdio branch February 28, 2023 14:03
@MrKevinWeiss MrKevinWeiss added this to the Release 2023.04 milestone Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: cpu Area: CPU/MCU ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: native Platform: This PR/issue effects the native platform Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants