~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_pyx.pyx

Use PyInt_AsUnsignedLongMask to correctly downcast larger fields in pyrex _pack_stat

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
    object PyTuple_GetItem_void_object "PyTuple_GET_ITEM" (void* tpl, int index)
98
98
    object PyTuple_GET_ITEM(object tpl, Py_ssize_t index)
99
99
 
 
100
    unsigned long PyInt_AsUnsignedLongMask(object number) except? -1
100
101
 
101
102
    char *PyString_AsString(object p)
102
103
    char *PyString_AsString_obj "PyString_AsString" (PyObject *string)
821
822
    cdef char result[6*4] # 6 long ints
822
823
    cdef int *aliased
823
824
    aliased = <int *>result
824
 
    aliased[0] = htonl(stat_value.st_size)
825
 
    aliased[1] = htonl(int(stat_value.st_mtime))
826
 
    aliased[2] = htonl(int(stat_value.st_ctime))
827
 
    aliased[3] = htonl(stat_value.st_dev)
828
 
    aliased[4] = htonl(stat_value.st_ino & 0xFFFFFFFF)
829
 
    aliased[5] = htonl(stat_value.st_mode)
 
825
    aliased[0] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_size))
 
826
    # mtime and ctime will often be floats but get converted to PyInt within
 
827
    aliased[1] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_mtime))
 
828
    aliased[2] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_ctime))
 
829
    aliased[3] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_dev))
 
830
    aliased[4] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_ino))
 
831
    aliased[5] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_mode))
830
832
    packed = PyString_FromStringAndSize(result, 6*4)
831
833
    return _encode(packed)[:-1]
832
834