-
Notifications
You must be signed in to change notification settings - Fork 550
Expand file tree
/
Copy patherror.cpp
More file actions
52 lines (45 loc) · 1.56 KB
/
error.cpp
File metadata and controls
52 lines (45 loc) · 1.56 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
/*******************************************************
* Copyright (c) 2015, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <af/array.h>
#include <af/device.h>
#include <af/exception.h>
#include <af/util.h>
#include <algorithm>
#include "symbol_manager.hpp"
void af_get_last_error(char **str, dim_t *len) {
// Set error message from unified backend
std::string &global_error_string = get_global_error_string();
dim_t slen =
std::min(MAX_ERR_SIZE, static_cast<int>(global_error_string.size()));
// If this is true, the error is coming from the unified backend.
if (slen != 0) {
if (len && slen == 0) {
*len = 0;
*str = NULL;
return;
}
void *in = nullptr;
af_alloc_host(&in, sizeof(char) * (slen + 1));
memcpy(str, &in, sizeof(void *));
global_error_string.copy(*str, slen);
(*str)[slen] = '\0';
global_error_string = std::string("");
if (len) { *len = slen; }
} else {
// If false, the error is coming from active backend.
typedef void (*af_func)(char **, dim_t *);
void *vfn = LOAD_SYMBOL();
af_func func = nullptr;
memcpy(&func, &vfn, sizeof(void *));
func(str, len);
}
}
af_err af_set_enable_stacktrace(int is_enabled) {
CALL(af_set_enable_stacktrace, is_enabled);
}