~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_btree_serializer_pyx.pyx

  • Committer: John Arbash Meinel
  • Date: 2010-08-04 01:31:03 UTC
  • mto: This revision was merged to the branch mainline in revision 5390.
  • Revision ID: john@arbash-meinel.com-20100804013103-mz61vkhuj1w3uozh
Add tests that we handle sizes close to and >2GB properly.

We can't use %llu because that wasn't added until python 2.7, but
we can use str(PyLong).

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
        pass
31
31
    int PyList_Append(object lst, object item) except -1
32
32
 
 
33
    int HAVE_LONG_LONG
 
34
 
33
35
    char *PyString_AsString(object p) except NULL
34
36
    object PyString_FromStringAndSize(char *, Py_ssize_t)
35
37
    PyObject *PyString_FromStringAndSize_ptr "PyString_FromStringAndSize" (char *, Py_ssize_t)
330
332
#       One slightly ugly option would be to cache block offsets in a global.
331
333
#       However, that leads to thread-safety issues, etc.
332
334
ctypedef struct gc_chk_sha1_record:
333
 
    unsigned long long block_offset
 
335
    long long block_offset
334
336
    unsigned int block_length
335
337
    unsigned int record_start
336
338
    unsigned int record_end
520
522
        value_and_refs = StaticTuple_New(2)
521
523
        # This is really inefficient to go from a logical state back to a
522
524
        # string, but it makes things work a bit better internally for now.
523
 
        value = PyString_FromFormat('%lu %lu %lu %lu',
524
 
                                    <unsigned long>record.block_offset,
 
525
        if record.block_offset >= 0xFFFFFFFFull:
 
526
            # %llu is what we really want, but unfortunately it was only added
 
527
            # in python 2.7... :(
 
528
            block_offset_str = str(record.block_offset)
 
529
            value = PyString_FromFormat('%s %lu %lu %lu',
 
530
                                    PyString_AS_STRING(block_offset_str),
525
531
                                    record.block_length,
526
532
                                    record.record_start, record.record_end)
 
533
        else:
 
534
            value = PyString_FromFormat('%lu %lu %lu %lu',
 
535
                                        <unsigned long>record.block_offset,
 
536
                                        record.block_length,
 
537
                                        record.record_start, record.record_end)
527
538
        Py_INCREF(value)
528
539
        StaticTuple_SET_ITEM(value_and_refs, 0, value)
529
540
        # Always empty refs