Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
af0779df
Commit
af0779df
authored
Mar 01, 2005
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
positive_id(): Use a trick from Armin Rigo to deduce the
native platorm address size.
parent
7679e9b9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
src/ZODB/utils.py
src/ZODB/utils.py
+8
-11
No files found.
src/ZODB/utils.py
View file @
af0779df
...
...
@@ -14,6 +14,7 @@
import
sys
import
time
import
struct
from
struct
import
pack
,
unpack
from
binascii
import
hexlify
import
cPickle
as
pickle
...
...
@@ -94,22 +95,18 @@ def readable_tid_repr(tid):
# 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
:
# This is a puzzle: there's no way to know the natural width of
# addresses on this box (in particular, there's no necessary
# relation to sys.maxint). Try 32 bits first (and on a 32-bit
# box, adding 2**32 gives a positive number with the same hex
# representation as the original result).
result
+=
1L
<<
32
if
result
<
0
:
# Undo that, and try 64 bits.
result
-=
1L
<<
32
result
+=
1L
<<
64
assert
result
>=
0
# else addresses are fatter than 64 bits
result
+=
_ADDRESS_MASK
assert
result
>
0
return
result
# Given a ZODB pickle, return pair of strings (module_name, class_name).
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment