klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

commit ba85f52de902fba436b9d30d5432714e0189fee8
parent 1a83162c930cf69884edf3b9003f5f16f81265ab
Author: Andres Navarro <canavarro82@gmail.com>
Date:   Thu, 10 Mar 2011 22:55:35 -0300

Bugfix: added immutability checking to set-car! and set-cdr!

Diffstat:
Msrc/kground.c | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/kground.c b/src/kground.c @@ -473,14 +473,17 @@ void cons(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) */ /* 4.7.1 set-car!, set-cdr! */ -/* TODO: check if pair is immutable */ void set_carB(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) { (void) denv; (void) xparams; bind_2tp(K, "set-car!", ptree, "pair", ttispair, pair, "any", anytype, new_car); - + + if(!kis_mutable(pair)) { + klispE_throw(K, "set-car!: immutable pair"); + return; + } kset_car(pair, new_car); kapply_cc(K, KINERT); } @@ -492,6 +495,10 @@ void set_cdrB(klisp_State *K, TValue *xparams, TValue ptree, TValue denv) bind_2tp(K, "set-cdr!", ptree, "pair", ttispair, pair, "any", anytype, new_cdr); + if(!kis_mutable(pair)) { + klispE_throw(K, "set-cdr!: immutable pair"); + return; + } kset_cdr(pair, new_cdr); kapply_cc(K, KINERT); }