~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: 2011-01-12 21:27:00 UTC
  • mto: This revision was merged to the branch mainline in revision 5605.
  • Revision ID: john@arbash-meinel.com-20110112212700-esqmtrmevddxrsq2
Clean up the test slightly, hoping to avoid race conditions, update NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
496
496
    return val
497
497
 
498
498
 
 
499
cdef _format_record_py24(gc_chk_sha1_record *record):
 
500
    """Python2.4 PyString_FromFormat doesn't have %u.
 
501
 
 
502
    It only has %d and %ld. We would really like to even have %llu, which
 
503
    is only in python2.7. So we go back into casting to regular objects.
 
504
    """
 
505
    return "%s %s %s %s" % (record.block_offset, record.block_length,
 
506
                            record.record_start, record.record_end)
 
507
 
 
508
 
499
509
cdef _format_record(gc_chk_sha1_record *record):
500
510
    # This is inefficient to go from a logical state back to a
501
511
    # string, but it makes things work a bit better internally for now.
503
513
        # %llu is what we really want, but unfortunately it was only added
504
514
        # in python 2.7... :(
505
515
        block_offset_str = str(record.block_offset)
506
 
        value = PyString_FromFormat('%s %u %u %u',
 
516
        value = PyString_FromFormat('%s %lu %lu %lu',
507
517
                                PyString_AS_STRING(block_offset_str),
508
518
                                record.block_length,
509
519
                                record.record_start, record.record_end)
510
520
    else:
511
 
        value = PyString_FromFormat('%lu %u %u %u',
 
521
        value = PyString_FromFormat('%lu %lu %lu %lu',
512
522
                                    <unsigned long>record.block_offset,
513
523
                                    record.block_length,
514
524
                                    record.record_start, record.record_end)
515
525
    return value
516
526
 
 
527
ctypedef object (*formatproc)(gc_chk_sha1_record *)
 
528
cdef formatproc _record_formatter
 
529
_record_formatter = _format_record
 
530
if sys.version_info[:2] == (2, 4):
 
531
    _record_formatter = _format_record_py24
 
532
 
517
533
 
518
534
cdef class GCCHKSHA1LeafNode:
519
535
    """Track all the entries for a given leaf node."""
577
593
        cdef StaticTuple value_and_refs
578
594
        cdef StaticTuple empty
579
595
        value_and_refs = StaticTuple_New(2)
580
 
        value = _format_record(record)
 
596
        value = _record_formatter(record)
581
597
        Py_INCREF(value)
582
598
        StaticTuple_SET_ITEM(value_and_refs, 0, value)
583
599
        # Always empty refs