Update of /cvs-repository/Packages/ZODB
In directory cvs.zope.org:/tmp/cvs-serv30839/ZODB

Modified Files:
      Tag: Zope-2_7-branch
        utils.py 
Log Message:
Replace trigger.py with ZODB 3.4's version.

This simplifies the code, and worms around suspected race bugs in
Microsoft's socket implementation.


=== Packages/ZODB/utils.py 1.17.4.4 => 1.17.4.5 ===
--- Packages/ZODB/utils.py:1.17.4.4     Sat Sep  4 00:45:03 2004
+++ Packages/ZODB/utils.py      Mon Aug  1 17:21:54 2005
@@ -15,6 +15,7 @@
 import sys, time
 from ZODB import TimeStamp
 
+import struct
 from struct import pack, unpack
 from types import StringType
 from binascii import hexlify
@@ -112,4 +113,23 @@
     result = tid_repr(tid)
     if isinstance(tid, StringType) and len(tid) == 8:
         result = "%s %s" % (result, TimeStamp.TimeStamp(tid))
+    return result
+
+# Addresses can "look negative" on some boxes, some of the time.  If you
+# feed a "negative address" to an %x format, Python 2.3 displays it as
+# unsigned, but produces a FutureWarning, because Python 2.4 will display
+# it as signed.  So when you want to prodce an address, use positive_id() to
+# obtain it.
+# _ADDRESS_MASK is 2**(number_of_bits_in_a_native_pointer).  Adding this to
+# a negative address gives a positive int with the same hex representation as
+# the significant bits in the original.
+
+_ADDRESS_MASK = 256 ** struct.calcsize('P')
+def positive_id(obj):
+    """Return id(obj) as a non-negative integer."""
+
+    result = id(obj)
+    if result < 0:
+        result += _ADDRESS_MASK
+        assert result > 0
     return result

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to