ZeroCM / zcm

Zero Communications and Marshalling
http://zerocm.github.io/zcm/
GNU Lesser General Public License v2.1
237 stars 69 forks source link

error: enum constant in boolean context #194

Closed sudhanvas closed 6 years ago

sudhanvas commented 6 years ago

While building master branch on Ubuntu 18.04 with gcc version 7.3.0, I see the following error pop out of here. It seems like pushIfRoom should return a bool; whereas, ZCM_EAGAIN is a specific return code.

In file included from ../zcm/blocking.cpp:5:0:
../zcm/util/threadsafe_queue.hpp: In instantiation of 'bool ThreadsafeQueue<Element>::pushIfRoom(Args&& ...) [with Args = {long unsig
ned int, const char*, unsigned int&, const unsigned char*&}; Element = Msg]':
../zcm/blocking.cpp:391:86:   required from here
../zcm/util/threadsafe_queue.hpp:76:43: error: enum constant in boolean context [-Werror=int-in-bool-context]
         if (!queue.hasFreeSpace()) return ZCM_EAGAIN;
                                           ^~~~~~~~~~

It's partly because all warnings being treated as errors during the build. I also see this for the same reason:

../tools/cpp/spy-lite/MsgDisplay.cpp: In function 'void msg_display(TypeDb&, const TypeMetadata&, void*, const MsgDisplayState&)':
../tools/cpp/spy-lite/MsgDisplay.cpp:213:26: error: 'index' may be used uninitialized in this function [-Werror=maybe-uninitialized]
             strnfmtappend(traversal, TRAVERSAL_BUFSZ, &traversal_used,
             ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                           "[%d]", index);
                           ~~~~~~~~~~~~~~
jbendes commented 6 years ago

Did you take a stab at fixing them? Seem like relatively straightforward issues to solve

sudhanvas commented 6 years ago

While I was able to fix the above errors, I bumped into the following from the Python bindings:

zcm/python/zcm.c: In function 'initzcm':
zcm/python/zcm.c:8543:5: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
     __Pyx_INCREF(((PyObject *)(&PyDict_Type)));
     ^~~~~~~~~~~~
zcm/python/zcm.c:8559:3: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   __Pyx_INCREF(((PyObject *)(&PyInt_Type)));
   ^~~~~~~~~~~~
cc1: all warnings being treated as errors

Any ideas on what the fix for this might be?

jbendes commented 6 years ago

Yea I'm not sure what that one is. It's somehow related to cython and the parsing of the python bindings into c. I'm not sure the exact error or how to get rid of it, but I'd guess the cython page would be a good place to start. They probably already know about it.

sudhanvas commented 6 years ago

Is there a way, in waf, to disable treating warnings as errors, in the meantime?

jbendes commented 6 years ago

Probably? Did you push up your fix to the first two issues? I can play around with it a bit, but I don't want to replicate work you already did!

jbendes commented 6 years ago

Yea nevermind i just fixed the first two issues that you mentioned. They were pretty small. The python one is not happening for me. Maybe you have a different python or cython version? What is the result of cython --version and python --version

sudhanvas commented 6 years ago

Cool, thanks! Yeah, I just didn't want to push up incomplete work.

Anyway, I've got Python 2.7.15rc1 and Cython version 0.28.3. Does that help?

sudhanvas commented 6 years ago

FYI, I'm building ZCM within Docker with Ubuntu 18.04 as the base image. It turns out that these warnings disappear when building with Ubuntu 16.04. These are the software versions Ubuntu 16.04 is using:

It seems like there's a MAJOR version difference in GCC and just a PATCH version difference in Python.

jbendes commented 6 years ago

Hmmm yea so we're definitely on different python, cython, and gcc versions. It is definitely all working on 16.04 (which is the most recent version of ubuntu it's been tested on). I also know it works with the following configuration: Cython version 0.23.4 Python 2.7.12 gcc 8.1.0

because that's what's currently on my laptop. I can try changing over to your cython version and see if anything changes.

jbendes commented 6 years ago

So I was able to replicate your issue. Hopefully will have a suggestion or patch here shortly

jbendes commented 6 years ago

okay i just pushed up a branch. Would you mind giving it a shot? Not sure why it fixes it, but seems to work for me! https://github.com/ZeroCM/zcm/tree/core-cython_fix

sudhanvas commented 6 years ago

Works for me too!

jbendes commented 6 years ago

Fixed in https://github.com/ZeroCM/zcm/pull/198