Skip to content
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

Cleaning conditional directives that break statements. #645

Open
wants to merge 4 commits into
base: bfgminer
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions adl.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ void init_adl(int nDevs)
int result, i, j, devices = 0, last_adapter = -1, gpu = 0, dummy = 0;
struct gpu_adapters adapters[MAX_GPUDEVICES], vadapters[MAX_GPUDEVICES];
bool devs_match = true;
bool test;

if (unlikely(pthread_mutex_init(&adl_lock, NULL))) {
applog(LOG_ERR, "Failed to init adl_lock in init_adl");
Expand Down Expand Up @@ -336,10 +337,11 @@ void init_adl(int nDevs)
if (i == j)
continue;
#ifdef WIN32
if (adapters[j].iBusNumber < adapters[i].iBusNumber)
test = adapters[j].iBusNumber < adapters[i].iBusNumber;
#else
if (adapters[j].iBusNumber > adapters[i].iBusNumber)
test = adapters[j].iBusNumber > adapters[i].iBusNumber;
#endif
if (test)
virtual_gpu++;
}
if (virtual_gpu != i) {
Expand Down
6 changes: 4 additions & 2 deletions driver-minergate.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ int minergate_open(const char * const devpath)
struct sockaddr_un sa = {
.sun_family = AF_UNIX,
};
bool test;
#ifdef UNIX_PATH_MAX
if (devpath_len >= UNIX_PATH_MAX)
test devpath_len >= UNIX_PATH_MAX;
Copy link
Owner

Choose a reason for hiding this comment

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

Pretty sure this is wrong?

#else
if (devpath_len >= sizeof(sa.sun_path))
test = devpath_len >= sizeof(sa.sun_path);
#endif
if (test)
Copy link
Owner

Choose a reason for hiding this comment

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

Wouldn't it be better to do:

#ifndef UNIX_PATH_MAX
    static const size_t UNIX_PATH_MAX = sizeof(sa.sun_path);
#endif

return -1;
const int fd = socket(PF_UNIX, SOCK_STREAM, 0);
strcpy(sa.sun_path, devpath);
Expand Down
5 changes: 3 additions & 2 deletions driver-x6500.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ void x6500_set_register(struct jtag_port *jp, uint8_t addr, uint32_t nv)
jtag_write(jp, JTAG_REG_DR, buf, 38);
jtag_run(jp);
#ifdef DEBUG_X6500_SET_REGISTER
if (x6500_get_register(jp, addr) != nv)
bool test x6500_get_register(jp, addr) != nv;
#else
if (0)
bool test = 0;
#endif
if (test)
{
applog(LOG_WARNING, "x6500_set_register failed %x=%08x", addr, nv);
goto retry;
Expand Down
6 changes: 4 additions & 2 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ static int keep_sockalive(SOCKETTYPE fd)
const int tcp_keepidle = 45;
const int tcp_keepintvl = 30;
int ret = 0;
bool unlikely_test;

if (unlikely(setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (const char *)&tcp_one, sizeof(tcp_one))))
ret = 1;
Expand All @@ -324,10 +325,11 @@ static int keep_sockalive(SOCKETTYPE fd)

if (!opt_delaynet)
#ifndef __linux
if (unlikely(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void *)&tcp_one, sizeof(tcp_one))))
unlikely_test = unlikely(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (const void *)&tcp_one, sizeof(tcp_one)));
#else /* __linux */
if (unlikely(setsockopt(fd, SOL_TCP, TCP_NODELAY, (const void *)&tcp_one, sizeof(tcp_one))))
unlikely_test = unlikely(setsockopt(fd, SOL_TCP, TCP_NODELAY, (const void *)&tcp_one, sizeof(tcp_one)));
#endif /* __linux */
if (unlikely_test)
Copy link
Owner

Choose a reason for hiding this comment

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

Doesn't the unlikely() need to be in the conditional?

Copy link
Owner

Choose a reason for hiding this comment

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

Also, this is broken. Notice the conditional on opt_delaynet before the #ifndef

You'll need to add braces when breaking up the one-liner.

ret = 1;

#ifdef __linux
Expand Down