[0.6.0] can't build C extensions on python 2.4?

Issue #1781 resolved
Former user created an issue

When building on a CentOS 5 platform (python 2.4), I get this error:

building 'sqlalchemy.cprocessors' extension
creating build/temp.linux-x86_64-2.4
creating build/temp.linux-x86_64-2.4/lib
creating build/temp.linux-x86_64-2.4/lib/sqlalchemy
creating build/temp.linux-x86_64-2.4/lib/sqlalchemy/cextension
gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fPIC -I/usr/include/python2.4 -c lib/sqlalchemy/cextension/processors.c -o build/temp.linux-x86_64-2.4/lib/sqlalchemy/cextension/processors.o
lib/sqlalchemy/cextension/processors.c: In function 'UnicodeResultProcessor_process':
lib/sqlalchemy/cextension/processors.c:186: error: 'Py_ssize_t' undeclared (first use in this function)
lib/sqlalchemy/cextension/processors.c:186: error: (Each undeclared identifier is reported only once
lib/sqlalchemy/cextension/processors.c:186: error: for each function it appears in.)
lib/sqlalchemy/cextension/processors.c:186: error: expected ';' before 'len'
lib/sqlalchemy/cextension/processors.c:191: error: 'len' undeclared (first use in this function)
error: command 'gcc' failed with exit status 1

Comments (7)

  1. Former user Account Deleted
    • changed component to engine
    • assigned issue to
    • changed milestone to 0.6.1

    (original author: ged) Hopefully fixed in 9f45612c63a723fb94be8ce3489973c1235a62d6. However, I cannot test it now as python2.4 is not easily installable on my current installation. Please update your copy to the latest tip and test it and close this ticket if it works. Thanks in advance.

  2. Mike Bayer repo owner

    keeping in mind that my python2.4 is somewhat hosed for native builds, so ignoring the OSX deployment target messages, below is what I get. Note that I can reproduce the above error exactly if I use the hg version right before your fix.

    214:sqlalchemy classic$ python2.4 setup.py --with-cextensions build_ext
    running build_ext
    building 'sqlalchemy.cprocessors' extension
    gcc -fno-strict-aliasing -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.4/include/python2.4 -c lib/sqlalchemy/cextension/processors.c -o build/temp.macosx-10.6-fat-2.4/lib/sqlalchemy/cextension/processors.o
    In file included from /usr/include/architecture/i386/math.h:626,
                     from /usr/include/math.h:28,
                     from /Library/Frameworks/Python.framework/Versions/2.4/include/python2.4/pyport.h:90,
                     from /Library/Frameworks/Python.framework/Versions/2.4/include/python2.4/Python.h:55,
                     from lib/sqlalchemy/cextension/processors.c:9:
    /usr/include/AvailabilityMacros.h:108:14: warning: #warning Building for Intel with Mac OS X Deployment Target < 10.4 is invalid.
    gcc -g -bundle -undefined dynamic_lookup build/temp.macosx-10.6-fat-2.4/lib/sqlalchemy/cextension/processors.o -o build/lib.macosx-10.6-fat-2.4/sqlalchemy/cprocessors.so
    building 'sqlalchemy.cresultproxy' extension
    gcc -fno-strict-aliasing -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.4/include/python2.4 -c lib/sqlalchemy/cextension/resultproxy.c -o build/temp.macosx-10.6-fat-2.4/lib/sqlalchemy/cextension/resultproxy.o
    In file included from /usr/include/architecture/i386/math.h:626,
                     from /usr/include/math.h:28,
                     from /Library/Frameworks/Python.framework/Versions/2.4/include/python2.4/pyport.h:90,
                     from /Library/Frameworks/Python.framework/Versions/2.4/include/python2.4/Python.h:55,
                     from lib/sqlalchemy/cextension/resultproxy.c:9:
    /usr/include/AvailabilityMacros.h:108:14: warning: #warning Building for Intel with Mac OS X Deployment Target < 10.4 is invalid.
    lib/sqlalchemy/cextension/resultproxy.c:505: error: 'lenfunc' undeclared here (not in a function)
    lib/sqlalchemy/cextension/resultproxy.c:505: error: expected '}' before 'BaseRowProxy_length'
    lib/sqlalchemy/cextension/resultproxy.c:518: error: expected '}' before 'BaseRowProxy_length'
    error: command 'gcc' failed with exit status 1
    
  3. Mike Bayer repo owner

    also some warnings if I build with 2.5:

    lib/sqlalchemy/cextension/resultproxy.c: In function 'BaseRowProxy_processvalues':
    lib/sqlalchemy/cextension/resultproxy.c:165: warning: format '%d' expects type 'int', but argument 3 has type 'Py_ssize_t'
    lib/sqlalchemy/cextension/resultproxy.c:165: warning: format '%d' expects type 'int', but argument 4 has type 'Py_ssize_t'
    lib/sqlalchemy/cextension/resultproxy.c: In function 'BaseRowProxy_processvalues':
    lib/sqlalchemy/cextension/resultproxy.c:165: warning: format '%d' expects type 'int', but argument 3 has type 'Py_ssize_t'
    lib/sqlalchemy/cextension/resultproxy.c:165: warning: format '%d' expects type 'int', but argument 4 has type 'Py_ssize_t'
    
  4. Former user Account Deleted

    The patch almost works.

    The following works under python 2.4 (compile tested only, will get to functional testing shortly).

    PLEASE NOTE the addition of the lenfunc typedef. The py 2.5 errors can easily be worked around with casting. if Py_ssize_t is ever larger than an int, then perhaps type casting to long and then using %ld might be best.

    diff -ur SQLAlchemy-0.6.0.orig/lib/sqlalchemy/cextension/processors.c SQLAlchemy-0.6.0/lib/sqlalchemy/cextension/processors.c
    --- SQLAlchemy-0.6.0.orig/lib/sqlalchemy/cextension/processors.c        2010-04-18 18:10:43.000000000 -0500
    +++ SQLAlchemy-0.6.0/lib/sqlalchemy/cextension/processors.c     2010-04-27 12:57:44.448883484 -0500
    @@ -9,6 +9,12 @@
     #include <Python.h>
     #include <datetime.h>
    
    +#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
    +typedef int Py_ssize_t;
    +#define PY_SSIZE_T_MAX INT_MAX
    +#define PY_SSIZE_T_MIN INT_MIN
    +#endif
    +
     static PyObject *
     int_to_boolean(PyObject *self, PyObject *arg)
     {
    diff -ur SQLAlchemy-0.6.0.orig/lib/sqlalchemy/cextension/resultproxy.c SQLAlchemy-0.6.0/lib/sqlalchemy/cextension/resultproxy.c
    --- SQLAlchemy-0.6.0.orig/lib/sqlalchemy/cextension/resultproxy.c       2010-04-18 18:10:43.000000000 -0500
    +++ SQLAlchemy-0.6.0/lib/sqlalchemy/cextension/resultproxy.c    2010-04-27 13:01:08.184435361 -0500
    @@ -8,6 +8,13 @@
    
     #include <Python.h>
    
    +#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
    +typedef int Py_ssize_t;
    +#define PY_SSIZE_T_MAX INT_MAX
    +#define PY_SSIZE_T_MIN INT_MIN
    +typedef Py_ssize_t (*lenfunc)(PyObject *);
    +#endif
    +
    
     /***********
      * Structs *
    
  5. Former user Account Deleted

    (original author: ged) lenfunc typedef added in 6d8db0fa3d9c729e5379dc9b9f05ce090cbaf71f, as well as some typecast to prevent warnings (those %d refer to number of columns, so I highly doubt anyone will ever produce a database with more than 2^32 columns). Still can't test those changes (even on Python2.5). Sorry about that... Ubuntu 10.04 does not provide any binary package for 2.4 or 2.5 and I don't have time to install them manually.

  6. Log in to comment