Skip to content

build fails with clang, python3 and numpy 1.7.1 and higher #3872

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

Closed
selasley opened this issue Jun 12, 2013 · 16 comments · Fixed by #3874 or #3936
Closed

build fails with clang, python3 and numpy 1.7.1 and higher #3872

selasley opened this issue Jun 12, 2013 · 16 comments · Fixed by #3874 or #3936
Labels
Build Library building on various platforms
Milestone

Comments

@selasley
Copy link
Contributor

The build succeeds if I change
void initObjToJSON(void)
to
int initObjToJSON(void)
in objToJSON.c, but I don't know if there are repercussions. I haven't tested with numpy 1.7 and lower.


$ git log
commit 51cc9d9
...
$ python3 -c "import numpy;print(numpy.version)"
1.7.1
(also fails with 1.8.0.dev-f7ea474)
$ python3 setup.py build
...
pandas/src/ujson/python/objToJSON.c:118:5: error: void function 'initObjToJSON' should not return a value [-Wreturn-type]
import_array();
^~~~~~~~~~~~~~
/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/numpy/core/include/numpy/__multiarray_api.h:1693:144: note: expanded from macro 'import_array'
#define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }


from generate_numpy_api.py

if PY_VERSION_HEX >= 0x03000000

define NUMPY_IMPORT_ARRAY_RETVAL NULL

else

define NUMPY_IMPORT_ARRAY_RETVAL

endif

define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }

@cpcloud
Copy link
Member

cpcloud commented Jun 12, 2013

make ur change, run the full test suite, push to travis submit a PR and then it'll probably get merged if that passes. the first error is the one that matters here the numpy stuff is unrelated. returning a value from a void function is undefined and thus the compiler rightly fails

@cpcloud
Copy link
Member

cpcloud commented Jun 12, 2013

although i don't get this bug...clang can sometimes be very strict with it's warnings/errors...

@cpcloud
Copy link
Member

cpcloud commented Jun 13, 2013

oh i c. this is what happens when c macros look like functions....the pp is rewriting a return statement in there and clang is pickier than gcc...

@cpcloud
Copy link
Member

cpcloud commented Jun 13, 2013

@selasley can u try my fix? i don't have an reasonable way to use clang i would have to recompile python plus all of the deps that require cython so that's a bit prohibitive...

@selasley
Copy link
Contributor Author

Sorry, I was away from the computer for a while. It builds with your change with python3, but I get an error trying to build with clang and python 2.7

pandas/src/ujson/python/objToJSON.c:118:5: error: non-void function 'initObjToJSON' should return a value [-Wreturn-type]
import_array();
^
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/include/numpy/__multiarray_api.h:1678:144: note: expanded from macro 'import_array'
#define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }


I think the problem arises from this section of generate_numpy_api.py

#if PY_VERSION_HEX >= 0x03000000
#define NUMPY_IMPORT_ARRAY_RETVAL NULL
#else
#define NUMPY_IMPORT_ARRAY_RETVAL
#endif

#define import_array() {if (_import_array() < 0) {PyErr_Print(); PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import"); return NUMPY_IMPORT_ARRAY_RETVAL; } }

So under python 3 import_array() returns NULL and under python 2 it returns no value. Maybe the change should be

#if (PY_VERSION_HEX < 0x03000000)
void initObjToJSON(void)
#else
int initObjToJSON(void)
#endif
{
PyObject *mod_frame;
PyDateTime_IMPORT;

I was able to build pandas with clang and python 2.7 and 3.3.2 on my mac running OS X 10.8 with this change. This is my first time forking pandas and trying to use Travis following the CONTRIBUTING docs. I think it built OK - https://travis-ci.org/selasley/pandas/builds/8039302

@cpcloud
Copy link
Member

cpcloud commented Jun 13, 2013

return type should probably be some kind of pointer maybe void * since it's returning NULL...i'm not sure ... maybe whoever wrote this can comment or fix it i'm not sure who taht is though...

@cpcloud
Copy link
Member

cpcloud commented Jun 13, 2013

i pushed that fix, we'll see what happens

@selasley
Copy link
Contributor Author

good catch. clang did issue a warning
warning: incompatible pointer to integer conversion returning 'void *' from a function with result type 'int'
but I missed it. pandas builds with clang and python 3 when initObjToJSON returns a void *
Thanks for your help.

@cpcloud
Copy link
Member

cpcloud commented Jun 13, 2013

i'll leave as int since NULL will be cast to 0 anyway.

@wesm
Copy link
Member

wesm commented Jun 15, 2013

merge the PR and close this one? OK with me if Kieran is OK with the PR

@jreback
Copy link
Contributor

jreback commented Jun 17, 2013

apparently 2.7 on clang is giving the same issue

maybe this is a compiler issue (rather than a version issue)?

anyone on mac can test?

https://groups.google.com/forum/?fromgroups=#!topic/pydata/8oq0ErM8_eE

@jreback jreback reopened this Jun 17, 2013
@jreback
Copy link
Contributor

jreback commented Jun 17, 2013

cc @rhstanton

@cpcloud
Copy link
Member

cpcloud commented Jun 17, 2013

no the patch i submitted is wrong crap sorry will fix

@cpcloud
Copy link
Member

cpcloud commented Jun 17, 2013

@selasley can u test?

@cpcloud
Copy link
Member

cpcloud commented Jun 17, 2013

u can do

git remote add upstream git://github.com/pydata/pandas
git fetch upstream
git checkout upstream/pr/3936

to get the pr

@selasley
Copy link
Contributor Author

On Jun 17, 2013, at 4:06 PM, Phillip Cloud [email protected] wrote:

@selasley can u test?

My access to computers is sporadic for the next several days. I was able to build the latest from github, 964516a, with clang-425.0.28 and python 3.3.2 and 2.7.4 under OS X 10.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Build Library building on various platforms
Projects
None yet
4 participants