From 133fb9871cf88cfbcbb35f17ebeb08b73feaf816 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Thu, 9 Feb 2012 23:53:10 +0100 Subject: [PATCH] Fixed buggy and broken KBKEY_ENCODE and KBKEY_DECODE macros. --- sortix/keycodes.h | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/sortix/keycodes.h b/sortix/keycodes.h index 350c61e8..ae86053f 100644 --- a/sortix/keycodes.h +++ b/sortix/keycodes.h @@ -143,19 +143,26 @@ #define KBKEY_ENCODE(_kbkey) \ ({ \ - int kbkey = (_kbkey); \ - uint32_t codepoint = (1U<<30U) | ((unsigned) kbkey); \ - codepoint &= ~(1U<<31U); \ - codepoint; \ + int __kbkey = (_kbkey); \ + uint32_t __codepoint = (1U<<30U) | ((unsigned) __kbkey); \ + __codepoint &= ~(1U<<31U); \ + __codepoint; \ }) #define KBKEY_DECODE(_codepoint) \ ({ \ - uint32_t codepoint = (_codepoint); \ - if ( !(codepoint & (1U<<30U)) ) { codepoint = 0U; } \ - if ( codepoint & (1U<<29U) ) { codepoint |= (1U<<31U); } \ - int kbkey = (int) codepoint; \ - kbkey; \ + struct { union { int __kbkey; uint32_t __codepoint; }; } __u; \ + __u.__codepoint = (_codepoint); \ + if ( __u.__codepoint & (1U<<30U) ) \ + { \ + if ( __u.__codepoint & (1U<<29U) ) { __u.__codepoint |= (1U<<31U); } \ + else { __u.__codepoint &= ~(1U<<30U); } \ + } \ + else \ + { \ + __u.__codepoint = 0U; \ + } \ + __u.__kbkey; \ }) #endif