forked from adafruit/circuitpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.c
More file actions
53 lines (47 loc) · 1.65 KB
/
__init__.c
File metadata and controls
53 lines (47 loc) · 1.65 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
// This file is part of the CircuitPython project: https://circuitpython.org
//
// SPDX-FileCopyrightText: Copyright (c) 2013, 2014 Damien P. George
// SPDX-FileCopyrightText: Copyright (c) 2015 Josef Gajdusek
// SPDX-FileCopyrightText: Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
//
// SPDX-License-Identifier: MIT
#include <string.h>
#include <stdarg.h>
#include "py/mpprint.h"
#include "py/mpstate.h"
#include "py/runtime.h"
#include "shared-bindings/warnings/__init__.h"
#include "shared-module/warnings/__init__.h"
void common_hal_warnings_warn(const char *message, const mp_obj_type_t *category) {
warnings_action_t action = MP_STATE_THREAD(warnings_action);
if (action == WARNINGS_IGNORE) {
return;
}
if (action == WARNINGS_ERROR) {
mp_raise_msg_str(category, message);
// Doesn't get here
return;
}
mp_printf(MICROPY_ERROR_PRINTER, "%q: %s\n", category->name, message);
}
void warnings_warn(const mp_obj_type_t *category, mp_rom_error_text_t message, ...) {
warnings_action_t action = MP_STATE_THREAD(warnings_action);
if (action == WARNINGS_IGNORE) {
return;
}
va_list argptr;
va_start(argptr, message);
if (action == WARNINGS_ERROR) {
mp_raise_msg_vlist(category, message, argptr);
va_end(argptr);
// Doesn't get here
return;
}
mp_printf(MICROPY_ERROR_PRINTER, "%q: ", category->name);
mp_vcprintf(MICROPY_ERROR_PRINTER, message, argptr);
mp_print_str(MICROPY_ERROR_PRINTER, "\n");
va_end(argptr);
}
void common_hal_warnings_simplefilter(warnings_action_t action) {
MP_STATE_THREAD(warnings_action) = action;
}