[Python-checkins] cpython: do not worry about 64-bit dict sizes on 32-bit platforms

benjamin.peterson python-checkins at python.org
Thu Sep 8 16:17:54 EDT 2016


https://hg.python.org/cpython/rev/af8cb71edcb7
changeset:   103352:af8cb71edcb7
user:        Benjamin Peterson <benjamin at python.org>
date:        Thu Sep 08 13:16:41 2016 -0700
summary:
  do not worry about 64-bit dict sizes on 32-bit platforms

files:
  Objects/dict-common.h |   4 +++-
  Objects/dictobject.c  |  10 +++++++---
  2 files changed, 10 insertions(+), 4 deletions(-)


diff --git a/Objects/dict-common.h b/Objects/dict-common.h
--- a/Objects/dict-common.h
+++ b/Objects/dict-common.h
@@ -59,14 +59,16 @@
        - 1 byte if dk_size <= 0xff (char*)
        - 2 bytes if dk_size <= 0xffff (int16_t*)
        - 4 bytes if dk_size <= 0xffffffff (int32_t*)
-       - 8 bytes otherwise (Py_ssize_t*)
+       - 8 bytes otherwise (int64_t*)
 
        Dynamically sized, 8 is minimum. */
     union {
         int8_t as_1[8];
         int16_t as_2[4];
         int32_t as_4[2];
+#if SIZEOF_VOID_P > 4
         int64_t as_8[1];
+#endif
     } dk_indices;
 
     /* "PyDictKeyEntry dk_entries[dk_usable];" array follows:
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -237,7 +237,7 @@
 
 static int dictresize(PyDictObject *mp, Py_ssize_t minused);
 
-/* Global counter used to set ma_version_tag field of dictionary.
+/*Global counter used to set ma_version_tag field of dictionary.
  * It is incremented each time that a dictionary is created and each
  * time that a dictionary is modified. */
 static uint64_t pydict_global_version = 0;
@@ -292,12 +292,12 @@
     (DK_SIZE(dk) <= 0xff ?                     \
         1 : DK_SIZE(dk) <= 0xffff ?            \
             2 : DK_SIZE(dk) <= 0xffffffff ?    \
-                4 : sizeof(Py_ssize_t))
+                4 : sizeof(int64_t))
 #else
 #define DK_IXSIZE(dk)                          \
     (DK_SIZE(dk) <= 0xff ?                     \
         1 : DK_SIZE(dk) <= 0xffff ?            \
-            2 : sizeof(Py_ssize_t))
+            2 : sizeof(int32_t))
 #endif
 #define DK_ENTRIES(dk) \
     ((PyDictKeyEntry*)(&(dk)->dk_indices.as_1[DK_SIZE(dk) * DK_IXSIZE(dk)]))
@@ -330,10 +330,12 @@
         int32_t *indices = keys->dk_indices.as_4;
         ix = indices[i];
     }
+#if SIZEOF_VOID_P > 4
     else {
         int64_t *indices = keys->dk_indices.as_8;
         ix = indices[i];
     }
+#endif
     assert(ix >= DKIX_DUMMY);
     return ix;
 }
@@ -361,10 +363,12 @@
         assert(ix <= 0x7fffffff);
         indices[i] = (int32_t)ix;
     }
+#if SIZEOF_VOID_P > 4
     else {
         int64_t *indices = keys->dk_indices.as_8;
         indices[i] = ix;
     }
+#endif
 }
 
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list