From 71fb79492cb955af4bd52e79f1fa69d17e084dbc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 19 Dec 2017 12:16:24 -0800 Subject: altos/scheme: Replace memory pool macros with inlines AO_SCHEME_IS_CONST -> ao_scheme_is_const_addr AO_SCHEME_IS_POOL -> ao_scheme_is_pool_addr Provides better typechecking and avoids confusion with ao_scheme_is_const inline (which takes an ao_poly instead of a void *) Signed-off-by: Keith Packard --- src/scheme/ao_scheme.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/scheme/ao_scheme.h') diff --git a/src/scheme/ao_scheme.h b/src/scheme/ao_scheme.h index b8e683fb..5cae0bda 100644 --- a/src/scheme/ao_scheme.h +++ b/src/scheme/ao_scheme.h @@ -155,8 +155,17 @@ ao_scheme_is_const(ao_poly poly) { return poly & AO_SCHEME_CONST; } -#define AO_SCHEME_IS_CONST(a) (ao_scheme_const <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_scheme_const + AO_SCHEME_POOL_CONST) -#define AO_SCHEME_IS_POOL(a) (ao_scheme_pool <= ((uint8_t *) (a)) && ((uint8_t *) (a)) < ao_scheme_pool + AO_SCHEME_POOL) +static inline int +ao_scheme_is_const_addr(const void *addr) { + const uint8_t *a = addr; + return (ao_scheme_const <= a) && (a < ao_scheme_const + AO_SCHEME_POOL_CONST); +} + +static inline int +ao_scheme_is_pool_addr(const void *addr) { + const uint8_t *a = addr; + return (ao_scheme_pool <= a) && (a < ao_scheme_pool + AO_SCHEME_POOL); +} void * ao_scheme_ref(ao_poly poly); -- cgit v1.2.3