-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Stream: add necessary flushes, removing unneeded IAR workaround #8331
Conversation
@Alex-EEE - Please review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to do BOTH the flush and the seek. Correct fix is what I said on the other PR:
However, as the actual problem is that Stream is reversing and should be fseeking, then that's the place for the fix. The simplest change should be to change the existing fflushes on entry to Stream's write functions to fseeks.
Also, the pull title doesn't remotely match the patch, and have we actually established what the point of the mbed_getc IAR 7 hack was anyway? I don't think we got to the bottom of what #770 was about in the previous PR. You need to properly justify the removal of that workaround, and that you've retested what the original issue was on IAR 7. (If we can figure it out). I'm not totally sure #770 was purely to workaround a problem caused by Stream's lack of fseek. It was something to do with unbuffered streams in general, I thought. Putting the fseeks in instead of flushes would be fine as-is. |
You are allowed in POSIX / ANSI C to read and write on the same stream, but you have to do an fseek in between read and write call (getc->fseek->putc) Thanks @Alex-EEE for sharing the fix: ARMmbed#7749 Added test case for verification of the behavior
3e3cb56
to
f79a354
Compare
I disagree, I think this does get to the bottom of #770. getc and putc weren't working before in IAR 7 b/c you were switching stream directions w/o making the POSIX mandated fseek. [ I guess this worked in gcc, etc b/c those compilers were more forgiving ]. The original fix was just a hack fix...it didn't address the underlying lack of fseek, but mucking with the IAR internal structure somehow make it work. This fix breaks in IAR 8 b/c that _FILE structure is ( appropriately ) hidden now, so the old fix can't see the members that it wants to mess with. As for removing the fflush...I don't know the answer to this one way or another, but if you switch directions before all the characters have been written out, do you lose those characters? Might you still need the flush before changing directions? |
Fix #770 was related to this issue #749. Test case added here should be good enough to verify the same fix. |
Ta @deepikabhavnani, that makes sense - this is killing the half of #770 that was to do with the lack of seek, but leaving the unbuffered stream bug workaround. I was thinking this reverted #770 entirely. Is that buffering bug still present in IAR 8?
No (assuming IAR isn't buggy). A seek is required to flush output if necessary - streams are not permitted to arbitrarily lose data. Anyway, the seek is going before the writes, not after. In the event of multiple back-to-back writes, ideally the seek would be a no-op (it doesn't have to flush). |
Title can still be clearer - this isn't to do with "loopback", this is fixing the way Also, this isn't really a fix, it's refactoring a fix - doing it properly rather than a tool-specific workaround. So good to have, but not the sort of thing that should be backported to 5.10.y. I can also imagine removal of |
Yes |
/morph build |
Build : SUCCESSBuild number : 3334 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 2966 |
Test : SUCCESSBuild number : 3142 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
This is a follow-up to PR ARMmbed#8331; fixing the Stream methods not covered there.
This is a follow-up to PR #8331; fixing the Stream methods not covered there.
Description
You are allowed in POSIX / ANSI C to read and write on the same stream, but you have to do an fseek in between. From the Linux man pages ( https://www.systutorials.com/docs/linux/man/3-fdopen/):
Thanks @Alex-EEE for sharing the fix: #7749
Resolves: #7571
Pull request type