Rev 5393: Lots of compatibility changes for python2.4 and mingw32 compilers. in http://bazaar.launchpad.net/~jameinel/bzr/2.3-btree-chk-leaf
John Arbash Meinel
john at arbash-meinel.com
Mon Aug 23 22:36:22 BST 2010
At http://bazaar.launchpad.net/~jameinel/bzr/2.3-btree-chk-leaf
------------------------------------------------------------
revno: 5393
revision-id: john at arbash-meinel.com-20100823213606-1pk5w1nyaz9kz9k0
parent: john at arbash-meinel.com-20100823191035-57bojnmqw54nutsz
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.3-btree-chk-leaf
timestamp: Mon 2010-08-23 16:36:06 -0500
message:
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.
-------------- next part --------------
=== modified file 'bzrlib/_btree_serializer_pyx.pyx'
--- a/bzrlib/_btree_serializer_pyx.pyx 2010-08-23 19:10:35 +0000
+++ b/bzrlib/_btree_serializer_pyx.pyx 2010-08-23 21:36:06 +0000
@@ -70,6 +70,7 @@
import_static_tuple_c, StaticTuple_New, \
StaticTuple_Intern, StaticTuple_SET_ITEM, StaticTuple_CheckExact, \
StaticTuple_GET_SIZE, StaticTuple_GET_ITEM
+import sys
# TODO: Find some way to import this from _dirstate_helpers
@@ -492,6 +493,41 @@
return val
+cdef _format_record_py24(gc_chk_sha1_record *record):
+ """Python2.4 PyString_FromFormat doesn't have %u.
+
+ It only has %d and %ld. We would really like to even have %llu, which
+ is only in python2.7. So we go back into casting to regular objects.
+ """
+ return "%s %s %s %s" % (record.block_offset, record.block_length,
+ record.record_start, record.record_end)
+
+
+cdef _format_record(gc_chk_sha1_record *record):
+ # This is inefficient to go from a logical state back to a
+ # string, but it makes things work a bit better internally for now.
+ if record.block_offset >= 0xFFFFFFFF:
+ # %llu is what we really want, but unfortunately it was only added
+ # in python 2.7... :(
+ block_offset_str = str(record.block_offset)
+ value = PyString_FromFormat('%s %lu %lu %lu',
+ PyString_AS_STRING(block_offset_str),
+ record.block_length,
+ record.record_start, record.record_end)
+ else:
+ value = PyString_FromFormat('%lu %lu %lu %lu',
+ <unsigned long>record.block_offset,
+ record.block_length,
+ record.record_start, record.record_end)
+ return value
+
+ctypedef object (*formatproc)(gc_chk_sha1_record *)
+cdef formatproc _record_formatter
+_record_formatter = _format_record
+if sys.version_info[:2] == (2, 4):
+ _record_formatter = _format_record_py24
+
+
cdef class GCCHKSHA1LeafNode:
"""Track all the entries for a given leaf node."""
@@ -554,21 +590,7 @@
cdef StaticTuple value_and_refs
cdef StaticTuple empty
value_and_refs = StaticTuple_New(2)
- # This is really inefficient to go from a logical state back to a
- # string, but it makes things work a bit better internally for now.
- if record.block_offset >= 0xFFFFFFFF:
- # %llu is what we really want, but unfortunately it was only added
- # in python 2.7... :(
- block_offset_str = str(record.block_offset)
- value = PyString_FromFormat('%s %lu %lu %lu',
- PyString_AS_STRING(block_offset_str),
- record.block_length,
- record.record_start, record.record_end)
- else:
- value = PyString_FromFormat('%lu %lu %lu %lu',
- <unsigned long>record.block_offset,
- record.block_length,
- record.record_start, record.record_end)
+ value = _record_formatter(record)
Py_INCREF(value)
StaticTuple_SET_ITEM(value_and_refs, 0, value)
# Always empty refs
=== modified file 'bzrlib/python-compat.h'
--- a/bzrlib/python-compat.h 2010-08-04 16:08:12 +0000
+++ b/bzrlib/python-compat.h 2010-08-23 21:36:06 +0000
@@ -65,8 +65,6 @@
#if !defined(S_ISLNK)
#define S_ISLNK(mode) (0)
#endif
- #define strtoll _strtoi64
- #define strtoull _strtoui64
#else /* Not win32 */
/* For htonl */
#include "arpa/inet.h"
@@ -76,6 +74,9 @@
#ifdef _MSC_VER
#define snprintf _snprintf
+/* gcc (mingw32) has strtoll, while the MSVC compiler uses _strtoi64 */
+#define strtoll _strtoi64
+#define strtoull _strtoui64
#endif
/* Introduced in Python 2.6 */
More information about the bazaar-commits
mailing list