#ifndef HEADER_INTERNAL_REFCOUNT_H
# define HEADER_INTERNAL_REFCOUNT_H
-# if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
+/* Used to checking reference counts, most while doing perl5 stuff :-) */
+# if defined(OPENSSL_NO_STDIO)
+# if defined(REF_PRINT)
+# error "REF_PRINT requires stdio"
+# endif
+# endif
+
+# if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
+ && !defined(__STDC_NO_ATOMICS__)
# include <stdatomic.h>
# define HAVE_C11_ATOMICS
# endif
-# if defined(HAVE_C11_ATOMICS) && ATOMIC_INT_LOCK_FREE > 0
+# if defined(HAVE_C11_ATOMICS) && defined(ATOMIC_INT_LOCK_FREE) \
+ && ATOMIC_INT_LOCK_FREE > 0
# define HAVE_ATOMICS 1
# define CRYPTO_DOWN_REF(val, ret, lock) CRYPTO_atomic_add(val, -1, ret, lock)
# endif
+
+# if !defined(NDEBUG) && !defined(OPENSSL_NO_STDIO)
+# define REF_ASSERT_ISNT(test) \
+ (void)((test) ? (OPENSSL_die("refcount error", __FILE__, __LINE__), 1) : 0)
+# else
+# define REF_ASSERT_ISNT(i)
+# endif
+
+# ifdef REF_PRINT
+# define REF_PRINT_COUNT(a, b) \
+ fprintf(stderr, "%p:%4d:%s\n", b, b->references, a)
+# else
+# define REF_PRINT_COUNT(a, b)
+# endif
+
#endif