fastfetch-cli / fastfetch

An actively maintained, feature-rich and performance oriented, neofetch like system information tool.
MIT License
8.08k stars 349 forks source link

[BUG] Syntax in `bluetooth_apple.m` needs a fix: `bluetooth_apple.m: error: expected '>' before '*' token` #943

Closed barracuda156 closed 1 month ago

barracuda156 commented 1 month ago

Bluetooth code does not compile on legacy macOS:

/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m: In function 'ffDetectBluetooth':
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:7:30: error: expected '>' before '*' token
    7 |     NSArray<IOBluetoothDevice*>* ioDevices = IOBluetoothDevice.pairedDevices;
      |                              ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:7:5: error: cannot find protocol declaration for 'IOBluetoothDevice'
    7 |     NSArray<IOBluetoothDevice*>* ioDevices = IOBluetoothDevice.pairedDevices;
      |     ^~~~~~~
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:8:9: error: 'ioDevices' undeclared (first use in this function); did you mean 'devices'?
    8 |     if(!ioDevices)
      |         ^~~~~~~~~
      |         devices
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:8:9: note: each undeclared identifier is reported only once for each function it appears in
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:14:46: error: request for member 'name' in something not a structure or union
   14 |         ffStrbufInitS(&device->name, ioDevice.name.UTF8String);
      |                                              ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:15:49: error: request for member 'addressString' in something not a structure or union
   15 |         ffStrbufInitS(&device->address, ioDevice.addressString.UTF8String);
      |                                                 ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:19:20: error: request for member 'serviceClassMajor' in something not a structure or union
   19 |         if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorLimitedDiscoverableMode)
      |                    ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:21:20: error: request for member 'serviceClassMajor' in something not a structure or union
   21 |         if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorReserved1)
      |                    ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:23:20: error: request for member 'serviceClassMajor' in something not a structure or union
   23 |         if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorReserved2)
      |                    ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:25:20: error: request for member 'serviceClassMajor' in something not a structure or union
   25 |         if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorPositioning)
      |                    ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:27:20: error: request for member 'serviceClassMajor' in something not a structure or union
   27 |         if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorNetworking)
      |                    ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:29:20: error: request for member 'serviceClassMajor' in something not a structure or union
   29 |         if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorRendering)
      |                    ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:31:20: error: request for member 'serviceClassMajor' in something not a structure or union
   31 |         if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorCapturing)
      |                    ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:33:20: error: request for member 'serviceClassMajor' in something not a structure or union
   33 |         if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorObjectTransfer)
      |                    ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:35:20: error: request for member 'serviceClassMajor' in something not a structure or union
   35 |         if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorAudio)
      |                    ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:37:20: error: request for member 'serviceClassMajor' in something not a structure or union
   37 |         if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorTelephony)
      |                    ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:39:20: error: request for member 'serviceClassMajor' in something not a structure or union
   39 |         if(ioDevice.serviceClassMajor & kBluetoothServiceClassMajorInformation)
      |                    ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:44:28: error: request for member 'deviceClassMajor' in something not a structure or union
   44 |             switch(ioDevice.deviceClassMajor)
      |                            ^
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/cursor/cursor_apple.m: In function 'ffDetectCursor':
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/cursor/cursor_apple.m:25:40: warning: 'NSDictionary' may not respond to '+dictionaryWithContentsOfURL:error:'
   25 |                                        error:&error];
      |                                        ^~~~~
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/cursor/cursor_apple.m:25:40: warning: (messages without a matching method signature will be assumed to return 'id' and accept '...' as arguments)
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:67:22: error: 'kBluetoothDeviceClassMajorWearable' undeclared (first use in this function); did you mean 'kBluetoothDeviceClassMajorNone'?
   67 |                 case kBluetoothDeviceClassMajorWearable:
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                      kBluetoothDeviceClassMajorNone
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:70:22: error: 'kBluetoothDeviceClassMajorToy' undeclared (first use in this function); did you mean 'kBluetoothDeviceClassMajorAny'?
   70 |                 case kBluetoothDeviceClassMajorToy:
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                      kBluetoothDeviceClassMajorAny
/opt/local/var/macports/build/_opt_PPCSnowLeopardPorts_sysutils_fastfetch/fastfetch/work/fastfetch-2.12.0/src/detection/bluetooth/bluetooth_apple.m:73:22: error: 'kBluetoothDeviceClassMajorHealth' undeclared (first use in this function); did you mean 'kBluetoothDeviceClassMajorEnd'?
   73 |                 case kBluetoothDeviceClassMajorHealth:
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                      kBluetoothDeviceClassMajorEnd
make[2]: *** [CMakeFiles/libfastfetch.dir/src/detection/bluetooth/bluetooth_apple.m.o] Error 1

It seems that syntax used to create an array is wrong, and then constructs like ioDevice.something do not work.

barracuda156 commented 1 month ago

@CarterLi This actually should be pretty easily fixable, since the framework headers have almost everything needed, but the syntax does not work. I can't fix it rightaway though, since this is ObjC.

It looks like array creation code from here is fine: https://github.com/toy/blueutil/blob/main/blueutil.m But I still get some errors in this module.

CarterLi commented 1 month ago

As documented in README, We officially support macOS only, not Mac OS X, nor OS X. 10.6 is Mac OS X not macOS I guess.

I'm not a big fun of obj-c syntax already. Rewriting existing code with older obj-c standard is BIG no to me. I think there won't be these questions if I wrote this in Swift before.

Again, if you want this compiling, guard it with #ifndef.

barracuda156 commented 1 month ago

@CarterLi Sure, there is obligation implied whatsoever. I will see if I can fix it.

Thanks for merging other fix-ups!

barracuda156 commented 1 month ago

@CarterLi I have kinda fixed the build of 2.12.0 (not neatly at the moment), however it fails to run:

(gdb) run
Starting program: /opt/local/bin/fastfetch 
Reading symbols for shared libraries ++++++++++++++++..................................................................... done
Reading symbols for shared libraries . done
2024-05-20 09:46:40.803 fastfetch[69901:c13] *** __NSAutoreleaseNoPool(): Object 0x5c0b0b0 of class NSURL autoreleased with no pool in place - just leaking
2024-05-20 09:46:40.806 fastfetch[69901:c13] *** __NSAutoreleaseNoPool(): Object 0x5c0b3c0 of class NSCFString autoreleased with no pool in place - just leaking
2024-05-20 09:46:40.806 fastfetch[69901:c13] +[NSDictionary dictionaryWithContentsOfURL:error:]: unrecognized selector sent to class 0x3d18d0
2024-05-20 09:46:40.807 fastfetch[69901:c13] *** __NSAutoreleaseNoPool(): Object 0x5c0b400 of class NSCFString autoreleased with no pool in place - just leaking
2024-05-20 09:46:40.807 fastfetch[69901:c13] *** __NSAutoreleaseNoPool(): Object 0x5c0b4c0 of class NSException autoreleased with no pool in place - just leaking
2024-05-20 09:46:40.808 fastfetch[69901:c13] *** __NSAutoreleaseNoPool(): Object 0x5c0cbb0 of class _NSCallStackArray autoreleased with no pool in place - just leaking
2024-05-20 09:46:40.809 fastfetch[69901:c13] *** __NSAutoreleaseNoPool(): Object 0x5c0cb70 of class _NSCallStackArray autoreleased with no pool in place - just leaking
2024-05-20 09:46:40.810 fastfetch[69901:c13] *** __NSAutoreleaseNoPool(): Object 0x5c0d4a0 of class NSCFString autoreleased with no pool in place - just leaking
2024-05-20 09:46:40.810 fastfetch[69901:c13] *** __NSAutoreleaseNoPool(): Object 0x6037000 of class NSCFString autoreleased with no pool in place - just leaking
2024-05-20 09:46:40.811 fastfetch[69901:c13] *** __NSAutoreleaseNoPool(): Object 0x5c0dfa0 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2024-05-20 09:46:40.811 fastfetch[69901:c13] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithContentsOfURL:error:]: unrecognized selector sent to class 0x3d18d0'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x002e0430 __raiseError + 144
    1   libobjc.A.dylib                     0x009dd968 objc_exception_throw + 72
    2   CoreFoundation                      0x0035ba8c +[__NSPlaceholderOrderedSet immutablePlaceholder] + 0
    3   CoreFoundation                      0x002cfc48 ___forwarding___ + 380
    4   CoreFoundation                      0x002cf9f8 _CF_forwarding_prep_0 + 216
    5   fastfetch                           0x0006fa18 ffDetectOSImpl + 96
    6   fastfetch                           0x00011dd4 ffDetectOS + 132
    7   fastfetch                           0x00016264 logoGetBuiltinDetected + 32
    8   fastfetch                           0x00016814 logoPrintDetected + 16
    9   fastfetch                           0x0000c240 ffStart + 380
    10  fastfetch                           0x00103128 main + 500
    11  fastfetch                           0x00006b68 start + 68
    12  fastfetch                           0x00001000 __dso_handle + 0
)

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0031b548 in ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___ ()
(gdb) bt
#0  0x0031b548 in ___TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION___ ()
#1  0x009dd968 in objc_exception_throw ()
#2  0x0035ba8c in +[NSObject doesNotRecognizeSelector:] ()
#3  0x002cfc48 in ___forwarding___ ()
#4  0x002cf9f8 in __forwarding_prep_0___ ()
#5  0x0006fa18 in ffDetectOSImpl ()
#6  0x00011dd4 in ffDetectOS ()
#7  0x00016264 in logoGetBuiltinDetected ()
#8  0x00016814 in logoPrintDetected ()
#9  0x0000c240 in ffStart ()
#10 0x00103128 in main ()

I thought I have done something wrong with patching, however I have tried to build now 1.7.2 (which required no patches besides a trivial missing define for OpenGL and removal of OpenCL module, i.e. no hacking the code itself), and it gives a logo on start, but still crashes with the same error:

2024-05-20 16:52:29.873 fastfetch[19955:10b] *** __NSAutoreleaseNoPool(): Object
2024-05-20 16:52:29.876 fastfetch[19955:10b] -[NSCFData _getCString:maxLength:en
2024-05-20 16:52:29.876 fastfetch[19955:10b] *** __NSAutoreleaseNoPool(): Object
2024-05-20 16:52:29.877 fastfetch[19955:10b] *** __NSAutoreleaseNoPool(): Object
2024-05-20 16:52:29.879 fastfetch[19955:10b] *** __NSAutoreleaseNoPool(): Object
2024-05-20 16:52:29.880 fastfetch[19955:10b] *** __NSAutoreleaseNoPool(): Object
2024-05-20 16:52:29.881 fastfetch[19955:10b] *** __NSAutoreleaseNoPool(): Object
2024-05-20 16:52:29.881 fastfetch[19955:10b] *** __NSAutoreleaseNoPool(): Object
2024-05-20 16:52:29.882 fastfetch[19955:10b] *** __NSAutoreleaseNoPool(): Object
2024-05-20 16:52:29.883 fastfetch[19955:10b] *** Terminating app due to uncaught
*** Call stack at first throw:
(
    0   CoreFoundation                      0x002e0430 __raiseError + 144
    1   libobjc.A.dylib                     0x008fb968 objc_exception_throw 
    2   CoreFoundation                      0x0035b9f0 +[NSObject doesNotRec
    3   CoreFoundation                      0x002cfc48 ___forwarding___ + 38
    4   CoreFoundation                      0x002cf9f8 _CF_forwarding_prep_0
    5   CoreFoundation                      0x0028f9a4 CFStringGetCString + 
    6   fastfetch                           0x00018b2c ffDetectGPUImpl + 412
    7   fastfetch                           0x00012358 ffDetectGPU + 100
    8   fastfetch                           0x000166b8 ffPrintGPU + 108
    9   fastfetch                           0x0002bc40 main + 1420
    10  fastfetch                           0x000034a4 start + 68
    11  fastfetch                           0x00001000 __dso_handle + 0
)
zsh: trace trap  /opt/local/bin/fastfetch

So while it is quite probable my local patches to ObjC stuff are to be improved, the segfaul seems independent of those. It is also not caused by any recent switches from C to ObjC code is Apple-related modules (those postdate 1.7.2).

Maybe you could suggest what may be failing? I am not asking to waste time fixing it, I can deal with that on my end, just give an opinion, since you know both the code and ObjC much better.

CarterLi commented 1 month ago

Seems one of ffCfDictGetString crashed. I'm not sure. Since you are working on it, why not debug it locally?

barracuda156 commented 1 month ago

Yes, I will 👍