xref: /6.6.0/platform/include/platform/cbassert.h (revision d3e7c4b4)
1/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2013 Couchbase, Inc.
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17#pragma once
18
19#include <platform/dynamic.h>
20#include <platform/visibility.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25    PLATFORM_PUBLIC_API
26    void cb_assert_die(const char *expression, const char *file, int line)
27        CB_ATTR_NORETURN;
28#ifdef __cplusplus
29}
30#endif
31
32#define cb_assert(e)  \
33    ((void)((e) ? (void)0 : cb_assert_die(#e, __FILE__, __LINE__)))
34
35/**
36 * If running on Windows with a Debug build, direct error and assertion
37 * messages from the CRT to stderr, in addition to the default GUI dialog
38 * box.
39 * Also includes a backtrace of the error.
40 * Ensures that errors from Debug-mode tests etc are visible even if running
41 * in a non-graphical mode (e.g. Jenkins CV job).
42 * No-op on non-Windows, non-Debug build.
43 */
44#ifdef __cplusplus
45extern "C" {
46#endif
47    PLATFORM_PUBLIC_API
48    void setupWindowsDebugCRTAssertHandling(void);
49#ifdef __cplusplus
50}
51#endif
52