diff --git a/src/array.c b/src/array.c
index 20027b63db9c8f7a75e310d1b173ed8388c66ab3..0c202d42366d1084266d2a15614a5c953ec5d87a 100644
--- a/src/array.c
+++ b/src/array.c
@@ -417,7 +417,7 @@ PMOD_EXPORT struct array *array_insert(struct array *v,struct svalue *s,INT32 in
       int e = v->size;
       struct svalue *s = ITEM(ret);
       while (e--) {
-	if (TYPEOF(*s) <= MAX_REF_TYPE) add_ref(s->u.dummy);
+	if (REFCOUNTED_TYPE(TYPEOF(*s))) add_ref(s->u.dummy);
 	s++;
       }
     }
diff --git a/src/builtin_functions.c b/src/builtin_functions.c
index 89a5a18c11747c6927e4227dfd6097925fa376cb..fd514a5841336552f04de2ccb83fd248e354f159 100644
--- a/src/builtin_functions.c
+++ b/src/builtin_functions.c
@@ -7728,7 +7728,7 @@ PMOD_EXPORT void f__refs(INT32 args)
   if(!args)
     SIMPLE_TOO_FEW_ARGS_ERROR("_refs", 1);
 
-  if(TYPEOF(Pike_sp[-args]) > MAX_REF_TYPE)
+  if(!REFCOUNTED_TYPE(TYPEOF(Pike_sp[-args])))
     SIMPLE_BAD_ARG_ERROR("refs", 1,
 			 "array|mapping|multiset|object|"
 			 "function|program|string");
@@ -7749,7 +7749,7 @@ PMOD_EXPORT void f__leak(INT32 args)
   if(!args)
     SIMPLE_TOO_FEW_ARGS_ERROR("_leak", 1);
 
-  if(TYPEOF(Pike_sp[-args]) > MAX_REF_TYPE)
+  if(!REFCOUNTED_TYPE(TYPEOF(Pike_sp[-args])))
     SIMPLE_BAD_ARG_ERROR("_leak", 1,
 			 "array|mapping|multiset|object|"
 			 "function|program|string");
@@ -8436,7 +8436,7 @@ PMOD_EXPORT void f__gc_set_watch(INT32 args)
 
   if (args < 1)
     SIMPLE_TOO_FEW_ARGS_ERROR("_gc_set_watch", 1);
-  if (TYPEOF(Pike_sp[-args]) > MAX_REF_TYPE)
+  if (!REFCOUNTED_TYPE(TYPEOF(Pike_sp[-args])))
     SIMPLE_BAD_ARG_ERROR("_gc_set_watch", 1, "reference type");
   gc_watch(Pike_sp[-args].u.refs);
   pop_n_elems(args);
diff --git a/src/code/ia32.c b/src/code/ia32.c
index 0e7e095e8a4c94e7630fe0324ef45b3251efb93c..860ca516c31e77763fd748993ee1ddabd208e779 100644
--- a/src/code/ia32.c
+++ b/src/code/ia32.c
@@ -539,7 +539,7 @@ static void ia32_call_c_function(void *addr)
 static void ia32_push_constant(struct svalue *tmp)
 {
   int e;
-  if(tmp->type <= MAX_REF_TYPE)
+  if(REFCOUNTED_TYPE(TYPEOF(*tmp)))
     ADD_VAL_TO_ABSADDR (1, tmp->u.refs);
 
   load_pi_reg (0);
@@ -1045,7 +1045,7 @@ void ins_f_byte_with_arg(unsigned int a, INT32 b)
        *
        * /grubba 2003-12-11
        */
-      if((Pike_compiler->new_program->constants[b].sval.type > MAX_REF_TYPE) &&
+      if(!REFCOUNTED_TYPE(TYPEOF(Pike_compiler->new_program->constants[b].sval)) &&
 	 !Pike_compiler->new_program->constants[b].sval.subtype)
       {
 	ins_debug_instr_prologue (a - F_OFFSET, b, 0);
diff --git a/src/code/ppc32.c b/src/code/ppc32.c
index 29edb044b5e87b84fb13a46a33a1a5d2ed0a4a82..e2b5d81c9a8dae6180a2f7ef9c5dc0e6b71176fe 100644
--- a/src/code/ppc32.c
+++ b/src/code/ppc32.c
@@ -173,7 +173,7 @@ void ppc32_push_constant(INT32 arg)
    * Note: The constants table may contain UNDEFINED in case of being
    *       called through decode_value() in PORTABLE_BYTECODE mode.
    */
-  if((sval->type > MAX_REF_TYPE) && !sval->subtype) {
+  if(!REFCOUNTED_TYPE(TYPEOF(*sval)) && !sval->subtype) {
     int e;
     INT32 last=0;
 
@@ -209,7 +209,7 @@ void ppc32_push_constant(INT32 arg)
       offs -= 65536;
   }
 
-  ppc32_push_svalue(PPC_REG_ARG1, offs, (sval->type <= MAX_REF_TYPE));
+  ppc32_push_svalue(PPC_REG_ARG1, offs, !!REFCOUNTED_TYPE(TYPEOF(*sval)));
 }
 
 void ppc32_push_local(INT32 arg)
diff --git a/src/code/ppc64.c b/src/code/ppc64.c
index 5c55eab37f0a1ce5a539bdd38c394cbba5b2a8c5..521214c078a5efe74719f23e913c933e3c67f3bd 100644
--- a/src/code/ppc64.c
+++ b/src/code/ppc64.c
@@ -150,7 +150,7 @@ void ppc64_push_constant(INT32 arg)
    * Note: The constants table may contain UNDEFINED in case of being
    *       called through decode_value() in PORTABLE_BYTECODE mode.
    */
-  if((sval->type > MAX_REF_TYPE) && !sval->subtype) {
+  if(!REFCOUNTED_TYPE(TYPEOF(*sval)) && !sval->subtype) {
     int e;
     INT64 last=0;
 
@@ -186,7 +186,7 @@ void ppc64_push_constant(INT32 arg)
       offs -= 65536;
   }
 
-  ppc64_push_svalue(PPC_REG_ARG1, offs, (sval->type <= MAX_REF_TYPE));
+  ppc64_push_svalue(PPC_REG_ARG1, offs, !!REFCOUNTED_TYPE(TYPEOF(*sval)));
 }
 
 void ppc64_push_local(INT32 arg)
diff --git a/src/dmalloc.h b/src/dmalloc.h
index 678ec2d4d43a73ff2e2ef70ae31b6f7bfb7465b5..078c764b14426eaff66e0446a196cb30cec54cb1 100644
--- a/src/dmalloc.h
+++ b/src/dmalloc.h
@@ -148,13 +148,13 @@ PMOD_EXPORT void debug_malloc_dump_references(void *x, int indent, int depth, in
 void debug_malloc_dump_fd(int fd);
 #define dmalloc_touch_svalue(X) do {		\
     const struct svalue *_tmp = (X);		\
-    if (TYPEOF(*_tmp) <= MAX_REF_TYPE) {	\
+    if (REFCOUNTED_TYPE(TYPEOF(*_tmp))) {	\
       debug_malloc_touch(_tmp->u.refs);		\
     }						\
   } while(0)
 #define dmalloc_touch_svalue_named(X,NAME) do {		\
     const struct svalue *_tmp = (X);			\
-    if (TYPEOF(*_tmp) <= MAX_REF_TYPE) {		\
+    if (REFCOUNTED_TYPE(TYPEOF(*_tmp))) {		\
       debug_malloc_touch_named(_tmp->u.refs,NAME);	\
     }							\
   } while(0)
diff --git a/src/error.c b/src/error.c
index 77287709123083f692c40033577b718046c786b1..a5e5de237c5dba0c2267e6bc05bad2e8689f9339 100644
--- a/src/error.c
+++ b/src/error.c
@@ -203,7 +203,7 @@ PMOD_EXPORT DECLSPEC(noreturn) void pike_throw(void) ATTRIBUTE((noreturn))
 
 #if defined(DEBUG_MALLOC) && defined(PIKE_DEBUG)
   /* This will tell us where the value was caught (I hope) */
-  if(TYPEOF(throw_value) <= MAX_REF_TYPE)
+  if(REFCOUNTED_TYPE(TYPEOF(throw_value)))
   {
     debug_malloc_update_location(throw_value.u.refs,
 				 Pike_interpreter.recoveries->file);
diff --git a/src/gc.c b/src/gc.c
index 827a1563bf9eb72d096ac13f92edfe5661b3080b..80127be575eb40b52767b09582f22086135cc95d 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -5557,7 +5557,7 @@ void f_count_memory (INT32 args)
       if (TYPEOF(*s) == T_INT)
 	continue;
 
-      else if (TYPEOF(*s) > MAX_REF_TYPE) {
+      else if (!REFCOUNTED_TYPE(TYPEOF(*s))) {
 	exit_mc_marker_hash();
 	free (mc_work_queue + 1);
 	mc_work_queue = NULL;
diff --git a/src/gc.h b/src/gc.h
index 1d334b1b2b028f740f25187fbf89f86f966daf45..9695e63304306e14f190d23e38bf4909c582470d 100644
--- a/src/gc.h
+++ b/src/gc.h
@@ -669,7 +669,7 @@ static INLINE int real_visit_short_svalue (union anything *u, TYPE_T t,
 					   int ref_type)
 {
   check_short_svalue (u, t);
-  if (t <= MAX_REF_TYPE)
+  if (REFCOUNTED_TYPE(t))
     visit_ref (u->ptr, ref_type, visit_fn_from_type[t], NULL);
   return 0;
 }
@@ -690,7 +690,7 @@ static INLINE void dmalloc_visit_svalue (struct svalue *s,
   int t = TYPEOF(*s);
   check_svalue (s);
   dmalloc_check_svalue (s, l);
-  if (t <= MAX_REF_TYPE) {
+  if (REFCOUNTED_TYPE(t)) {
     if (t == PIKE_T_FUNCTION) visit_function (s, ref_type);
     else visit_ref (s->u.ptr, ref_type, visit_fn_from_type[t], NULL);
   }
@@ -703,7 +703,7 @@ static INLINE void visit_svalue (struct svalue *s, int ref_type)
 {
   int t = TYPEOF(*s);
   check_svalue (s);
-  if (t <= MAX_REF_TYPE) {
+  if (REFCOUNTED_TYPE(t)) {
     if (t == PIKE_T_FUNCTION) visit_function (s, ref_type);
     else visit_ref (s->u.ptr, ref_type, visit_fn_from_type[t], NULL);
   }
diff --git a/src/mapping.c b/src/mapping.c
index dce0637a06046be084f6fc6e53e5baff525876c7..33cb343baaae89cd52222a72b5f6389cdc3df3e8 100644
--- a/src/mapping.c
+++ b/src/mapping.c
@@ -338,13 +338,13 @@ static void mapping_rehash_backwards_evil(struct mapping_data *md,
       default:
 	Pike_fatal("Instable mapping data flags.\n");
       case MAPPING_WEAK_INDICES:
-	if ((TYPEOF(from->ind) <= MAX_REF_TYPE) &&
+	if (REFCOUNTED_TYPE(TYPEOF(from->ind)) &&
 	    (*from->ind.u.refs > 1)) {
 	  goto keep_keypair;
 	}
 	break;
       case MAPPING_WEAK_VALUES:
-	if ((TYPEOF(from->val) <= MAX_REF_TYPE) &&
+	if (REFCOUNTED_TYPE(TYPEOF(from->val)) &&
 	    (*from->val.u.refs > 1)) {
 	  goto keep_keypair;
 	}
@@ -353,9 +353,9 @@ static void mapping_rehash_backwards_evil(struct mapping_data *md,
 	/* NB: Compat: Unreference counted values are counted
 	 *             as multi-referenced here.
 	 */
-	if (((TYPEOF(from->ind) > MAX_REF_TYPE) ||
+	if ((!REFCOUNTED_TYPE(TYPEOF(from->ind)) ||
 	     (*from->ind.u.refs > 1)) &&
-	    ((TYPEOF(from->val) > MAX_REF_TYPE) ||
+	    (!REFCOUNTED_TYPE(TYPEOF(from->val)) ||
 	     (*from->val.u.refs > 1))) {
 	  goto keep_keypair;
 	}
@@ -431,13 +431,13 @@ static void mapping_rehash_backwards_good(struct mapping_data *md,
       default:
 	Pike_fatal("Instable mapping data flags.\n");
       case MAPPING_WEAK_INDICES:
-	if ((TYPEOF(from->ind) <= MAX_REF_TYPE) &&
+	if (REFCOUNTED_TYPE(TYPEOF(from->ind)) &&
 	    (*from->ind.u.refs > 1)) {
 	  goto keep_keypair;
 	}
 	break;
       case MAPPING_WEAK_VALUES:
-	if ((TYPEOF(from->val) <= MAX_REF_TYPE) &&
+	if (REFCOUNTED_TYPE(TYPEOF(from->val)) &&
 	    (*from->val.u.refs > 1)) {
 	  goto keep_keypair;
 	}
@@ -446,9 +446,9 @@ static void mapping_rehash_backwards_good(struct mapping_data *md,
 	/* NB: Compat: Unreference counted values are counted
 	 *             as multi-referenced here.
 	 */
-	if (((TYPEOF(from->ind) > MAX_REF_TYPE) ||
+	if ((!REFCOUNTED_TYPE(TYPEOF(from->ind)) ||
 	     (*from->ind.u.refs > 1)) &&
-	    ((TYPEOF(from->val) > MAX_REF_TYPE) ||
+	    (!REFCOUNTED_TYPE(TYPEOF(from->val)) ||
 	     (*from->val.u.refs > 1))) {
 	  goto keep_keypair;
 	}
diff --git a/src/modules/Gmp/mpq.cmod b/src/modules/Gmp/mpq.cmod
index e8e20c88f8b0029e625962c6415c59f2106ee5c6..0832d75707811c5d789249eea60447d8f7c1201c 100644
--- a/src/modules/Gmp/mpq.cmod
+++ b/src/modules/Gmp/mpq.cmod
@@ -265,7 +265,7 @@ PIKECLASS mpq
 
 #ifdef DEBUG_MALLOC
 #define get_mpq(S, THROW_ERROR, ARG_FUNC, ARG, ARGS)			\
-  (TYPEOF(*(S)) <= MAX_REF_TYPE ? debug_malloc_touch((S)->u.object) : 0, \
+  (REFCOUNTED_TYPE(TYPEOF(*(S))) ? debug_malloc_touch((S)->u.object) : 0, \
    debug_get_mpq((S), (THROW_ERROR), (ARG_FUNC), (ARG), (ARGS)))
 #else
 #define get_mpq debug_get_mpq
diff --git a/src/modules/Gmp/mpz_glue.c b/src/modules/Gmp/mpz_glue.c
index 70432755c693f6a9a90ef876c34cb4059bfdc6ae..0d5d70face78000e3e46179cfba6127e36ef4159 100644
--- a/src/modules/Gmp/mpz_glue.c
+++ b/src/modules/Gmp/mpz_glue.c
@@ -2493,7 +2493,7 @@ PIKE_MODULE_INIT
     
     /* Magic hook in... */
 #ifdef PIKE_DEBUG
-    if (TYPEOF(auto_bignum_program) <= MAX_REF_TYPE) {
+    if (REFCOUNTED_TYPE(TYPEOF(auto_bignum_program))) {
       Pike_fatal("Strange initial value for auto_bignum_program\n");
     }
 #endif /* PIKE_DEBUG */
diff --git a/src/modules/Gmp/my_gmp.h b/src/modules/Gmp/my_gmp.h
index 806d988dc7b29272a8d475b188a4dca08fbd3ea9..bc78bb116bb29fe0d2795086a097e29536e1d915 100644
--- a/src/modules/Gmp/my_gmp.h
+++ b/src/modules/Gmp/my_gmp.h
@@ -113,7 +113,7 @@ extern struct program *bignum_program;
 
 #ifdef DEBUG_MALLOC
 #define get_mpz(S, THROW_ERROR, ARG_FUNC, ARG, ARGS)			\
-  ((S)->type <= MAX_REF_TYPE ? debug_malloc_touch((S)->u.object) : 0,	\
+  (REFCOUNTED_TYPE(TYPEOF(*(S))) ? debug_malloc_touch((S)->u.object) : 0, \
    debug_get_mpz((S), (THROW_ERROR), (ARG_FUNC), (ARG), (ARGS)))
 #else
 #define get_mpz debug_get_mpz 
diff --git a/src/object.c b/src/object.c
index 91ee24c0cc935bddda703702bc93261859c69792..3cf37f5a1c82c9e0cc16b276a0df7b37688f6d8c 100644
--- a/src/object.c
+++ b/src/object.c
@@ -907,7 +907,7 @@ PMOD_EXPORT void destruct_object (struct object *o, enum object_destruct_reason
 	union anything *u;
 	u=(union anything *)(storage + id->func.offset);
 #ifdef DEBUG_MALLOC
-	if (rtt <= MAX_REF_TYPE) {debug_malloc_touch(u->refs);}
+	if (REFCOUNTED_TYPE(rtt)) {debug_malloc_touch(u->refs);}
 #endif
 	if (rtt != T_OBJECT || u->object != o ||
 	    !(identifier_flags & IDENTIFIER_NO_THIS_REF)) {
@@ -1515,7 +1515,7 @@ static void object_lower_set_index(struct object *o, union idptr func, int rtt,
       dmalloc_touch_svalue (to);
       if ((TYPEOF(*to) != T_OBJECT && TYPEOF(*to) != T_FUNCTION) ||
 	  (to->u.object != o)) {
-	if(TYPEOF(*to) <= MAX_REF_TYPE) {
+	if(REFCOUNTED_TYPE(TYPEOF(*to))) {
 	  (void) debug_malloc_update_location(o, DMALLOC_NAMED_LOCATION(" store_global"));
 	  add_ref(to->u.dummy);
 #ifdef DEBUG_MALLOC
@@ -2114,7 +2114,7 @@ PMOD_EXPORT void visit_object (struct object *o, int action)
 	var = inh_storage + id->func.offset;
 	u = (union anything *) var;
 #ifdef DEBUG_MALLOC
-	if (rtt <= MAX_REF_TYPE)
+	if (REFCOUNTED_TYPE(rtt))
 	  debug_malloc_touch (u->ptr);
 #endif
 
@@ -2268,7 +2268,7 @@ PMOD_EXPORT void gc_mark_object_as_referenced(struct object *o)
 	      union anything *u;
 	      u=(union anything *)(pike_frame->current_storage + id->func.offset);
 #ifdef DEBUG_MALLOC
-	      if (rtt <= MAX_REF_TYPE) debug_malloc_touch(u->refs);
+	      if (REFCOUNTED_TYPE(rtt)) debug_malloc_touch(u->refs);
 #endif
 	      if (rtt != T_OBJECT || u->object != o ||
 		  !(id_flags & IDENTIFIER_NO_THIS_REF))
@@ -2334,7 +2334,7 @@ PMOD_EXPORT void real_gc_cycle_check_object(struct object *o, int weak)
 	    union anything *u;
 	    u=(union anything *)(pike_frame->current_storage + id->func.offset);
 #ifdef DEBUG_MALLOC
-	    if (rtt <= MAX_REF_TYPE) debug_malloc_touch(u->refs);
+	    if (REFCOUNTED_TYPE(rtt)) debug_malloc_touch(u->refs);
 #endif
 	    if (rtt != T_OBJECT || u->object != o ||
 		!(id_flags & IDENTIFIER_NO_THIS_REF))
@@ -2408,7 +2408,7 @@ static void gc_check_object(struct object *o)
 	    union anything *u;
 	    u=(union anything *)(pike_frame->current_storage + id->func.offset);
 #ifdef DEBUG_MALLOC
-	    if (rtt <= MAX_REF_TYPE) debug_malloc_touch(u->refs);
+	    if (REFCOUNTED_TYPE(rtt)) debug_malloc_touch(u->refs);
 #endif
 	    if (rtt != T_OBJECT || u->object != o ||
 		!(id_flags & IDENTIFIER_NO_THIS_REF))
diff --git a/src/pike_search_engine.c b/src/pike_search_engine.c
index 305f039ef176842ff8266c904844e45d0bc95971..54e88e04aca5b714a8ae445256f5277d6715655f 100644
--- a/src/pike_search_engine.c
+++ b/src/pike_search_engine.c
@@ -334,7 +334,7 @@ SearchMojt NameN(compile_memsearcher)(NCHAR *needle,
 	struct keypair **prev;
 	for(prev = md->hash + e; (k = *prev);) {
 	  count++;
-	  if ((TYPEOF(k->val) <= MAX_REF_TYPE) &&
+	  if (REFCOUNTED_TYPE(TYPEOF(k->val)) &&
 	      (*k->val.u.refs == 1)) {
 	    /* map_delete(memsearch_cache, &k->ind); */
 	    *prev = k->next;
diff --git a/src/svalue.c b/src/svalue.c
index 3aa4e4159be879fe49d1f33c3f57a338e6eefc84..7b1caef280eb5dee2561b516130684914c416d7e 100644
--- a/src/svalue.c
+++ b/src/svalue.c
@@ -254,7 +254,7 @@ PMOD_EXPORT void debug_free_svalues(struct svalue *s, size_t num, INT32 type_hin
     while(num--)
       {
 #ifdef DEBUG_MALLOC
-	if(TYPEOF(*s) <= MAX_REF_TYPE)
+	if(REFCOUNTED_TYPE(TYPEOF(*s)))
 	  debug_malloc_update_location(s->u.refs  DMALLOC_PROXY_ARGS);
 #endif
 	free_svalue(s++);
@@ -267,7 +267,7 @@ PMOD_EXPORT void debug_free_mixed_svalues(struct svalue *s, size_t num, INT32 UN
   while(num--)
   {
 #ifdef DEBUG_MALLOC
-    if(TYPEOF(*s) <= MAX_REF_TYPE)
+    if(REFCOUNTED_TYPE(TYPEOF(*s)))
       debug_malloc_update_location(s->u.refs  DMALLOC_PROXY_ARGS);
 #endif
     free_svalue(s++);
@@ -300,7 +300,7 @@ PMOD_EXPORT TYPE_FIELD assign_svalues_no_free(struct svalue *to,
   type_hint = 0;
   while(num--) {
     type_hint |= 1 << TYPEOF(*from);
-    if (TYPEOF(*from) <= MAX_REF_TYPE) {
+    if (REFCOUNTED_TYPE(TYPEOF(*from))) {
       add_ref(from->u.dummy);
     }
     from++;
@@ -336,7 +336,7 @@ PMOD_EXPORT void assign_to_short_svalue(union anything *u,
 	u->refs = s->u.refs;
 	add_ref(u->dummy);
     }
-  }else if(type<=MAX_REF_TYPE && UNSAFE_IS_ZERO(s)){
+  }else if(REFCOUNTED_TYPE(type) && UNSAFE_IS_ZERO(s)){
     if(u->refs && !sub_ref(u->dummy)) really_free_short_svalue(u,type);
     u->refs=0;
   }else{
@@ -363,7 +363,7 @@ PMOD_EXPORT void assign_to_short_svalue_no_free(union anything *u,
 	u->refs = s->u.refs;
 	add_ref(u->dummy);
     }
-  }else if(type<=MAX_REF_TYPE && UNSAFE_IS_ZERO(s)){
+  }else if(REFCOUNTED_TYPE(type) && UNSAFE_IS_ZERO(s)){
     u->refs=0;
   }else{
     Pike_error("Wrong type in assignment, expected %s, got %s.\n",
@@ -1806,7 +1806,7 @@ PMOD_EXPORT void safe_print_svalue (FILE *out, const struct svalue *s)
 
 PMOD_EXPORT void print_short_svalue (FILE *out, const union anything *a, TYPE_T type)
 {
-  if (type <= MAX_REF_TYPE && !a->dummy)
+  if (REFCOUNTED_TYPE(type) && !a->dummy)
     fputc ('0', out);
   else {
     struct svalue sval;
@@ -1861,7 +1861,7 @@ PMOD_EXPORT void safe_print_svalue_compact (FILE *out, const struct svalue *s)
 
 PMOD_EXPORT void print_short_svalue_compact (FILE *out, const union anything *a, TYPE_T type)
 {
-  if (type <= MAX_REF_TYPE && !a->dummy)
+  if (REFCOUNTED_TYPE(type) && !a->dummy)
     fputs ("0", out);
   else {
     struct svalue sval;
@@ -1926,7 +1926,7 @@ PMOD_EXPORT void copy_svalues_recursively_no_free(struct svalue *to,
       /* Recursive data */
       if (m && (tmp = low_mapping_lookup(m, from))) {
 	*to = *tmp;
-	if (TYPEOF(*tmp) <= MAX_REF_TYPE) add_ref(tmp->u.dummy);
+	if (REFCOUNTED_TYPE(TYPEOF(*tmp))) add_ref(tmp->u.dummy);
       } else {
 #define ALLOC_DUPL_MAPPING(type_hint)				\
 	do if (!m && (type_hint) & BIT_COMPLEX) {		\
@@ -1953,7 +1953,7 @@ PMOD_EXPORT void copy_svalues_recursively_no_free(struct svalue *to,
       }
     } else {
       *to = *from;
-      if (from_type <= MAX_REF_TYPE) add_ref(from->u.array);
+      if (REFCOUNTED_TYPE(from_type)) add_ref(from->u.array);
     }
     
     to++;
@@ -2023,7 +2023,7 @@ void low_thorough_check_short_svalue (const union anything *u, TYPE_T type)
 static void low_check_short_svalue(const union anything *u, TYPE_T type)
 {
   check_type(type);
-  if ((type > MAX_REF_TYPE)||(!u->refs)) return;
+  if (!REFCOUNTED_TYPE(type) || (!u->refs)) return;
 
   switch(type)
   {
@@ -2041,7 +2041,7 @@ static void low_check_short_svalue(const union anything *u, TYPE_T type)
 
 void check_short_svalue(const union anything *u, TYPE_T type)
 {
-  if(type<=MAX_REF_TYPE &&
+  if(REFCOUNTED_TYPE(type) &&
      ((PIKE_POINTER_ALIGNMENT-1) & (ptrdiff_t)(u->refs)))
     Pike_fatal("Odd pointer! type=%d u->refs=%p\n",type,u->refs);
 
@@ -2068,7 +2068,7 @@ PMOD_EXPORT void debug_svalue_type_error (const struct svalue *s)
 PMOD_EXPORT void debug_check_svalue(const struct svalue *s)
 {
   check_svalue_type (s);
-  if(TYPEOF(*s) <= MAX_REF_TYPE &&
+  if(REFCOUNTED_TYPE(TYPEOF(*s)) &&
      ((PIKE_POINTER_ALIGNMENT-1) & (ptrdiff_t)(s->u.refs)))
     Pike_fatal("Odd pointer! type=%d u->refs=%p, align: %d\n",
 	       TYPEOF(*s), s->u.refs, PIKE_POINTER_ALIGNMENT);
@@ -2118,7 +2118,7 @@ PMOD_EXPORT void real_gc_mark_external_svalues(const struct svalue *s, ptrdiff_t
     
     gc_svalue_location=(void *)s;
 
-    if(TYPEOF(*s) <= MAX_REF_TYPE)
+    if(REFCOUNTED_TYPE(TYPEOF(*s)))
       gc_mark_external (s->u.refs, place);
   }
   gc_svalue_location=0;
diff --git a/src/svalue.h b/src/svalue.h
index beef4ed74ef69c9b7d4f5c37c34588b1b66348e3..74c54472b528a00450196b314100cfe5d6557b1a 100644
--- a/src/svalue.h
+++ b/src/svalue.h
@@ -343,6 +343,8 @@ struct svalue
 /* Max type handled by svalue primitives */
 #define MAX_TYPE PIKE_T_FLOAT
 
+#define REFCOUNTED_TYPE(T)	((T) <= MAX_REF_TYPE)
+
 #define NUMBER_NUMBER 0
 #define NUMBER_UNDEFINED 1
 #define NUMBER_DESTRUCTED 2
@@ -448,14 +450,14 @@ void low_thorough_check_short_svalue (const union anything *u, TYPE_T type);
     TYPE_T typ_ = (T);							\
     check_short_svalue (anyth_, typ_);					\
     if (d_flag <= 50) /* Done directly by check_svalue otherwise. */	\
-      if (typ_ <= MAX_REF_TYPE)						\
+      if (REFCOUNTED_TYPE(typ_))					\
 	low_thorough_check_short_svalue (anyth_, typ_);			\
   } while (0)
 #define thorough_check_svalue(S) do {					\
     struct svalue *sval_ = (S);						\
     check_svalue (sval_);						\
     if (d_flag <= 50) /* Done directly by check_svalue otherwise. */	\
-      if (TYPEOF(*sval_) <= MAX_REF_TYPE)				\
+      if (REFCOUNTED_TYPE(TYPEOF(*sval_)))				\
 	low_thorough_check_short_svalue (&sval_->u, TYPEOF(*sval_));	\
   } while (0)
 
@@ -468,7 +470,7 @@ PMOD_EXPORT void real_gc_mark_external_svalues(const struct svalue *s, ptrdiff_t
 
 PMOD_EXPORT extern const char msg_sval_obj_wo_refs[];
 #define check_refs(S) do {\
- if(TYPEOF(*(S)) <= MAX_REF_TYPE && (!(S)->u.refs || (S)->u.refs[0] < 0)) { \
+ if(REFCOUNTED_TYPE(TYPEOF(*(S))) && (!(S)->u.refs || (S)->u.refs[0] < 0)) { \
    fprintf (stderr, "%s", msg_sval_obj_wo_refs);			\
    describe((S)->u.refs);						\
    Pike_fatal("%s", msg_sval_obj_wo_refs);				\
@@ -476,7 +478,7 @@ PMOD_EXPORT extern const char msg_sval_obj_wo_refs[];
 
 PMOD_EXPORT extern const char msg_ssval_obj_wo_refs[];
 #define check_refs2(S,T) do { \
-if((T) <= MAX_REF_TYPE && (S)->refs && (S)->refs[0] <= 0) {\
+if(REFCOUNTED_TYPE(T) && (S)->refs && (S)->refs[0] <= 0) {\
   fprintf (stderr, "%s", msg_ssval_obj_wo_refs);	   \
   describe((S)->refs);					   \
   Pike_fatal("%s", msg_ssval_obj_wo_refs);		   \
@@ -494,7 +496,7 @@ static INLINE struct svalue *dmalloc_check_svalue(struct svalue *s, char *l)
   debug_malloc_update_location(s,l);
 #endif
 #if 1
-  if(s && TYPEOF(*s) <= MAX_REF_TYPE)
+  if(s && REFCOUNTED_TYPE(TYPEOF(*s)))
     debug_malloc_update_location(s->u.refs,l);
 #endif
   return s;
@@ -512,7 +514,7 @@ static INLINE union anything *dmalloc_check_union(union anything *u,int type, ch
   debug_malloc_update_location(u,l);
 #endif
 #if 1
-  if(u && type <= MAX_REF_TYPE)
+  if(u && REFCOUNTED_TYPE(type))
     debug_malloc_update_location(u->refs,l);
 #endif
   return u;
@@ -630,7 +632,7 @@ static INLINE struct callable *pass_callable (struct callable *c) {return c;}
       check_refs(_s);						\
     }								\
   );								\
-  if (TYPEOF(*_s) > MAX_REF_TYPE)				\
+  if (!REFCOUNTED_TYPE(TYPEOF(*_s)))				\
     assert_free_svalue (_s);					\
   else {							\
     DO_IF_DEBUG (						\
@@ -648,7 +650,7 @@ static INLINE struct callable *pass_callable (struct callable *c) {return c;}
   union anything *_s=(X); TYPE_T _t=(T);				\
   check_type(_t); check_refs2(_s,_t);					\
   assert_svalue_locked(_s);						\
-  if(_t<=MAX_REF_TYPE && _s->refs) {					\
+  if(REFCOUNTED_TYPE(_t) && _s->refs) {					\
     DO_IF_DEBUG (							\
       DO_IF_PIKE_CLEANUP (						\
 	if (gc_external_refs_zapped)					\
@@ -668,7 +670,7 @@ static INLINE struct callable *pass_callable (struct callable *c) {return c;}
       check_refs(_tmp);						\
     }								\
   );								\
-  if(TYPEOF(*_tmp) <= MAX_REF_TYPE) add_ref(_tmp->u.dummy);	\
+  if(REFCOUNTED_TYPE(TYPEOF(*_tmp))) add_ref(_tmp->u.dummy);	\
 }while(0)
 
 /* Handles PIKE_T_FREE. */
@@ -684,7 +686,7 @@ static INLINE struct callable *pass_callable (struct callable *c) {return c;}
       Pike_fatal(msg_assign_svalue_error, _to);		\
   );							\
   *_to=*_from;						\
-  if(TYPEOF(*_to) <= MAX_REF_TYPE) add_ref(_to->u.dummy);	\
+  if(REFCOUNTED_TYPE(TYPEOF(*_to))) add_ref(_to->u.dummy); \
 }while(0)
 
 /* Handles PIKE_T_FREE. */
@@ -917,7 +919,7 @@ static INLINE void free_svalue(struct svalue *s)
 #ifndef free_short_svalue
 static INLINE void free_short_svalue(union anything *s, int t)
 {
-  if(t <= MAX_REF_TYPE)
+  if(REFCOUNTED_TYPE(t))
   {
     INT32 tmp;
     tmp=pike_atomic_swap32((INT32 *)s, 0);