From 28631537bd14d0497c8d51d796cdda45b3719890 Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Sun, 8 Feb 2015 13:42:00 +0000
Subject: [PATCH] py: Add MICROPY_OBJ_BASE_ALIGNMENT to help with 16-bit ports.

---
 py/mpconfig.h | 8 ++++++++
 py/obj.h      | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/py/mpconfig.h b/py/mpconfig.h
index e8c8fcc59..b235d6fe6 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -536,6 +536,14 @@ typedef double mp_float_t;
 /*****************************************************************************/
 /* Miscellaneous settings                                                    */
 
+// All uPy objects in ROM must be aligned on at least a 4 byte boundary
+// so that the small-int/qstr/pointer distinction can be made.  For machines
+// that don't do this (eg 16-bit CPU), define the following macro to something
+// like __attribute__((aligned(4))).
+#ifndef MICROPY_OBJ_BASE_ALIGNMENT
+#define MICROPY_OBJ_BASE_ALIGNMENT
+#endif
+
 // On embedded platforms, these will typically enable/disable irqs.
 #ifndef MICROPY_BEGIN_ATOMIC_SECTION
 #define MICROPY_BEGIN_ATOMIC_SECTION() (0)
diff --git a/py/obj.h b/py/obj.h
index 1b1f82414..0f6179630 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -46,7 +46,7 @@ typedef machine_const_ptr_t mp_const_obj_t;
 
 struct _mp_obj_type_t;
 struct _mp_obj_base_t {
-    const struct _mp_obj_type_t *type;
+    const struct _mp_obj_type_t *type MICROPY_OBJ_BASE_ALIGNMENT;
 };
 typedef struct _mp_obj_base_t mp_obj_base_t;
 
-- 
GitLab