1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

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.
This commit is contained in:
Andy Wingo 2011-01-27 10:49:51 +01:00
parent 4914fe1963
commit dce0252bf2
3 changed files with 34 additions and 5 deletions

1
THANKS
View file

@ -63,6 +63,7 @@ For fixes or providing information which led to a fix:
Judy Hawkins Judy Hawkins
Jon Herron Jon Herron
Sam Hocevar Sam Hocevar
Kevin Holmnes
Patrick Horgan Patrick Horgan
Ales Hvezda Ales Hvezda
Stefan Israelsson Tampe Stefan Israelsson Tampe

View file

@ -153,6 +153,12 @@ VM_NAME (SCM vm, SCM program, SCM *argv, int nargs)
scm_list_1 (finish_args), SCM_BOOL_F); scm_list_1 (finish_args), SCM_BOOL_F);
goto vm_error; goto vm_error;
vm_error_not_a_variable:
SYNC_ALL ();
scm_error (scm_arg_type_key, func_name, "Not a variable: ~S",
scm_list_1 (finish_args), scm_list_1 (finish_args));
goto vm_error;
vm_error_apply_to_non_list: vm_error_apply_to_non_list:
SYNC_ALL (); SYNC_ALL ();
scm_error (scm_arg_type_key, "apply", "Apply to non-list: ~S", scm_error (scm_arg_type_key, "apply", "Apply to non-list: ~S",

View file

@ -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 * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License * 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; 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; 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) VM_DEFINE_INSTRUCTION (26, variable_bound, "variable-bound?", 0, 1, 1)
{ {
if (VARIABLE_BOUNDP (*sp)) SCM x = *sp;
*sp = SCM_BOOL_T;
if (SCM_UNLIKELY (!SCM_VARIABLEP (x)))
{
func_name = "variable-bound?";
finish_args = x;
goto vm_error_not_a_variable;
}
else else
*sp = SCM_BOOL_F; *sp = scm_from_bool (VARIABLE_BOUNDP (x));
NEXT; 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) 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]); VARIABLE_SET (sp[0], sp[-1]);
DROPN (2); DROPN (2);
NEXT; NEXT;