commit a9b8f0645ef5b1128538335430036d10dcf29951
parent 0b2abc678a2b617face37136ad432194706f01e5
Author: Andres Navarro <canavarro82@gmail.com>
Date: Tue, 13 Dec 2011 23:58:34 -0300
Modified [un]register-requirement! to throw errors if (non|already) registered. This makes it consistent with the module counterparts.
Diffstat:
1 file changed, 21 insertions(+), 6 deletions(-)
diff --git a/src/kgports.c b/src/kgports.c
@@ -991,9 +991,17 @@ void register_requirementB(klisp_State *K)
TValue saved_name = kstring_immutablep(name)? name :
kstring_new_bs_imm(K, kstring_buf(name), kstring_size(name));
- /* don't throw error if already registered */
- *(klispH_setstr(K, tv2table(K->require_table),
- tv2str(saved_name))) = KTRUE;
+ TValue *node = klispH_setstr(K, tv2table(K->require_table),
+ tv2str(saved_name));
+
+ /* throw error if already registered */
+ if (!ttisfree(*node)) {
+ klispE_throw_simple_with_irritants(K, "Name already registered",
+ 1, name);
+ return;
+ }
+
+ *node = KTRUE;
kapply_cc(K, KINERT);
}
@@ -1007,9 +1015,16 @@ void unregister_requirementB(klisp_State *K)
TValue saved_name = kstring_immutablep(name)? name :
kstring_new_bs_imm(K, kstring_buf(name), kstring_size(name));
- /* don't throw error if not registered */
- *(klispH_setstr(K, tv2table(K->require_table),
- tv2str(saved_name))) = KFREE;
+ TValue *node = klispH_setstr(K, tv2table(K->require_table),
+ tv2str(saved_name));
+
+ /* throw error if not registered */
+ if (ttisfree(*node)) {
+ klispE_throw_simple_with_irritants(K, "Unregistered name", 1, name);
+ return;
+ }
+
+ *node = KFREE;
kapply_cc(K, KINERT);
}