Skip to content

Commit 564e464

Browse files
committed
py: Add generic helper to align a pointer.
1 parent 58c9586 commit 564e464

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

py/misc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ int m_get_peak_bytes_allocated(void);
8484
// get the number of elements in a fixed-size array
8585
#define MP_ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
8686

87+
// align ptr to the nearest multiple of "alignment"
88+
#define MP_ALIGN(ptr, alignment) (void*)(((mp_uint_t)(ptr) + ((alignment) - 1)) & ~((alignment) - 1))
89+
8790
/** unichar / UTF-8 *********************************************/
8891

8992
typedef int unichar; // TODO

0 commit comments

Comments
 (0)