Here's a basic patch, tested on amd64 and sparc64.
It passes all unit tests, and the compiler didn't generate an actual memcpy
call on either architecture.
--- a/librt_internal.c
+++ b/librt_internal.c
@@ -3,6 +3,7 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <stdint.h>
+#include <string.h>
#include "CPy.h"
#define LIBRT_INTERNAL_MODULE
#include "librt_internal.h"
@@ -41,13 +42,14 @@
#define _READ(result, data, type) \
do { \
- *(result) = *(type *)(((ReadBufferObject *)data)->ptr); \
+ memcpy((void *) result, ((ReadBufferObject *)data)->ptr, sizeof(type)); \
((ReadBufferObject *)data)->ptr += sizeof(type); \
} while (0)
#define _WRITE(data, type, v) \
do { \
- *(type *)(((WriteBufferObject *)data)->ptr) = v; \
+ type temp = v; \
+ memcpy(((WriteBufferObject *)data)->ptr, (const void *) &temp, sizeof(type)); \
((WriteBufferObject *)data)->ptr += sizeof(type); \
} while (0)