Repository: pandas-dev/pandas

Issue:
Building latest master fails in Anaconda Python 3.3 environment on RedHat 
Checked out a2a7a5f85dd25f05f7d3b813d15dc0f1ecc45fa2, `python3 setup.py build` fails with: 

```
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Ipandas/src/ujson/python -Ipandas/src/ujson/lib -Ipandas/src/datetime -Ipandas/src/klib -Ipandas/src -I/home/me/anaconda/envs/py33/lib/python3.3/site-packages/numpy/core/include -I/home/me/anaconda/envs/py33/include/python3.3m -c pandas/src/ujson/lib/ultrajsonenc.c -o build/temp.linux-x86_64-3.3/pandas/src/ujson/lib/ultrajsonenc.o
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -Ipandas/src/ujson/python -Ipandas/src/ujson/lib -Ipandas/src/datetime -Ipandas/src/klib -Ipandas/src -I/home/me/anaconda/envs/py33/lib/python3.3/site-packages/numpy/core/include -I/home/me/anaconda/envs/py33/include/python3.3m -c pandas/src/ujson/lib/ultrajsondec.c -o build/temp.linux-x86_64-3.3/pandas/src/ujson/lib/ultrajsondec.o
pandas/src/ujson/lib/ultrajsondec.c: In function ‘decode_numeric’:
pandas/src/ujson/lib/ultrajsondec.c:119: error: ‘LLONG_MAX’ undeclared (first use in this function)
pandas/src/ujson/lib/ultrajsondec.c:119: error: (Each undeclared identifier is reported only once
pandas/src/ujson/lib/ultrajsondec.c:119: error: for each function it appears in.)
pandas/src/ujson/lib/ultrajsondec.c:125: error: ‘LLONG_MIN’ undeclared (first use in this function)
error: command 'gcc' failed with exit status 1
```

NB: Building da14c6e857fd1fc7875cd552779a6063ec9e4ddc worked fine yesterday on Ubuntu 12.04, otherwise the same environment



Discussion:
cc @Komnomnomnom

Hi @hmgaudecker is this a 32 or 64 bit machine, anything special about your architecture?

@hmgaudecker  also what version of gcc are you on? (`gcc --version` in a terminal).

```
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

Should be a 64-bit machine. Nothing special that I would be aware of, built lots of things on it and never had any special issues.

A quick google turned up this one, haven't checked in detail but looks like it is the same thing: https://github.com/esnme/ultrajson/pull/66

@hmgaudecker can u try putting the `extra_compile_args=['-D_GNU_SOURCE']` argument in the `setup` function in `setup.py`?

i have a red hat machine that i can test this on

@cpcloud try the inline code fix instead

@jreback do u mean the one that just defines the macros?

yes

seems like that might break something. on my system those macros are only defined if you're using iso c99 or u try to use it and you're using gcc but they haven't been defined... maybe that's an issue here?

it should be done in a conditional define only for CentOS

we can test with vagrant...they have [some centos boxes](http://www.vagrantbox.es/). the following code builds and runs correctly on a recent fedora with the same compiler flags minus the includes

``` c
#include <stdio.h>
#include <limits.h>
int main(int argc, const char* argv[]) {
    printf("%lli\n", LLONG_MAX);
    return 0;
}
```

i can also confirm that pandas builds correctly on fedora, but the `-D_GNU_SOURCE` flag is passed...

@hmgaudecker looks like you're using [an unsupported version of redhat](https://rhn.redhat.com/errata/RHSA-2012-0073.html) and a really old version of gcc. any reason for either of those?

personally, i think neither pandas nor ujson should try to hack around a 5 year old compiler and an [8 year old OS](http://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux#RHEL_4)

Yes -- it's a machine where some sensitive data lives, no way I can change anything in that respect... 

I could live with a hack around this, though -- if it only amounts to changing a line in setup.py, no big deal. 

i think changing `setup.py` is the path of least resistance but others might feel different. changing ujson c code to support such a rare legacy case doesn't seem appropriate since you can probably just add the compiler flag in `setup.py` and not worry about breaking things later on

so you can't upgrade your compiler? i understand that u can't upgrade the whole os. just want to clarify

@hmgaudecker were you ever able to build any of pandas versions with ujson on ur RHEL box?

I don't have admin rights and I am in no position to convince the admins to do much about it (it is maintained by an organisation not related to my own University). And I'd rather change a line than compile gcc myself... Everything seems to work fine with the following:

``` python
ujson_ext = Extension('pandas.json',
                      depends=['pandas/src/ujson/lib/ultrajson.h'],
                      sources=['pandas/src/ujson/python/ujson.c',
                               'pandas/src/ujson/python/objToJSON.c',
                               'pandas/src/ujson/python/JSONtoObj.c',
                               'pandas/src/ujson/lib/ultrajsonenc.c',
                               'pandas/src/ujson/lib/ultrajsondec.c',
                               'pandas/src/datetime/np_datetime.c',
                               'pandas/src/datetime/np_datetime_strings.c'],
                      include_dirs=['pandas/src/ujson/python',
                                    'pandas/src/ujson/lib',
                                    'pandas/src/datetime'] + common_include,
                      extra_compile_args=['-D_GNU_SOURCE']
)
```

i think that's probably the way to go. need to test this on mac and windows too...

didn't affect build on windows / debian linux......let's make a PR and add that in

@cpcloud the setup.py arg of `-DGNU_SOURCE` is how ultrajson fixed it aswell according to https://github.com/esnme/ultrajson/pull/66, so it makes sense to do the same here. 


Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -482,7 +482,8 @@ def pxd(name):
                                'pandas/src/datetime/np_datetime_strings.c'],
                       include_dirs=['pandas/src/ujson/python',
                                     'pandas/src/ujson/lib',
-                                    'pandas/src/datetime'] + common_include)
+                                    'pandas/src/datetime'] + common_include,
+                      extra_compile_args=['-D_GNU_SOURCE'])
 
 
 extensions.append(ujson_ext)


Test patch: