LAMMP 4.2.0
Lamina High-Precision Arithmetic Library
载入中...
搜索中...
未找到
abort.c
浏览该文件的文档.
1/**
2 * Copyright (C) 2026 HJimmyK(Jericho Knox)
3 *
4 * This file is part of LAMMP.
5 *
6 * LAMMP is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License (LGPL) as published
8 * by the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed WITHOUT ANY WARRANTY.
12 *
13 * See <https://www.gnu.org/licenses/>.
14 */
15
16#include "../../../include/lammp/lmmp.h"
17#include <stdio.h>
18#include <stdlib.h>
19
20#if defined(LAMMP_WINDOWS)
21#include <windows.h>
22
25
33
38
42
43#else
44#ifdef __STDC_NO_THREADS__
45#error "Threads support is required for setting abort function"
46#else
47#include <threads.h>
48#endif
49
52
53static void init_abort_lock(void) {
55}
56
57static void abort_func_lock(void) {
60}
61
62static void abort_func_unlock(void) {
64}
65
66#endif
67
69
78
79static const char* type_to_str(lmmp_error_t type) {
80 switch (type) {
82 return "ASSERT_FAILURE";
84 return "DEBUG_ASSERT_FAILURE";
86 return "PARAM_ASSERT_FAILURE";
88 return "MEMORY_ALLOC_FAILURE";
90 return "MEMORY_FREE_FAILURE";
92 return "OUT_OF_BOUNDS";
94 return "MEMORY_LEAK";
96 return "UNEXPECTED_ERROR";
97 default:
98 return "UNKNOWN_TYPE";
99 }
100}
101
102void lmmp_abort(lmmp_error_t type, const char* msg, const char* func, int line) {
106
107 if (fn != NULL) {
108 fn(type, msg, func, line);
109 } else {
110 fprintf(stderr, "LAMMP abort at [%s]:%d\n", func, line);
111 fprintf(stderr, "Abort type: %s, abort msg: \n%s\n", type_to_str(type), msg);
112 fflush(stderr);
113 }
114 abort();
115}
static const char * type_to_str(lmmp_error_t type)
Definition abort.c:79
static BOOL CALLBACK init_abort_cs(PINIT_ONCE once, PVOID param, PVOID *ctx)
Definition abort.c:26
lmmp_abort_fn lmmp_set_abort_fn(lmmp_abort_fn func)
设置 LAMMP 全局退出函数(所有线程均生效)
Definition abort.c:70
void lmmp_abort(lmmp_error_t type, const char *msg, const char *func, int line)
LAMMP 全局退出函数,内部错误或断言失败时调用,若设置了全局退出函数,则会调用该函数,否则会调用默认的退出函数。
Definition abort.c:102
static void abort_func_unlock(void)
Definition abort.c:39
static CRITICAL_SECTION abort_func_cs
Copyright (C) 2026 HJimmyK(Jericho Knox)
Definition abort.c:23
static void abort_func_lock(void)
Definition abort.c:34
static INIT_ONCE abort_cs_once
Definition abort.c:24
static lmmp_abort_fn lmmp_abort_func
Definition abort.c:68
void(* lmmp_abort_fn)(lmmp_error_t type, const char *msg, const char *func, int line)
LAMMP 全局退出函数指针类型
Definition lmmp.h:229
lmmp_error_t
Definition lmmp.h:211
@ LAMMP_ERROR_MEMORY_ALLOC_FAILURE
Definition lmmp.h:215
@ LAMMP_ERROR_DEBUG_ASSERT_FAILURE
Definition lmmp.h:213
@ LAMMP_ERROR_UNEXPECTED_ERROR
Definition lmmp.h:219
@ LAMMP_ERROR_MEMORY_LEAK
Definition lmmp.h:218
@ LAMMP_ERROR_ASSERT_FAILURE
Definition lmmp.h:212
@ LAMMP_ERROR_PARAM_ASSERT_FAILURE
Definition lmmp.h:214
@ LAMMP_ERROR_MEMORY_FREE_FAILURE
Definition lmmp.h:216
@ LAMMP_ERROR_OUT_OF_BOUNDS
Definition lmmp.h:217
#define n