summaryrefslogtreecommitdiff
path: root/lib/utils/context_manager_helpers.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2017-02-19 16:11:33 +0100
committerScott Shawcroft <scott.shawcroft@gmail.com>2017-02-19 16:11:33 +0100
commite9659e61f89fb9ef84011c42e89849f7fd9bc9c1 (patch)
tree595734f7464dfbab8bf6b31c22b306380c3f8829 /lib/utils/context_manager_helpers.c
parentc4ee6d5716d89ab57ad4b70712f2cf9e49b37e14 (diff)
Switch enum-like attributes to all caps and add print support for them. Make room for this functionality by adding a shared __enter__ function object. #76
Diffstat (limited to 'lib/utils/context_manager_helpers.c')
-rw-r--r--lib/utils/context_manager_helpers.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/utils/context_manager_helpers.c b/lib/utils/context_manager_helpers.c
new file mode 100644
index 000000000..901c27030
--- /dev/null
+++ b/lib/utils/context_manager_helpers.c
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "lib/utils/context_manager_helpers.h"
+
+#include "py/obj.h"
+
+STATIC mp_obj_t default___enter__(mp_obj_t self_in) {
+ return self_in;
+}
+MP_DEFINE_CONST_FUN_OBJ_1(default___enter___obj, default___enter__);