Fix pgm_read_ macros with inline functions (#449)

Fixes #447
This commit is contained in:
Earle F. Philhower, III 2022-01-28 18:44:34 -08:00 committed by GitHub
parent d24c8442c4
commit d8835df9ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

@ -1 +1 @@
Subproject commit 9da53735171f7cccbe781c66d9ee1068d94d6ec8 Subproject commit ff01bb620e0c3386e39e032e209d9a07ad799d25

View file

@ -110,11 +110,23 @@ typedef const void* uint_farptr_t;
#define pgm_read_ptr(addr) (*(void *const *)(addr)) #define pgm_read_ptr(addr) (*(void *const *)(addr))
#else #else
// Supports misaligned addresses // Supports misaligned addresses
#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #ifdef __cplusplus
#define pgm_read_word(addr) ((unsigned short)(pgm_read_byte((intptr_t)addr) | (pgm_read_byte((intptr_t)addr + 1) << 8))) extern "C"{
#define pgm_read_dword(addr) ((unsigned long)(pgm_read_byte((intptr_t)addr) | (pgm_read_byte((intptr_t)addr + 1) << 8)) | \ #endif
(pgm_read_byte((intptr_t)addr + 2) << 16) | (pgm_read_byte((intptr_t)addr + 3) << 24)) static inline unsigned char pgm_read_byte(const void *addr) {
#define pgm_read_ptr(addr) ((void *)pgm_read_dword(addr)) return *(const unsigned char *)(addr);
}
static inline unsigned short pgm_read_word(const void *addr) {
const unsigned char *a = (const unsigned char *)addr;
return pgm_read_byte(a) | ( pgm_read_byte(a + 1) << 8 );
}
static inline unsigned long pgm_read_dword(const void *addr) {
const unsigned char *a = (const unsigned char *)addr;
return pgm_read_byte(a) | ( pgm_read_byte(a + 1) << 8 ) | ( pgm_read_byte(a + 2) << 16 ) | ( pgm_read_byte(a + 3) << 24 );
}
static inline void *pgm_read_ptr(const void *addr) {
return (void*) pgm_read_dword(addr);
}
static inline float pgm_read_float(const void *addr) { static inline float pgm_read_float(const void *addr) {
union { union {
void *p; void *p;
@ -123,6 +135,10 @@ static inline float pgm_read_float(const void *addr) {
x.p = pgm_read_ptr(addr); x.p = pgm_read_ptr(addr);
return x.f; return x.f;
} }
#ifdef __cplusplus
}
#endif
#endif #endif
#define pgm_read_byte_near(addr) pgm_read_byte(addr) #define pgm_read_byte_near(addr) pgm_read_byte(addr)