From 5729e0e9af590807df66a3db688008f9547bce9f Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Fri, 10 Feb 2023 14:09:10 -0300 Subject: iconv: Remove _STRING_ARCH_unaligned usage for get/set macros And use a packed structure instead. The compiler generates optimized unaligned code if the architecture supports it. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Wilco Dijkstra --- iconv/gconv_int.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'iconv/gconv_int.h') diff --git a/iconv/gconv_int.h b/iconv/gconv_int.h index da792a95f5..4b247a815f 100644 --- a/iconv/gconv_int.h +++ b/iconv/gconv_int.h @@ -26,6 +26,34 @@ __BEGIN_DECLS +/* We have to provide support for machines which are not able to handled + unaligned memory accesses. Some of the character encodings have + representations with a fixed width of 2 or 4 bytes. */ +#define get16(addr) \ +({ \ + const struct { uint16_t r; } __attribute__ ((__packed__)) *__ptr \ + = (__typeof(__ptr))(addr); \ + __ptr->r; \ +}) +#define get32(addr) \ +({ \ + const struct { uint32_t r; } __attribute__ ((__packed__)) *__ptr \ + = (__typeof(__ptr))(addr); \ + __ptr->r; \ +}) + +#define put16(addr, val) \ +do { \ + struct { uint16_t r; } __attribute__ ((__packed__)) *__ptr \ + = (__typeof(__ptr))(addr); \ + __ptr->r = val; \ +} while (0) +#define put32(addr, val) \ +do { \ + struct { uint32_t r; } __attribute__ ((__packed__)) *__ptr \ + = (__typeof(__ptr))(addr); \ + __ptr->r = val; \ +} while (0) /* Structure for alias definition. Simply two strings. */ struct gconv_alias -- cgit 1.4.1