Bug 685 - Python bindings build failure on 32-bit systems
Python bindings build failure on 32-bit systems
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: python bindings
ns-3-dev
All All
: P1 blocker
Assigned To: ns-bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-09-21 06:53 UTC by Gustavo J. A. M. Carneiro
Modified: 2009-09-25 07:17 UTC (History)
0 users

See Also:


Attachments
bundle of proposed solution (179.51 KB, application/octet-stream)
2009-09-22 11:24 UTC, Gustavo J. A. M. Carneiro
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gustavo J. A. M. Carneiro 2009-09-21 06:53:37 UTC
static PyObject* _wrap_PyNs3FlowProbeFlowStats__get_bytesDropped(PyNs3FlowProbeFlowStats *self)
{
    PyObject *py_retval;
    Pystd__vector__lt___unsigned_long___gt__ *py_std__vector__lt___unsigned_long___gt__;
    
    py_std__vector__lt___unsigned_long___gt__ = PyObject_New(Pystd__vector__lt___unsigned_long___gt__, &Pystd__vector__lt___unsigned_long___gt___Type);

    ////////////////////// HERE:
    py_std__vector__lt___unsigned_long___gt__->obj = new std::vector< unsigned long >(self->obj->bytesDropped);
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    py_retval = Py_BuildValue((char *) "N", py_std__vector__lt___unsigned_long___gt__);
    return py_retval;
}

The problem is due to the fact that GCC-XML reports to us std::vector<unsigned long> instead of std::vector<uint64_t>.  But while "unsigned long" is effectively the same as uint64_t on 64-bit systems (LP64), but uint64_t is "unsigned long long" on 32-bit systems.  The mismatch between "unsigned long long" and "unsigned long" in 32-bit systems causes the compilation error.

The problem had already caused cygwin compilation problems.  And is due to the following GCC-XML bug, which was closed as "not fixable": http://www.gccxml.org/Bug/view.php?id=7572
Comment 1 Gustavo J. A. M. Carneiro 2009-09-21 13:45:12 UTC
With the following patch, we can force gccxml scanner to treat the API as if from the point of view of a 32-bit system:

diff -r 3816b13c16bc bindings/python/ns3modulescan.py
--- a/bindings/python/ns3modulescan.py	Mon Sep 21 17:53:43 2009 +0100
+++ b/bindings/python/ns3modulescan.py	Mon Sep 21 18:35:59 2009 +0100
@@ -275,7 +275,8 @@
          define_symbols={
             #'NS3_ASSERT_ENABLE': None,
             #'NS3_LOG_ENABLE': None,
-            }
+            },
+        cflags='--gccxml-cxxflags "-m32"'
         )
 
     module_parser.parse_init([everything_h],


This has impact on the problematic definitions:

-    module.add_container('std::vector< unsigned long >', 'long unsigned int', container_type='vector')
+    module.add_container('std::vector< unsigned long long >', 'long long unsigned int', container_type='vector')

Unfortunately, then the bindings won't build on 64-bit systems.  Code scanned for 32-bit systems only builds on 32-bit systems. Code scanned for 64-bit systems only builds on 64-bit systems.

I see only one possible solution to really "fix" the bug: have multiple directories containing the scanned API definitions, one directory for each data model: gcc-32, gcc-64, and we might as well include 'cygwin' to fix the python bindings for cygwin.  And select the source API definitions directory dynamically at build time according to the platform.

However, this move would represent some risk, near the release, and an added burden for maintainers.  Maintainers with 64-bit systems could scan for 64 and 32 bits in one go (although it will take twice the time), 32-bit maintainers can only scan for 32-bit, and as for cygwin only by running the scanning inside cygwin can you take care of it.

*sigh* Stupid GCC-XML :(
Comment 2 Gustavo J. A. M. Carneiro 2009-09-22 11:24:16 UTC
Created attachment 600 [details]
bundle of proposed solution

This bundle makes the python apidefs duplicated in subdirectories, one for each data model.  It removes the bindings/python/ns3_module_*.py files, and adds similar files in bindings/python/apidefs/<model>.  For now, <model> can be gcc-ILP32 and gcc-LP64.  In the future, cygwin should also be finally supported, if ever someone manages to install gccxml and pygccxml in cygwin and run ./waf --python-scan.
Comment 3 Gustavo J. A. M. Carneiro 2009-09-22 13:06:51 UTC
Well, I give up trying to build gcc-xml on cygwin :(
Comment 4 Gustavo J. A. M. Carneiro 2009-09-25 07:17:56 UTC
Lack of time to do better, and lack of better idea; I committed this solution:

comparing with ssh://code@code.nsnam.org/repos/ns-3-dev
searching for changes
changeset:   5249:85cde7d987ed
parent:      5233:3816b13c16bc
user:        Gustavo J. A. M. Carneiro  <gjc@inescporto.pt>
date:        Tue Sep 22 16:13:42 2009 +0100
summary:     Python: allow multiple api definitions directories, one per data model.

changeset:   5250:7d3096b23352
parent:      5248:6b93abd21871
parent:      5249:85cde7d987ed
user:        Gustavo J. A. M. Carneiro  <gjc@inescporto.pt>
date:        Fri Sep 25 11:48:05 2009 +0100
summary:     merge

changeset:   5251:306856feb249
tag:         tip
user:        Gustavo J. A. M. Carneiro  <gjc@inescporto.pt>
date:        Fri Sep 25 12:15:27 2009 +0100
summary:     Put back the configure check to disable python bindings in cygwin, due to our inability to install gccxml in cygwin.