~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-23 21:36:06 UTC
  • mto: This revision was merged to the branch mainline in revision 5390.
  • Revision ID: john@arbash-meinel.com-20100823213606-1pk5w1nyaz9kz9k0
Lots of compatibility changes for python2.4 and mingw32 compilers.

gcc has strtoll available, and does the wrong thing if you use _strtoi64 (it implicitly
defines it to return an 'int' which isn't a 64-bit integer.)

Further, python2.4 doesn't support the %lu syntax, only having %ld and %d. So we go
back to casting everything into real python objects and then stringifying them, but
only for python 2.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
    import_static_tuple_c, StaticTuple_New, \
71
71
    StaticTuple_Intern, StaticTuple_SET_ITEM, StaticTuple_CheckExact, \
72
72
    StaticTuple_GET_SIZE, StaticTuple_GET_ITEM
 
73
import sys
73
74
 
74
75
 
75
76
# TODO: Find some way to import this from _dirstate_helpers
492
493
    return val
493
494
 
494
495
 
 
496
cdef _format_record_py24(gc_chk_sha1_record *record):
 
497
    """Python2.4 PyString_FromFormat doesn't have %u.
 
498
 
 
499
    It only has %d and %ld. We would really like to even have %llu, which
 
500
    is only in python2.7. So we go back into casting to regular objects.
 
501
    """
 
502
    return "%s %s %s %s" % (record.block_offset, record.block_length,
 
503
                            record.record_start, record.record_end)
 
504
 
 
505
 
 
506
cdef _format_record(gc_chk_sha1_record *record):
 
507
    # This is inefficient to go from a logical state back to a
 
508
    # string, but it makes things work a bit better internally for now.
 
509
    if record.block_offset >= 0xFFFFFFFF:
 
510
        # %llu is what we really want, but unfortunately it was only added
 
511
        # in python 2.7... :(
 
512
        block_offset_str = str(record.block_offset)
 
513
        value = PyString_FromFormat('%s %lu %lu %lu',
 
514
                                PyString_AS_STRING(block_offset_str),
 
515
                                record.block_length,
 
516
                                record.record_start, record.record_end)
 
517
    else:
 
518
        value = PyString_FromFormat('%lu %lu %lu %lu',
 
519
                                    <unsigned long>record.block_offset,
 
520
                                    record.block_length,
 
521
                                    record.record_start, record.record_end)
 
522
    return value
 
523
 
 
524
ctypedef object (*formatproc)(gc_chk_sha1_record *)
 
525
cdef formatproc _record_formatter
 
526
_record_formatter = _format_record
 
527
if sys.version_info[:2] == (2, 4):
 
528
    _record_formatter = _format_record_py24
 
529
 
 
530
 
495
531
cdef class GCCHKSHA1LeafNode:
496
532
    """Track all the entries for a given leaf node."""
497
533
 
554
590
        cdef StaticTuple value_and_refs
555
591
        cdef StaticTuple empty
556
592
        value_and_refs = StaticTuple_New(2)
557
 
        # This is really inefficient to go from a logical state back to a
558
 
        # string, but it makes things work a bit better internally for now.
559
 
        if record.block_offset >= 0xFFFFFFFF:
560
 
            # %llu is what we really want, but unfortunately it was only added
561
 
            # in python 2.7... :(
562
 
            block_offset_str = str(record.block_offset)
563
 
            value = PyString_FromFormat('%s %lu %lu %lu',
564
 
                                    PyString_AS_STRING(block_offset_str),
565
 
                                    record.block_length,
566
 
                                    record.record_start, record.record_end)
567
 
        else:
568
 
            value = PyString_FromFormat('%lu %lu %lu %lu',
569
 
                                        <unsigned long>record.block_offset,
570
 
                                        record.block_length,
571
 
                                        record.record_start, record.record_end)
 
593
        value = _record_formatter(record)
572
594
        Py_INCREF(value)
573
595
        StaticTuple_SET_ITEM(value_and_refs, 0, value)
574
596
        # Always empty refs