Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 647753d5 authored by Arman Uguray's avatar Arman Uguray
Browse files

osi: Introduce ptr <-> integer conversion macros

This CL introduces macros for safe pointer to integer conversion (and vice
versa). Also fixed a small style issue in log.h

Bug: 21570302
Change-Id: If76bf5e35970f9b33f9bef53fbd03a7effae08dc
parent 13808c5a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@
#define LOG_WARN(...) LOGWRAPPER(__VA_ARGS__)
#define LOG_ERROR(...) LOGWRAPPER(__VA_ARGS__)

#else
#else  /* !defined(OS_GENERIC) */

#include <cutils/log.h>

@@ -46,4 +46,4 @@
#define LOG_ERROR(...)   ALOGE(__VA_ARGS__)


#endif
#endif  /* defined(OS_GENERIC) */
+11 −0
Original line number Diff line number Diff line
@@ -20,3 +20,14 @@
#define COMPILE_ASSERT(x) char * DUMMY_PTR = !(x)

typedef uint32_t timeout_t;

// Macros for safe integer to pointer conversion. In the C language, data is
// commonly cast to opaque pointer containers and back for generic parameter
// passing in callbacks. These macros should be used sparingly in new code
// (never in C++ code). Whenever integers need to be passed as a pointer, use
// these macros.
#define PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p)))
#define UINT_TO_PTR(u) ((void *) ((uintptr_t) (u)))

#define PTR_TO_INT(p) ((int) ((intptr_t) (p)))
#define INT_TO_PTR(i) ((void *) ((intptr_t) (i)))