[sysprof: 36/63] libsysprof-capture: Avoid using GLIB_SIZEOF_VOID_P



commit 6d3ede2e9fdafe01f11ab609276106fe24c92205
Author: Philip Withnall <withnall endlessm com>
Date:   Thu Jul 2 11:32:09 2020 +0100

    libsysprof-capture: Avoid using GLIB_SIZEOF_VOID_P
    
    Use `UINTPTR_MAX` to calculate the size of a pointer instead. This
    assumes that all pointers are the same width.
    
    It also means that the sysprof-capture code uses the pointer size of the
    platform that libsysprof-capture was compiled on, rather than the
    pointer size of the platform that GLib was compiled on. They seem
    unlikely to differ.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    Helps: #40

 src/libsysprof-capture/sysprof-capture-types.h | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-capture-types.h b/src/libsysprof-capture/sysprof-capture-types.h
index c522839..c0d2e6e 100644
--- a/src/libsysprof-capture/sysprof-capture-types.h
+++ b/src/libsysprof-capture/sysprof-capture-types.h
@@ -81,12 +81,14 @@ SYSPROF_BEGIN_DECLS
 
 #define SYSPROF_CAPTURE_ADDRESS_FORMAT "0x%016" PRIx64
 
-#if GLIB_SIZEOF_VOID_P == 8
+static_assert (sizeof (void *) == sizeof (uintptr_t),
+               "UINTPTR_MAX can’t be used to determine sizeof(void*) at compile time");
+#if UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFu
 # define SYSPROF_CAPTURE_JITMAP_MARK    SYSPROF_UINT64_CONSTANT(0xE000000000000000)
-#elif GLIB_SIZEOF_VOID_P == 4
+#elif UINTPTR_MAX == 0xFFFFFFFF
 # define SYSPROF_CAPTURE_JITMAP_MARK    SYSPROF_UINT64_CONSTANT(0xE0000000)
 #else
-#error Unknown GLIB_SIZEOF_VOID_P
+#error Unknown UINTPTR_MAX
 #endif
 
 #define SYSPROF_CAPTURE_CURRENT_TIME   (sysprof_clock_get_current_time())


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]