From dec31bb8725dab3061a99341920b0e391734f2a3 Mon Sep 17 00:00:00 2001
From: Paul Sokolovsky <pfalcon@users.sourceforge.net>
Date: Tue, 22 Apr 2014 00:01:13 +0300
Subject: [PATCH] objexcept: Add mp_obj_new_exception_arg1() convenience
 function.

---
 py/obj.h       | 1 +
 py/objexcept.c | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/py/obj.h b/py/obj.h
index d62d376ab..6bb264c1c 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -351,6 +351,7 @@ mp_obj_t mp_obj_new_float(mp_float_t val);
 mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag);
 #endif
 mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type);
+mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg);
 mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, uint n_args, const mp_obj_t *args);
 mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg);
 mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char *fmt, ...); // counts args by number of % symbols in fmt, excluding %%; can only handle void* sizes (ie no float/double!)
diff --git a/py/objexcept.c b/py/objexcept.c
index 781a00405..5b6c96b27 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -191,6 +191,11 @@ mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type) {
     return mp_obj_new_exception_args(exc_type, 0, NULL);
 }
 
+// "Optimized" version for common(?) case of having 1 exception arg
+mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg) {
+    return mp_obj_new_exception_args(exc_type, 1, &arg);
+}
+
 mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, uint n_args, const mp_obj_t *args) {
     assert(exc_type->make_new == mp_obj_exception_make_new);
     return exc_type->make_new((mp_obj_t)exc_type, n_args, 0, args);
-- 
GitLab