Skip to content

Conversation

@CarterLi
Copy link
Member

image

@CarterLi
Copy link
Member Author

Apple Terminal ( I don't really use ):

image

Copy link
Collaborator

@LinusDierheimer LinusDierheimer left a comment

Choose a reason for hiding this comment

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

Can we move terminal detection to src/detection (similar to GPU)? A terminal.c file for common code, and terminal_<platform>.c for each platform.

And according to Apple Developer Documentation, we need to add -fconstant-cfstrings to our cflags if using the CFSTR macro. Does cmake do this, or do we need to do this our self (or emit the usage and rely on standard c)?

@CarterLi
Copy link
Member Author

Question: why don't we have something like ffStrbufInitCopyS(FFstrbuf* buf, const char* str)?

@CarterLi
Copy link
Member Author

Can we move terminal detection to src/detection (similar to GPU)? A terminal.c file for common code, and terminal_<platform>.c for each platform.

I don't get it. We have had src/detection/terminalShell.c

And according to Apple Developer Documentation, we need to add -fconstant-cfstrings to our cflags if using the CFSTR macro. Does cmake do this, or do we need to do this our self (or emit the usage and rely on standard c)?

I don't know. It was my first time to use those CF* stuff. The compiler didn't emit any compile / link errors though.

@CarterLi
Copy link
Member Author

Just tried -fsanitize=leak

==39455==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 32816 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x7f77a886eed4 in __alloc_dir (/lib64/libc.so.6+0xd8ed4)

Direct leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x4586c5 in ffPrintPublicIp /home/parallels/fastfetch/src/modules/publicip.c:11
    #3 0x40f3ab in parseStructureCommand /home/parallels/fastfetch/src/fastfetch.c:1390
    #4 0x40f912 in main /home/parallels/fastfetch/src/fastfetch.c:1441
    #5 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 912 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x416fb1 in ffListInitA /home/parallels/fastfetch/src/util/FFlist.c:15
    #2 0x416d69 in ffListInit /home/parallels/fastfetch/src/util/FFlist.c:7
    #3 0x417a22 in ffValuestoreInit /home/parallels/fastfetch/src/util/FFvaluestore.c:9
    #4 0x40f6dd in main /home/parallels/fastfetch/src/fastfetch.c:1420
    #5 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 512 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a9083595 in __interceptor_realloc.part.0 (/lib64/libasan.so.8+0xb9595)
    #1 0x410059 in ffStrbufEnsureFree /home/parallels/fastfetch/src/util/FFstrbuf.c:58
    #2 0x410a8f in ffStrbufAppendS /home/parallels/fastfetch/src/util/FFstrbuf.c:100
    #3 0x41299d in ffStrbufSetS /home/parallels/fastfetch/src/util/FFstrbuf.c:214
    #4 0x406240 in optionParseString /home/parallels/fastfetch/src/fastfetch.c:599
    #5 0x409050 in parseOption /home/parallels/fastfetch/src/fastfetch.c:946
    #6 0x405c12 in parseConfigFile /home/parallels/fastfetch/src/fastfetch.c:518
    #7 0x405e00 in optionParseConfigFile /home/parallels/fastfetch/src/fastfetch.c:538
    #8 0x4079af in parseOption /home/parallels/fastfetch/src/fastfetch.c:839
    #9 0x40eb29 in parseArguments /home/parallels/fastfetch/src/fastfetch.c:1316
    #10 0x40f787 in main /home/parallels/fastfetch/src/fastfetch.c:1426
    #11 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 288 byte(s) in 9 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x40fa00 in ffStrbufInit /home/parallels/fastfetch/src/util/FFstrbuf.c:12
    #3 0x419a2a in defaultConfig /home/parallels/fastfetch/src/common/init.c:134
    #4 0x41bd45 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:239
    #5 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 256 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x416fb1 in ffListInitA /home/parallels/fastfetch/src/util/FFlist.c:15
    #2 0x416d69 in ffListInit /home/parallels/fastfetch/src/util/FFlist.c:7
    #3 0x417eaa in initConfigDirs /home/parallels/fastfetch/src/common/init.c:21
    #4 0x4197be in initState /home/parallels/fastfetch/src/common/init.c:118
    #5 0x41bd39 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:238
    #6 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #7 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 128 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x450fe3 in ffPrintCPU /home/parallels/fastfetch/src/modules/cpu.c:23
    #3 0x40f1bc in parseStructureCommand /home/parallels/fastfetch/src/fastfetch.c:1372
    #4 0x40f912 in main /home/parallels/fastfetch/src/fastfetch.c:1441
    #5 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x41909f in initCacheDir /home/parallels/fastfetch/src/common/init.c:88
    #3 0x4197ca in initState /home/parallels/fastfetch/src/common/init.c:119
    #4 0x41bd39 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:238
    #5 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x43a7c2 in ffDetectTemps /home/parallels/fastfetch/src/detection/temps.c:83
    #3 0x46045b in detectCPUTemp /home/parallels/fastfetch/src/detection/cpu/cpu_linux.c:65
    #4 0x460ac1 in ffDetectCPUImpl /home/parallels/fastfetch/src/detection/cpu/cpu_linux.c:99
    #5 0x43b3a6 in ffDetectCPU /home/parallels/fastfetch/src/detection/cpu/cpu.c:8
    #6 0x450d5f in ffPrintCPU /home/parallels/fastfetch/src/modules/cpu.c:14
    #7 0x40f1bc in parseStructureCommand /home/parallels/fastfetch/src/fastfetch.c:1372
    #8 0x40f912 in main /home/parallels/fastfetch/src/fastfetch.c:1441
    #9 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x418684 in initConfigDirs /home/parallels/fastfetch/src/common/init.c:49
    #3 0x4197be in initState /home/parallels/fastfetch/src/common/init.c:118
    #4 0x41bd39 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:238
    #5 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x40fa00 in ffStrbufInit /home/parallels/fastfetch/src/util/FFstrbuf.c:12
    #3 0x443641 in ffPrintPackages /home/parallels/fastfetch/src/modules/packages.c:431
    #4 0x40eedc in parseStructureCommand /home/parallels/fastfetch/src/fastfetch.c:1348
    #5 0x40f912 in main /home/parallels/fastfetch/src/fastfetch.c:1441
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x40fa00 in ffStrbufInit /home/parallels/fastfetch/src/util/FFstrbuf.c:12
    #3 0x43f04d in ffPrintHost /home/parallels/fastfetch/src/modules/host.c:23
    #4 0x40ee00 in parseStructureCommand /home/parallels/fastfetch/src/fastfetch.c:1340
    #5 0x40f912 in main /home/parallels/fastfetch/src/fastfetch.c:1441
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x40fa00 in ffStrbufInit /home/parallels/fastfetch/src/util/FFstrbuf.c:12
    #3 0x419d50 in defaultConfig /home/parallels/fastfetch/src/common/init.c:141
    #4 0x41bd45 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:239
    #5 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x40fa00 in ffStrbufInit /home/parallels/fastfetch/src/util/FFstrbuf.c:12
    #3 0x419e02 in defaultConfig /home/parallels/fastfetch/src/common/init.c:144
    #4 0x41bd45 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:239
    #5 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x40fa00 in ffStrbufInit /home/parallels/fastfetch/src/util/FFstrbuf.c:12
    #3 0x419da9 in defaultConfig /home/parallels/fastfetch/src/common/init.c:142
    #4 0x41bd45 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:239
    #5 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Direct leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x40fa00 in ffStrbufInit /home/parallels/fastfetch/src/util/FFstrbuf.c:12
    #3 0x4198fe in defaultConfig /home/parallels/fastfetch/src/common/init.c:131
    #4 0x41bd45 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:239
    #5 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x418df2 in initConfigDirs /home/parallels/fastfetch/src/common/init.c:79
    #3 0x4197be in initState /home/parallels/fastfetch/src/common/init.c:118
    #4 0x41bd39 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:238
    #5 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x418b75 in initConfigDirs /home/parallels/fastfetch/src/common/init.c:74
    #3 0x4197be in initState /home/parallels/fastfetch/src/common/init.c:118
    #4 0x41bd39 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:238
    #5 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x41837d in initConfigDirs /home/parallels/fastfetch/src/common/init.c:43
    #3 0x4197be in initState /home/parallels/fastfetch/src/common/init.c:118
    #4 0x41bd39 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:238
    #5 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f77a908468f in __interceptor_malloc (/lib64/libasan.so.8+0xba68f)
    #1 0x40fad2 in ffStrbufInitA /home/parallels/fastfetch/src/util/FFstrbuf.c:20
    #2 0x418005 in initConfigDirs /home/parallels/fastfetch/src/common/init.c:37
    #3 0x4197be in initState /home/parallels/fastfetch/src/common/init.c:118
    #4 0x41bd39 in ffInitInstance /home/parallels/fastfetch/src/common/init.c:238
    #5 0x40f6c9 in main /home/parallels/fastfetch/src/fastfetch.c:1416
    #6 0x7f77a87bf54f in __libc_start_call_main (/lib64/libc.so.6+0x2954f)

SUMMARY: AddressSanitizer: 39648 byte(s) leaked in 28 allocation(s).

Will investigate them later

@LinusDierheimer
Copy link
Collaborator

I don't get it. We have had src/detection/terminalShell.c

Sorry i meant terminal font, not just terminal.
To be more clear, I propose the following file structure:

src/detection/terminalFont/terminalFont.h // defines a FFTerminalFontResult struct and a method to obtain it
src/detection/terminalFont/terminalFont.c // common code
src/detection/terminalFont/terminalFont_<platform>.c // platform specific code
src/modules/terminalFont.c // UI logic

Question: why don't we have something like ffStrbufInitCopyS(FFstrbuf* buf, const char* str)?

I had a lot of init methods before (e.g. ffStrbufInitS), but i used most of them in only one place, so i removed most of them. If you need a new constructor, just write one. In general feel free to expand any API, if it makes code shorter / clearer etc.

I don't know. It was my first time to use those CF* stuff. The compiler didn't emit any compile / link errors though.

It is probably fine then. Maybe cmake already adds it, because we link CoreFoundation. Someone will complain if the program crashes because of it.

Will investigate them later

Thanks.

@CarterLi
Copy link
Member Author

I don't get it. We have had src/detection/terminalShell.c

Sorry i meant terminal font, not just terminal. To be more clear, I propose the following file structure:

src/detection/terminalFont/terminalFont.h // defines a FFTerminalFontResult struct and a method to obtain it
src/detection/terminalFont/terminalFont.c // common code
src/detection/terminalFont/terminalFont_<platform>.c // platform specific code
src/modules/terminalFont.c // UI logic

That requires a lot of code changes. Can we have this PR merged first?

Question: why don't we have something like ffStrbufInitCopyS(FFstrbuf* buf, const char* str)?

I had a lot of init methods before (e.g. ffStrbufInitS), but i used most of them in only one place, so i removed most of them. If you need a new constructor, just write one. In general feel free to expand any API, if it makes code shorter / clearer etc.

I saw a lot of ffStrbufInit following ffStrbufAppendS. Would be simpler to have ffStrbufInitS

@LinusDierheimer
Copy link
Collaborator

LinusDierheimer commented Sep 17, 2022

That requires a lot of code changes. Can we have this PR merged first?

Yes, i will do the refactoring myself.

I saw a lot of ffStrbufInit following ffStrbufAppendS. Would be simpler to have ffStrbufInitS

Yeah probably its time to reintroduce it...


Thanks for the PR!

@LinusDierheimer LinusDierheimer merged commit 051a043 into fastfetch-cli:master Sep 17, 2022
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