#14254: OverflowErrors in TripleDictEraser
----------------------------+-----------------------------------------------
Reporter: jdemeyer | Owner: robertwb
Type: defect | Status: new
Priority: blocker | Milestone: sage-5.8
Component: coercion | Resolution:
Keywords: | Work issues:
Report Upstream: N/A | Reviewers:
Authors: | Merged in:
Dependencies: | Stopgaps:
----------------------------+-----------------------------------------------
Comment (by SimonKing):
There is a comment
{{{
# A note about how to store "id" keys in python structures:
#
# In python a "pointer length integer" (size_t) normally, is encoded
# as a *signed* integer, of type Py_ssize_t. This has an advantage in that
# if the value gets encoded as a *python integer* it can do so in a sign-
preserving
# way and still make use of all the bits that python offers to store
(small) integers.
#
# There is one place where we have to be careful about signs:
# Our hash values most naturally live in Py_ssize_t. We convert those into
# an index into our bucket list by taking the hash modulo the number of
buckets.
# However, the modulo operator in C preserves the sign of the number we
take the
# modulus of, which is not what we want.
# The solution is to always do
# (<size_t) h)% modulus
# to ensure we're doing an unsigned modulus.
}}}
Could it be that this is relevant here?
Is it really safe to do
{{{
cdef Py_ssize_t k1,k2,k3
cdef int offset
k1,k2,k3,offset = r.key
cdef Py_ssize_t h = (k1 + 13*k2 ^ 503*k3)
PyList_GET_ITEM(buckets, (<size_t>h) % PyList_GET_SIZE(buckets))
}}}
?
Yes, we need to care about the sign. But we also have
{{{
Py_ssize_t PyList_GET_SIZE(object list)
PyObject* PyList_GET_ITEM(object list, Py_ssize_t i)
}}}
(hence, the modulus is Py_ssize_t, and the result will be translated into
Py_ssize_t, too)
I am afraid I have no 32 bit machine to test.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/14254#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.