[vlc-devel] [PATCH 2/2] Print(Color)Msg: display 32bits ID
Rafaël Carré
funman at videolan.org
Mon Nov 18 18:58:03 CET 2013
Use simple CRC to have a unique 32bits ID even with x86_64 pointers
---
src/misc/messages.c | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/src/misc/messages.c b/src/misc/messages.c
index 4272f1d..4f3b30b 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -204,8 +204,29 @@ static const char msg_type[4][9] = { "", " error", " warning", " debug" };
#define GRAY "\033[0m"
static const char msg_color[4][8] = { WHITE, RED, YELLOW, GRAY };
-/* Display size of a pointer */
-static const int ptr_width = 2 * /* hex digits */ sizeof(uintptr_t);
+/*
+ * crc_octets() was lamely copied from rfc 2440
+ * Copyright (C) The Internet Society (1998). All Rights Reserved.
+ */
+#define CRC24_INIT 0xB704CEL
+#define CRC24_POLY 0x1864CFBL
+
+static uint32_t crc_octets( uint8_t *octets, size_t len )
+{
+ uint32_t crc = CRC24_INIT;
+ int i;
+ while (len--)
+ {
+ crc ^= (*octets++) << 16;
+ for (i = 0; i < 8; i++)
+ {
+ crc <<= 1;
+ if (crc & 0x1000000)
+ crc ^= CRC24_POLY;
+ }
+ }
+ return crc & 0xFFFFFFL;
+}
static void PrintColorMsg (void *d, int type, const vlc_log_t *p_item,
const char *format, va_list ap)
@@ -216,10 +237,11 @@ static void PrintColorMsg (void *d, int type, const vlc_log_t *p_item,
if (verbose < 0 || verbose < (type - VLC_MSG_ERR))
return;
+ uint32_t id = crc_octets((uint8_t*)&p_item->i_object_id, sizeof(p_item->i_object_id));
int canc = vlc_savecancel ();
flockfile (stream);
- fprintf (stream, "["GREEN"%0*"PRIxPTR""GRAY"] ", ptr_width, p_item->i_object_id);
+ fprintf (stream, "["GREEN"%08x"GRAY"] ", id);
if (p_item->psz_header != NULL)
utf8_fprintf (stream, "[%s] ", p_item->psz_header);
utf8_fprintf (stream, "%s %s%s: %s", p_item->psz_module,
@@ -242,10 +264,11 @@ static void PrintMsg (void *d, int type, const vlc_log_t *p_item,
if (verbose < 0 || verbose < (type - VLC_MSG_ERR))
return;
+ uint32_t id = crc_octets((uint8_t*)&p_item->i_object_id, sizeof(p_item->i_object_id));
int canc = vlc_savecancel ();
flockfile (stream);
- fprintf (stream, "[%0*"PRIxPTR"] ", ptr_width, p_item->i_object_id);
+ fprintf (stream, "[%08d] ", id);
if (p_item->psz_header != NULL)
utf8_fprintf (stream, "[%s] ", p_item->psz_header);
utf8_fprintf (stream, "%s %s%s: ", p_item->psz_module,
--
1.8.3.2
More information about the vlc-devel
mailing list