summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/mpconfig.h16
-rw-r--r--py/obj.c2
-rw-r--r--py/runtime.h4
-rw-r--r--py/vm.c2
-rw-r--r--py/warning.c11
5 files changed, 29 insertions, 6 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 48427c3e5..4fd08db23 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -598,6 +598,11 @@ typedef long long mp_longint_impl_t;
#define MICROPY_WARNINGS (0)
#endif
+// Whether to support warning categories
+#ifndef MICROPY_WARNINGS_CATEGORY
+#define MICROPY_WARNINGS_CATEGORY (0)
+#endif
+
// This macro is used when printing runtime warnings and errors
#ifndef MICROPY_ERROR_PRINTER
#define MICROPY_ERROR_PRINTER (&mp_plat_print)
@@ -1508,4 +1513,15 @@ typedef double mp_float_t;
#endif
#endif
+// Warning categories are by default implemented as strings, though
+// hook is left for a port to define them as something else.
+#if MICROPY_WARNINGS_CATEGORY
+# ifndef MP_WARN_CAT
+# define MP_WARN_CAT(x) #x
+# endif
+#else
+# undef MP_WARN_CAT
+# define MP_WARN_CAT(x) (NULL)
+#endif
+
#endif // MICROPY_INCLUDED_PY_MPCONFIG_H
diff --git a/py/obj.c b/py/obj.c
index 47b7d15ae..7007d5070 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -202,7 +202,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
str_cmp_err:
#if MICROPY_PY_STR_BYTES_CMP_WARN
if (MP_OBJ_IS_TYPE(o1, &mp_type_bytes) || MP_OBJ_IS_TYPE(o2, &mp_type_bytes)) {
- mp_warning("Comparison between bytes and str");
+ mp_warning(MP_WARN_CAT(BytesWarning), "Comparison between bytes and str");
}
#endif
return false;
diff --git a/py/runtime.h b/py/runtime.h
index dd4c9a984..9811c1b5a 100644
--- a/py/runtime.h
+++ b/py/runtime.h
@@ -179,7 +179,9 @@ void mp_native_raise(mp_obj_t o);
#define mp_sys_argv (MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_sys_argv_obj)))
#if MICROPY_WARNINGS
-void mp_warning(const char *msg, ...);
+#ifndef mp_warning
+void mp_warning(const char *category, const char *msg, ...);
+#endif
#else
#define mp_warning(...)
#endif
diff --git a/py/vm.c b/py/vm.c
index f9f9a3d6a..fce59349f 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -1116,7 +1116,7 @@ unwind_return:
mp_uint_t unum = *ip;
mp_obj_t obj;
if (unum == 2) {
- mp_warning("exception chaining not supported");
+ mp_warning(NULL, "exception chaining not supported");
// ignore (pop) "from" argument
sp--;
}
diff --git a/py/warning.c b/py/warning.c
index 12d0f9c99..ebaf2d078 100644
--- a/py/warning.c
+++ b/py/warning.c
@@ -32,10 +32,15 @@
#if MICROPY_WARNINGS
-void mp_warning(const char *msg, ...) {
+void mp_warning(const char *category, const char *msg, ...) {
+ if (category == NULL) {
+ category = "Warning";
+ }
+ mp_print_str(MICROPY_ERROR_PRINTER, category);
+ mp_print_str(MICROPY_ERROR_PRINTER, ": ");
+
va_list args;
va_start(args, msg);
- mp_print_str(MICROPY_ERROR_PRINTER, "Warning: ");
mp_vprintf(MICROPY_ERROR_PRINTER, msg, args);
mp_print_str(MICROPY_ERROR_PRINTER, "\n");
va_end(args);
@@ -43,7 +48,7 @@ void mp_warning(const char *msg, ...) {
void mp_emitter_warning(pass_kind_t pass, const char *msg) {
if (pass == MP_PASS_CODE_SIZE) {
- mp_warning(msg, NULL);
+ mp_warning(NULL, msg);
}
}