summaryrefslogtreecommitdiff
path: root/py/gc.h
diff options
context:
space:
mode:
authorDavid Grimes <dgrimes@navisite.com>2019-11-22 13:47:13 -0500
committerDavid Grimes <dgrimes@navisite.com>2019-11-22 13:47:13 -0500
commitf13ba7e8d9048802e960b45264f7d85cc16a1a4d (patch)
treef6f7686528e60c6de291d3c9ef0160c88369644e /py/gc.h
parentc000567d880b054ca9ed0e9f96ee474451e92e3c (diff)
* only make objects long lived if they are on the GC heap
Diffstat (limited to 'py/gc.h')
-rw-r--r--py/gc.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/py/gc.h b/py/gc.h
index 02bf45158..cd63ba94c 100644
--- a/py/gc.h
+++ b/py/gc.h
@@ -29,8 +29,19 @@
#include <stdint.h>
#include "py/mpconfig.h"
+#include "py/mpstate.h"
#include "py/misc.h"
+#define WORDS_PER_BLOCK ((MICROPY_BYTES_PER_GC_BLOCK) / BYTES_PER_WORD)
+#define BYTES_PER_BLOCK (MICROPY_BYTES_PER_GC_BLOCK)
+
+// ptr should be of type void*
+#define VERIFY_PTR(ptr) ( \
+ ((uintptr_t)(ptr) & (BYTES_PER_BLOCK - 1)) == 0 /* must be aligned on a block */ \
+ && ptr >= (void*)MP_STATE_MEM(gc_pool_start) /* must be above start of pool */ \
+ && ptr < (void*)MP_STATE_MEM(gc_pool_end) /* must be below end of pool */ \
+ )
+
void gc_init(void *start, void *end);
void gc_deinit(void);