assert.h revision 1
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz/*
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz * All rights reserved.
fef1e07ef354c2dcda4dc397c33f5a5532432c7asl *
fef1e07ef354c2dcda4dc397c33f5a5532432c7asl * By using this file, you agree to the terms and conditions set
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz * forth in the LICENSE file which can be found at the top level of
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz * the sendmail distribution.
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz *
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz * $Id: assert.h,v 1.10 2001/06/07 20:04:53 ca Exp $
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz */
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz#pragma ident "%Z%%M% %I% %E% SMI"
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz/*
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz** libsm abnormal program termination and assertion checking
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz** See libsm/assert.html for documentation.
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz*/
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz#ifndef SM_ASSERT_H
fef1e07ef354c2dcda4dc397c33f5a5532432c7asl# define SM_ASSERT_H
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# include <sm/gen.h>
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# include <sm/debug.h>
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz/*
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz** abnormal program termination
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz*/
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yztypedef void (*SM_ABORT_HANDLER_T) __P((const char *, int, const char *));
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yzextern SM_DEAD(void
c138f478d2bc94e73ab8f6a084e323bec25e62f5yzsm_abort_at __P((
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz const char *,
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz int,
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz const char *)));
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yzextern void
c138f478d2bc94e73ab8f6a084e323bec25e62f5yzsm_abort_sethandler __P((
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz SM_ABORT_HANDLER_T));
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yzextern SM_DEAD(void PRINTFLIKE(1, 2)
c138f478d2bc94e73ab8f6a084e323bec25e62f5yzsm_abort __P((
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz char *,
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz ...)));
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz/*
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz** assertion checking
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz*/
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# ifndef SM_CHECK_ALL
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# define SM_CHECK_ALL 1
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# endif /* ! SM_CHECK_ALL */
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# ifndef SM_CHECK_REQUIRE
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# define SM_CHECK_REQUIRE SM_CHECK_ALL
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# endif /* ! SM_CHECK_REQUIRE */
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# ifndef SM_CHECK_ENSURE
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# define SM_CHECK_ENSURE SM_CHECK_ALL
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# endif /* ! SM_CHECK_ENSURE */
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# ifndef SM_CHECK_ASSERT
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# define SM_CHECK_ASSERT SM_CHECK_ALL
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# endif /* ! SM_CHECK_ASSERT */
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# if SM_CHECK_REQUIRE
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# if defined(__STDC__) || defined(__cplusplus)
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# define SM_REQUIRE(cond) \
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz ((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz "SM_REQUIRE(" #cond ") failed"), 0)))
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# else /* defined(__STDC__) || defined(__cplusplus) */
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# define SM_REQUIRE(cond) \
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz ((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz "SM_REQUIRE(cond) failed"), 0)))
c138f478d2bc94e73ab8f6a084e323bec25e62f5yz# endif /* defined(__STDC__) || defined(__cplusplus) */
# else /* SM_CHECK_REQUIRE */
# define SM_REQUIRE(cond) ((void) 0)
# endif /* SM_CHECK_REQUIRE */
# define SM_REQUIRE_ISA(obj, magic) \
SM_REQUIRE((obj) != NULL && (obj)->sm_magic == (magic))
# if SM_CHECK_ENSURE
# if defined(__STDC__) || defined(__cplusplus)
# define SM_ENSURE(cond) \
((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
"SM_ENSURE(" #cond ") failed"), 0)))
# else /* defined(__STDC__) || defined(__cplusplus) */
# define SM_ENSURE(cond) \
((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
"SM_ENSURE(cond) failed"), 0)))
# endif /* defined(__STDC__) || defined(__cplusplus) */
# else /* SM_CHECK_ENSURE */
# define SM_ENSURE(cond) ((void) 0)
# endif /* SM_CHECK_ENSURE */
# if SM_CHECK_ASSERT
# if defined(__STDC__) || defined(__cplusplus)
# define SM_ASSERT(cond) \
((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
"SM_ASSERT(" #cond ") failed"), 0)))
# else /* defined(__STDC__) || defined(__cplusplus) */
# define SM_ASSERT(cond) \
((void) ((cond) || (sm_abort_at(__FILE__, __LINE__, \
"SM_ASSERT(cond) failed"), 0)))
# endif /* defined(__STDC__) || defined(__cplusplus) */
# else /* SM_CHECK_ASSERT */
# define SM_ASSERT(cond) ((void) 0)
# endif /* SM_CHECK_ASSERT */
extern SM_DEBUG_T SmExpensiveRequire;
extern SM_DEBUG_T SmExpensiveEnsure;
extern SM_DEBUG_T SmExpensiveAssert;
#endif /* ! SM_ASSERT_H */