diff options
author | Andy Wingo <wingo@pobox.com> | 2011-01-27 10:49:51 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-01-27 10:49:51 +0100 |
commit | dce0252bf2b6b25ce825038472b2c3fa811a0164 (patch) | |
tree | 2920f0f769d24cf7fcf293bdeaba94e53b9726ce /libguile/vm-i-system.c | |
parent | 4914fe1963ce5bee2ecd86f3a386dd0e23d3678b (diff) | |
download | guile-dce0252bf2b6b25ce825038472b2c3fa811a0164.tar.gz |
fix error handling in variable-ref family of instructions
* libguile/vm-i-system.c (variable-ref, variable-set, variable-bound?):
Check that the argument is actually a variable. Thanks to Kevin
Holmes for the report.
* libguile/vm-engine.c (vm_engine): Error handling down here.
* THANKS: Update.
Diffstat (limited to 'libguile/vm-i-system.c')
-rw-r--r-- | libguile/vm-i-system.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/libguile/vm-i-system.c b/libguile/vm-i-system.c index 5b40c1b9d..57712cabd 100644 --- a/libguile/vm-i-system.c +++ b/libguile/vm-i-system.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2001,2008,2009,2010 Free Software Foundation, Inc. +/* Copyright (C) 2001,2008,2009,2010,2011 Free Software Foundation, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License @@ -300,7 +300,17 @@ VM_DEFINE_INSTRUCTION (25, variable_ref, "variable-ref", 0, 1, 1) { SCM x = *sp; - if (SCM_UNLIKELY (!VARIABLE_BOUNDP (x))) + /* We don't use ASSERT_VARIABLE or ASSERT_BOUND_VARIABLE here because, + unlike in top-variable-ref, it really isn't an internal assertion + that can be optimized out -- the variable could be coming directly + from the user. */ + if (SCM_UNLIKELY (!SCM_VARIABLEP (x))) + { + func_name = "variable-ref"; + finish_args = x; + goto vm_error_not_a_variable; + } + else if (SCM_UNLIKELY (!VARIABLE_BOUNDP (x))) { SCM var_name; @@ -320,10 +330,16 @@ VM_DEFINE_INSTRUCTION (25, variable_ref, "variable-ref", 0, 1, 1) VM_DEFINE_INSTRUCTION (26, variable_bound, "variable-bound?", 0, 1, 1) { - if (VARIABLE_BOUNDP (*sp)) - *sp = SCM_BOOL_T; + SCM x = *sp; + + if (SCM_UNLIKELY (!SCM_VARIABLEP (x))) + { + func_name = "variable-bound?"; + finish_args = x; + goto vm_error_not_a_variable; + } else - *sp = SCM_BOOL_F; + *sp = scm_from_bool (VARIABLE_BOUNDP (x)); NEXT; } @@ -398,6 +414,12 @@ VM_DEFINE_INSTRUCTION (30, long_local_set, "long-local-set", 2, 1, 0) VM_DEFINE_INSTRUCTION (31, variable_set, "variable-set", 0, 2, 0) { + if (SCM_UNLIKELY (!SCM_VARIABLEP (sp[0]))) + { + func_name = "variable-set!"; + finish_args = sp[0]; + goto vm_error_not_a_variable; + } VARIABLE_SET (sp[0], sp[-1]); DROPN (2); NEXT; |