@@ -72,8 +72,8 @@ static void InternTable_init_1(InternTable *table){
72
72
}
73
73
74
74
static void InternTable_dealloc_1 (InternTable * table ){
75
- Py_XDECREF (table -> zero_value );
76
75
size_t j ;
76
+ Py_XDECREF (table -> zero_value );
77
77
for (j = 0 ; j < table -> capacity ; j ++ ){
78
78
Py_XDECREF (table -> entries [j ].value );
79
79
}
@@ -194,7 +194,7 @@ static const char * what_sym[] = {"CALL", "EXC ", "LINE", "RET "};
194
194
195
195
// From http://www.cris.com/~Ttwang/tech/inthash.htm via
196
196
// 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 ){
198
198
key += ~(key << 32 );
199
199
key ^= (key >> 22 );
200
200
key += ~(key << 13 );
@@ -211,7 +211,7 @@ static uint64_t hash64(uint64_t key){
211
211
InternTable_lookup
212
212
*/
213
213
static PyObject * *
214
- InternTable_lookup (InternTable * table , uint64_t key );
214
+ InternTable_lookup (InternTable * table , PY_LONG_LONG key );
215
215
216
216
/*
217
217
Core implementation of the InternTable hash table.
@@ -223,8 +223,8 @@ InternTable_lookup(InternTable *table, uint64_t key);
223
223
returns a value pointer for the key.
224
224
225
225
*/
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
228
228
){
229
229
size_t index = location & (table -> capacity - 1 );
230
230
InternEntry * entry = table -> entries + index ;
@@ -263,7 +263,7 @@ static inline PyObject ** InternEntry_matches(
263
263
}
264
264
}
265
265
free (old_entries );
266
- assert (table -> current_fill == old_fill );
266
+ assert (table -> current_fill == old_fill ); ( void )( old_fill );
267
267
268
268
/* The shape of the table has changed and the caller doesn't know
269
269
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
288
288
populate the cell with the newly created object.
289
289
*/
290
290
static PyObject * *
291
- InternTable_lookup (InternTable * table , uint64_t key ){
291
+ InternTable_lookup (InternTable * table , PY_LONG_LONG key ){
292
292
size_t i ;
293
+ PyObject * * initial_attempt ;
294
+ size_t probe ;
293
295
294
296
if (key == 0 ){
295
297
return & (table -> zero_value );
296
298
}
297
- PyObject * * initial_attempt = InternEntry_matches (table , key , key );
299
+ initial_attempt = InternEntry_matches (table , key , key );
298
300
if (initial_attempt != NULL ){
299
301
return initial_attempt ;
300
302
}
301
- size_t probe = hash64 (key ) & (table -> capacity - 1 );
303
+ probe = hash64 (key ) & (table -> capacity - 1 );
302
304
for (i = 0 ; i < table -> capacity ; i ++ ){
303
305
PyObject * * attempt = InternEntry_matches (table , probe + i , key );
304
306
if (attempt != NULL ){
@@ -316,17 +318,17 @@ CTracer_record_pair(CTracer *self, int l1, int l2)
316
318
int ret = RET_ERROR ;
317
319
318
320
/*
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
320
322
than just concatenate them, we xor them together for the low bits. The
321
323
reason for this is that it allows us to trigger our no-hash lookup in the
322
324
table more often, because it ensures a reasonable range of diversity in the
323
325
low bits. We can recreate the original key as u1 = key >> 32,
324
326
u2 = ((uint32_t)u1) ^ ((uint32_t)key), so this still maps the tuple to a
325
327
unique key.
326
328
*/
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 );
330
332
331
333
PyObject * * container = InternTable_lookup (
332
334
& self -> intern_table , key );
@@ -355,7 +357,7 @@ static int
355
357
CTracer_record_int (CTracer * self , int lineno_from ){
356
358
357
359
PyObject * * container = InternTable_lookup (
358
- & self -> intern_table , (uint64_t )lineno_from );
360
+ & self -> intern_table , (PY_LONG_LONG )lineno_from );
359
361
360
362
PyObject * this_line = * container ;
361
363
if (this_line == NULL ) {
@@ -1367,14 +1369,17 @@ InternTable_dealloc(InternTableObject *self)
1367
1369
1368
1370
static PyObject * InternTable_getitem (InternTableObject * self , PyObject * key )
1369
1371
{
1372
+ PY_LONG_LONG int_key ;
1373
+ PyObject * * result ;
1374
+
1370
1375
assert (self -> table .entries );
1371
1376
PyErr_Clear ();
1372
- uint64_t int_key = PyLong_AsUnsignedLongLong (key );
1377
+ int_key = MyInt_AsLongLong (key );
1373
1378
if (PyErr_Occurred ()){
1374
1379
return NULL ;
1375
1380
}
1376
1381
1377
- PyObject * * result = InternTable_lookup (& self -> table , int_key );
1382
+ result = InternTable_lookup (& self -> table , int_key );
1378
1383
if (* result == NULL ){
1379
1384
return Py_None ;
1380
1385
}
@@ -1385,13 +1390,16 @@ static PyObject *InternTable_getitem(InternTableObject *self, PyObject *key)
1385
1390
1386
1391
static int InternTable_setitem (InternTableObject * self , PyObject * key , PyObject * value )
1387
1392
{
1393
+ PY_LONG_LONG int_key ;
1394
+ PyObject * * result ;
1395
+
1388
1396
assert (self -> table .entries );
1389
1397
1390
1398
PyErr_Clear ();
1391
- uint64_t int_key = PyLong_AsUnsignedLongLong (key );
1399
+ int_key = MyInt_AsLongLong (key );
1392
1400
if (PyErr_Occurred ()) return RET_ERROR ;
1393
1401
1394
- PyObject * * result = InternTable_lookup (& self -> table , int_key );
1402
+ result = InternTable_lookup (& self -> table , int_key );
1395
1403
if (* result != NULL ){
1396
1404
Py_XDECREF (* result );
1397
1405
}
0 commit comments