wareck / cgminer-gekko

cgminer 4.12.1 with GekkoScience (Compac , 2pac , Newpac , R606 /R909 , CompacF) Also with Extranonce/nicehash support. Compatible with OpenWrt
Other
92 stars 39 forks source link

Cleaned up compiler errors and warnings building on macOS. #9

Closed chipjarred closed 3 years ago

chipjarred commented 3 years ago

libusb had some warnings due to deprecation of old macOS system features like OSAtomicIncrement32, and an ObjC runtime object registration function that now does nothing. I changed darwin_usb.c to conditionally compile out the latter if the target OS version is later than the deprecation (which it should mostly be since it was macOS 10.6, and were now on 11), and in the former case, if C99 is available changed it to use stdatomic's atomic_fetch_add. It was also warning on what amounted to assigning a pointer to NULL, but the particular form the NULL took was through a chain of typedefs.

driver-gekko still had those two functions that are defined to return void, but which didn't return anything at all. Clang continued to warn on that, and after some investigation to find out what the C standard actually says for that situation, it turns out to be undefined behavior. Those functions are being passed to thr_info_create as callbacks, and it does appear to take a pointer to a function that returns a void. I don't know what the correct value to return is, but invoking undefined behavior can't be the right approach, so changed them to return NULL with a big comment marked "FIXME" so they can be easily located to change to the correct return value, if it shouldn't be NULL.

I also fixed an uninitialized variable that was set in an "if...else if" statement, but if neither condition were true would remain uninitialized. I also modified the test in that same function that used abs on unsigned integers which clang was warning about. Basically instead of doing a subtraction inside abs() on the left side of the comparisons, which could overflow (would be negative if it were signed arithmetic, but since it's unsigned it would overflow), I moved it to addition on the right, and removed the abs. So basically abs(x - y) > z, became x > (z + y)

BTW - I see that you made the changes I suggested in the issue I opened a while back. Thank you!

chipjarred commented 3 years ago

I've fixed the literal that I was using to test for C11. I'm unsure of whether I need to close this pull request and open anoth

wareck commented 3 years ago

Hi thanks for your work I merge the changes

chipjarred commented 3 years ago

You're welcome, though as I noted in a in-code comment I had used the wrong numeric literal to check for C11 in darwin_usb.c. I fixed that, but then discovered that it was still using C99, so I had to update configure.ac to use C11. That triggered an error from using the typeof compiler extension, which I also fixed. So there's another quick pull request coming. It's funny because I was typing the comment for that pull request when I got notification that the changes had already been merged.