-
Notifications
You must be signed in to change notification settings - Fork 358
Expand file tree
/
Copy pathdeDefs.c
More file actions
145 lines (127 loc) · 4.66 KB
/
Copy pathdeDefs.c
File metadata and controls
145 lines (127 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*-------------------------------------------------------------------------
* drawElements Base Portability Library
* -------------------------------------
*
* Copyright 2014 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*//*!
* \file
* \brief Basic portability.
*//*--------------------------------------------------------------------*/
#include "deDefs.h"
#include "deInt32.h"
/* Assert base type sizes. */
DE_STATIC_ASSERT(sizeof(uint8_t) == 1);
DE_STATIC_ASSERT(sizeof(uint16_t) == 2);
DE_STATIC_ASSERT(sizeof(uint32_t) == 4);
DE_STATIC_ASSERT(sizeof(uint64_t) == 8);
DE_STATIC_ASSERT(sizeof(int8_t) == 1);
DE_STATIC_ASSERT(sizeof(int16_t) == 2);
DE_STATIC_ASSERT(sizeof(int32_t) == 4);
DE_STATIC_ASSERT(sizeof(int64_t) == 8);
DE_STATIC_ASSERT(sizeof(uintptr_t) == sizeof(void *));
DE_STATIC_ASSERT(sizeof(intptr_t) == sizeof(void *));
DE_STATIC_ASSERT(DE_PTR_SIZE == sizeof(void *));
/* Sanity checks for DE_PTR_SIZE & DE_CPU */
#if !((DE_CPU == DE_CPU_X86_64 || DE_CPU == DE_CPU_ARM_64 || DE_CPU == DE_CPU_MIPS_64 || DE_CPU == DE_CPU_RISCV_64) && \
(DE_PTR_SIZE == 8)) && \
!((DE_CPU == DE_CPU_X86 || DE_CPU == DE_CPU_ARM || DE_CPU == DE_CPU_MIPS || DE_CPU == DE_CPU_RISCV_32) && \
(DE_PTR_SIZE == 4))
#error "DE_CPU and DE_PTR_SIZE mismatch"
#endif
#if (DE_OS == DE_OS_UNIX || DE_OS == DE_OS_WIN32) && defined(NDEBUG)
/* We need __assert_fail declaration from assert.h */
#undef NDEBUG
#endif
#include <stdio.h>
#include <assert.h>
#include <string.h>
#if (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS) || defined(__FreeBSD__)
#include <signal.h>
#include <stdlib.h>
#endif
#if (DE_OS == DE_OS_ANDROID)
#include <android/log.h>
#endif
/*
#if (DE_OS == DE_OS_WIN32)
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
#endif
*/
DE_BEGIN_EXTERN_C
#if defined(DE_ASSERT_FAILURE_CALLBACK)
static deAssertFailureCallbackFunc g_assertFailureCallback = NULL;
#endif
void deSetAssertFailureCallback(deAssertFailureCallbackFunc callback)
{
#if defined(DE_ASSERT_FAILURE_CALLBACK)
g_assertFailureCallback = callback;
#else
DE_UNREF(callback);
#endif
}
void deAssertFail(const char *reason, const char *file, int line)
{
#if defined(DE_ASSERT_FAILURE_CALLBACK)
if (g_assertFailureCallback != NULL)
{
/* Remove callback in case of the callback causes further asserts. */
deAssertFailureCallbackFunc callback = g_assertFailureCallback;
deSetAssertFailureCallback(NULL);
callback(reason, file, line);
}
#endif
#if (((DE_OS == DE_OS_WIN32) || (DE_OS == DE_OS_WINCE)) && (DE_COMPILER == DE_COMPILER_MSC))
{
wchar_t wreason[1024];
wchar_t wfile[128];
int num;
int i;
/* MessageBox(reason, "Assertion failed", MB_OK); */
num = deMin32((int)strlen(reason), DE_LENGTH_OF_ARRAY(wreason) - 1);
for (i = 0; i < num; i++)
wreason[i] = reason[i];
wreason[i] = 0;
num = deMin32((int)strlen(file), DE_LENGTH_OF_ARRAY(wfile) - 1);
for (i = 0; i < num; i++)
wfile[i] = file[i];
wfile[i] = 0;
#if (DE_OS == DE_OS_WIN32)
_wassert(wreason, wfile, line);
#else /* WINCE */
assert(wreason);
#endif
}
#elif ((DE_OS == DE_OS_WIN32) && (DE_COMPILER == DE_COMPILER_CLANG || DE_COMPILER == DE_COMPILER_GCC))
_assert(reason, file, line);
#elif (DE_OS == DE_OS_OSX) || (DE_OS == DE_OS_IOS) || defined(__FreeBSD__)
fprintf(stderr, "Assertion '%s' failed at %s:%d\n", reason, file, line);
raise(SIGTRAP);
abort();
#elif (DE_OS == DE_OS_UNIX) || (DE_OS == DE_OS_FUCHSIA) || (DE_OS == DE_OS_OHOS)
__assert_fail(reason, file, (unsigned int)line, "Unknown function");
#elif (DE_OS == DE_OS_QNX)
__assert(reason, file, (unsigned int)line, "Unknown function");
#elif (DE_OS == DE_OS_SYMBIAN)
__assert("Unknown function", file, line, reason);
#elif (DE_OS == DE_OS_ANDROID)
__android_log_print(ANDROID_LOG_ERROR, "delibs", "Assertion '%s' failed at %s:%d", reason, file, line);
__assert(file, line, reason);
#else
#error Implement assertion function on your platform.
#endif
}
DE_END_EXTERN_C