Skip to content

Commit 2863153

Browse files
committed
py: Add MICROPY_OBJ_BASE_ALIGNMENT to help with 16-bit ports.
1 parent 5351a48 commit 2863153

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

py/mpconfig.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,14 @@ typedef double mp_float_t;
536536
/*****************************************************************************/
537537
/* Miscellaneous settings */
538538

539+
// All uPy objects in ROM must be aligned on at least a 4 byte boundary
540+
// so that the small-int/qstr/pointer distinction can be made. For machines
541+
// that don't do this (eg 16-bit CPU), define the following macro to something
542+
// like __attribute__((aligned(4))).
543+
#ifndef MICROPY_OBJ_BASE_ALIGNMENT
544+
#define MICROPY_OBJ_BASE_ALIGNMENT
545+
#endif
546+
539547
// On embedded platforms, these will typically enable/disable irqs.
540548
#ifndef MICROPY_BEGIN_ATOMIC_SECTION
541549
#define MICROPY_BEGIN_ATOMIC_SECTION() (0)

py/obj.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef machine_const_ptr_t mp_const_obj_t;
4646

4747
struct _mp_obj_type_t;
4848
struct _mp_obj_base_t {
49-
const struct _mp_obj_type_t *type;
49+
const struct _mp_obj_type_t *type MICROPY_OBJ_BASE_ALIGNMENT;
5050
};
5151
typedef struct _mp_obj_base_t mp_obj_base_t;
5252

0 commit comments

Comments
 (0)