fix: Log Macro will print to console twice if no log_file was given w…#122
Open
chuguo01 wants to merge 1 commit into
Open
fix: Log Macro will print to console twice if no log_file was given w…#122chuguo01 wants to merge 1 commit into
chuguo01 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
老师您好。
在学习为NPC搭建基础设施时,很自然地想到复用NEMU中的基础设施,于是选择性地将部分NEMU的源文件与NPC一起编译。在移植
log.c的过程中,发现当日志文件没有在命令行中被指定,即log_fp被设置为stdout时,后续Log宏都会被打印两遍,此事在之前的双周分享会中亦有记载:【可不可以优雅地复用NEMU的代码 - 任勤博 - 一生一芯双周分享会】 https://www.bilibili.com/video/BV168DHY8EtJ
原因应该是
printf打印了一遍,fprintf又向指向stdout的stream打了一遍。修复过程中,尝试了在
log_write(...)的判断条件中加入:log_fp != stdout!isatty(fileno(fp))来让
log_fp指向stdout时只输出一次,均会触发段错误,具体原理暂时未知。目前的处理方式是权宜之计,应该会有更好的解决方案。
感谢阅读。