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
497c776e
Commit
497c776e
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
1f6caf72
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
11 deletions
+8
-11
branches/3.3/src/ZODB/utils.py
branches/3.3/src/ZODB/utils.py
+8
-11
No files found.
branches/3.3/src/ZODB/utils.py
View file @
497c776e
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
import
sys
import
sys
import
time
import
time
import
struct
from
struct
import
pack
,
unpack
from
struct
import
pack
,
unpack
from
binascii
import
hexlify
from
binascii
import
hexlify
import
cPickle
as
pickle
import
cPickle
as
pickle
...
@@ -94,22 +95,18 @@ def readable_tid_repr(tid):
...
@@ -94,22 +95,18 @@ def readable_tid_repr(tid):
# unsigned, but produces a FutureWarning, because Python 2.4 will display
# 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
# it as signed. So when you want to prodce an address, use positive_id() to
# obtain it.
# 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
):
def
positive_id
(
obj
):
"""Return id(obj) as a non-negative integer."""
"""Return id(obj) as a non-negative integer."""
result
=
id
(
obj
)
result
=
id
(
obj
)
if
result
<
0
:
if
result
<
0
:
# This is a puzzle: there's no way to know the natural width of
result
+=
_ADDRESS_MASK
# addresses on this box (in particular, there's no necessary
assert
result
>
0
# 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
return
result
return
result
# Given a ZODB pickle, return pair of strings (module_name, class_name).
# 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