[asterisk-commits] russell: trunk r92305 - in /trunk: include/asterisk/unaligned.h main/event.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 11 10:29:30 CST 2007


Author: russell
Date: Tue Dec 11 10:29:29 2007
New Revision: 92305

URL: http://svn.digium.com/view/asterisk?view=rev&rev=92305
Log:
* In unaligned.h, remove some unnecessary casts and mark the arg of the 
  get_unaligned functions as const
* In event.c, use get_unaligned_uint32() in a couple of places to fix issues on
  architectures that don't allow unaligned access

Modified:
    trunk/include/asterisk/unaligned.h
    trunk/main/event.c

Modified: trunk/include/asterisk/unaligned.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/unaligned.h?view=diff&rev=92305&r1=92304&r2=92305
==============================================================================
--- trunk/include/asterisk/unaligned.h (original)
+++ trunk/include/asterisk/unaligned.h Tue Dec 11 10:29:29 2007
@@ -29,43 +29,43 @@
 
 #ifdef __GNUC__
 /* If we just tell GCC what's going on, we can trust it to behave optimally */
-static inline unsigned int get_unaligned_uint32(void *p)
+static inline unsigned int get_unaligned_uint32(const void *p)
 {
-	struct { unsigned int d; } __attribute__((packed)) *pp = (void *)p;
+	const struct { unsigned int d; } __attribute__((packed)) *pp = p;
 
 	return pp->d;
 }
-static inline unsigned short get_unaligned_uint16(void *p)
+static inline unsigned short get_unaligned_uint16(const void *p)
 {
-	struct { unsigned short d; } __attribute__((packed)) *pp = (void *)p;
+	const struct { unsigned short d; } __attribute__((packed)) *pp = p;
 
 	return pp->d;
 }
 
 static inline void put_unaligned_uint32(void *p, unsigned int datum)
 {
-	struct { unsigned int d; } __attribute__((packed)) *pp = (void *)p;
+	struct { unsigned int d; } __attribute__((packed)) *pp = p;
 
 	pp->d = datum;
 }
 
 static inline void put_unaligned_uint16(void *p, unsigned short datum)
 {
-	struct { unsigned short d; } __attribute__((packed)) *pp = (void *)p;
+	struct { unsigned short d; } __attribute__((packed)) *pp = p;
 
 	pp->d = datum;
 }
 #elif defined(SOLARIS) && defined(__sparc__)
-static inline unsigned int get_unaligned_uint32(void *p)
+static inline unsigned int get_unaligned_uint32(const void *p)
 {
-	unsigned char *cp = p;
+	const unsigned char *cp = p;
 
 	return (cp[0] << 24) | (cp[1] << 16) | (cp[2] << 8) | cp[3];
 }
 
-static inline unsigned short get_unaligned_uint16(void *p)
+static inline unsigned short get_unaligned_uint16(const void *p)
 {
-	unsigned char *cp = p;
+	const unsigned char *cp = p;
 
 	return (cp[0] << 8) | cp[1] ;
 }

Modified: trunk/main/event.c
URL: http://svn.digium.com/view/asterisk/trunk/main/event.c?view=diff&rev=92305&r1=92304&r2=92305
==============================================================================
--- trunk/main/event.c (original)
+++ trunk/main/event.c Tue Dec 11 10:29:29 2007
@@ -32,6 +32,7 @@
 #include "asterisk/linkedlists.h"
 #include "asterisk/lock.h"
 #include "asterisk/utils.h"
+#include "asterisk/unaligned.h"
 
 /* Only use one thread for now to ensure ordered delivery */
 #define NUM_EVENT_THREADS 1
@@ -392,7 +393,7 @@
 
 uint32_t ast_event_iterator_get_ie_uint(struct ast_event_iterator *iterator)
 {
-	return ntohl(*iterator->ie->ie_payload);
+	return ntohl(get_unaligned_uint32(iterator->ie->ie_payload));
 }
 
 const char *ast_event_iterator_get_ie_str(struct ast_event_iterator *iterator)
@@ -416,7 +417,7 @@
 
 	ie_val = ast_event_get_ie_raw(event, ie_type);
 
-	return ie_val ? ntohl(*ie_val) : 0;
+	return ie_val ? ntohl(get_unaligned_uint32(ie_val)) : 0;
 }
 
 const char *ast_event_get_ie_str(const struct ast_event *event, enum ast_event_ie_type ie_type)




More information about the asterisk-commits mailing list