PyLong to std::size_t conversion overflows

Issue #377 wontfix
Jan Blechta created an issue

Conversion from PyLong to std::size_t fails for values >= 2**63 on 64-bit machines. The key of the problem is in dolfin/swig/typemaps/primitives.i:Py_convert_std_size_t. Solution of the problem should probably wait until Py3 transition is finished.

MWE:

from dolfin import *
m = UnitIntervalMesh(1)
f = CellFunction('size_t', m)
f[0] = 2**63
# TypeError: (size_t) expected positive 'int' for argument 3

Comments (19)

  1. Jan Blechta reporter

    What about testing with py3? Is it handled by buildbots, @johannes_ring?

    Is somewhere written what python versions do we support?

  2. Martin Sandve Alnæs

    FEniCS dev requires 2.7, and the py3 buildbot passes all but a few tests. Some of the failures are a bit weird and may or may not be hard to debug. Feel free to look at them.

  3. Martin Sandve Alnæs

    I don't know. I think Aslak used 3.2 while I've used 3.4. @johannes_ring what 3.x does the buildbot use?

  4. Martin Sandve Alnæs

    @blechta we haven't discussed which 3.x version to require, but I think there are minor issues that are more compatible between 2.7 and 3.2 than with 3.0 and possibly 3.1, so requiring 3.2 makes sense. For all I care it's just as well to just jump straight to 3.4. Personally I'll stick with 2.7 for now, as 3.x seems a lot slower.

  5. Jan Blechta reporter

    Fix in pull request #162. Nevertheless some strange issues persist

    from dolfin import *
    import numpy as np
    m = UnitIntervalMesh(1)
    f = CellFunction('size_t', m)
    
    f[0] = np.uintp(2**63 - 1)
    print f[0] == 2**63 - 1 # True
    print f[0] == np.uintp(2**63 -    1) # True
    print f[0] == np.uintp(2**63 -  512) # True!!!
    print f[0] == np.uintp(2**63 + 1024) # True!!!
    
    f[0] = 2** 64 - 1 # now working
    print f[0] == 2**64 - 1 # True
    f[0] = np.uintp(2** 64 - 1) # not yet working
    
  6. Johan Hake

    I have now fixed the last conversion. We needed to treat numpy integers different to Python ints, at least for Python 2. Will push and merge as soon as it passes local tests.

  7. Log in to comment