@@ -72,8 +72,8 @@ static void InternTable_init_1(InternTable *table){
7272}
7373
7474static void InternTable_dealloc_1 (InternTable * table ){
75- Py_XDECREF (table -> zero_value );
7675 size_t j ;
76+ Py_XDECREF (table -> zero_value );
7777 for (j = 0 ; j < table -> capacity ; j ++ ){
7878 Py_XDECREF (table -> entries [j ].value );
7979 }
@@ -194,7 +194,7 @@ static const char * what_sym[] = {"CALL", "EXC ", "LINE", "RET "};
194194
195195// From http://www.cris.com/~Ttwang/tech/inthash.htm via
196196// https://chromium.googlesource.com/chromium/blink/+/master/Source/wtf/HashFunctions.h
197- static uint64_t hash64 (uint64_t key ){
197+ static PY_LONG_LONG hash64 (PY_LONG_LONG key ){
198198 key += ~(key << 32 );
199199 key ^= (key >> 22 );
200200 key += ~(key << 13 );
@@ -211,7 +211,7 @@ static uint64_t hash64(uint64_t key){
211211 InternTable_lookup
212212*/
213213static PyObject * *
214- InternTable_lookup (InternTable * table , uint64_t key );
214+ InternTable_lookup (InternTable * table , PY_LONG_LONG key );
215215
216216/*
217217 Core implementation of the InternTable hash table.
@@ -223,8 +223,8 @@ InternTable_lookup(InternTable *table, uint64_t key);
223223 returns a value pointer for the key.
224224
225225*/
226- static inline PyObject * * InternEntry_matches (
227- InternTable * table , size_t location , uint64_t key
226+ static PyObject * * InternEntry_matches (
227+ InternTable * table , size_t location , PY_LONG_LONG key
228228){
229229 size_t index = location & (table -> capacity - 1 );
230230 InternEntry * entry = table -> entries + index ;
@@ -263,7 +263,7 @@ static inline PyObject ** InternEntry_matches(
263263 }
264264 }
265265 free (old_entries );
266- assert (table -> current_fill == old_fill );
266+ assert (table -> current_fill == old_fill ); ( void )( old_fill );
267267
268268 /* The shape of the table has changed and the caller doesn't know
269269 about that, so we just recurse and look up the key in the new
@@ -288,17 +288,19 @@ a freshly created key it will be a pointer to null. The caller should then
288288populate the cell with the newly created object.
289289*/
290290static PyObject * *
291- InternTable_lookup (InternTable * table , uint64_t key ){
291+ InternTable_lookup (InternTable * table , PY_LONG_LONG key ){
292292 size_t i ;
293+ PyObject * * initial_attempt ;
294+ size_t probe ;
293295
294296 if (key == 0 ){
295297 return & (table -> zero_value );
296298 }
297- PyObject * * initial_attempt = InternEntry_matches (table , key , key );
299+ initial_attempt = InternEntry_matches (table , key , key );
298300 if (initial_attempt != NULL ){
299301 return initial_attempt ;
300302 }
301- size_t probe = hash64 (key ) & (table -> capacity - 1 );
303+ probe = hash64 (key ) & (table -> capacity - 1 );
302304 for (i = 0 ; i < table -> capacity ; i ++ ){
303305 PyObject * * attempt = InternEntry_matches (table , probe + i , key );
304306 if (attempt != NULL ){
@@ -316,17 +318,17 @@ CTracer_record_pair(CTracer *self, int l1, int l2)
316318 int ret = RET_ERROR ;
317319
318320 /*
319- We combine the two int values into a uint64_t in a slightly odd way: Rather
321+ We combine the two int values into a PY_LONG_LONG in a slightly odd way: Rather
320322 than just concatenate them, we xor them together for the low bits. The
321323 reason for this is that it allows us to trigger our no-hash lookup in the
322324 table more often, because it ensures a reasonable range of diversity in the
323325 low bits. We can recreate the original key as u1 = key >> 32,
324326 u2 = ((uint32_t)u1) ^ ((uint32_t)key), so this still maps the tuple to a
325327 unique key.
326328 */
327- uint64_t u1 = (uint32_t )l1 ;
328- uint64_t u2 = (uint32_t )l2 ;
329- uint64_t key = (u1 << 32 ) | (u1 ^ u2 );
329+ PY_LONG_LONG u1 = (PY_UINT32_T )l1 ;
330+ PY_LONG_LONG u2 = (PY_UINT32_T )l2 ;
331+ PY_LONG_LONG key = (u1 << 32 ) | (u1 ^ u2 );
330332
331333 PyObject * * container = InternTable_lookup (
332334 & self -> intern_table , key );
@@ -355,7 +357,7 @@ static int
355357CTracer_record_int (CTracer * self , int lineno_from ){
356358
357359 PyObject * * container = InternTable_lookup (
358- & self -> intern_table , (uint64_t )lineno_from );
360+ & self -> intern_table , (PY_LONG_LONG )lineno_from );
359361
360362 PyObject * this_line = * container ;
361363 if (this_line == NULL ) {
@@ -1367,14 +1369,17 @@ InternTable_dealloc(InternTableObject *self)
13671369
13681370static PyObject * InternTable_getitem (InternTableObject * self , PyObject * key )
13691371{
1372+ PY_LONG_LONG int_key ;
1373+ PyObject * * result ;
1374+
13701375 assert (self -> table .entries );
13711376 PyErr_Clear ();
1372- uint64_t int_key = PyLong_AsUnsignedLongLong (key );
1377+ int_key = MyInt_AsLongLong (key );
13731378 if (PyErr_Occurred ()){
13741379 return NULL ;
13751380 }
13761381
1377- PyObject * * result = InternTable_lookup (& self -> table , int_key );
1382+ result = InternTable_lookup (& self -> table , int_key );
13781383 if (* result == NULL ){
13791384 return Py_None ;
13801385 }
@@ -1385,13 +1390,16 @@ static PyObject *InternTable_getitem(InternTableObject *self, PyObject *key)
13851390
13861391static int InternTable_setitem (InternTableObject * self , PyObject * key , PyObject * value )
13871392{
1393+ PY_LONG_LONG int_key ;
1394+ PyObject * * result ;
1395+
13881396 assert (self -> table .entries );
13891397
13901398 PyErr_Clear ();
1391- uint64_t int_key = PyLong_AsUnsignedLongLong (key );
1399+ int_key = MyInt_AsLongLong (key );
13921400 if (PyErr_Occurred ()) return RET_ERROR ;
13931401
1394- PyObject * * result = InternTable_lookup (& self -> table , int_key );
1402+ result = InternTable_lookup (& self -> table , int_key );
13951403 if (* result != NULL ){
13961404 Py_XDECREF (* result );
13971405 }
0 commit comments