1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

(rnrs hashtables): Mutation of immutable hashtable ignored

Pinging this thread with a (very slightly) updated patch. :-)

[2. text/x-diff; 0001-Hashtable-set-errors-on-immutable-hashtable.patch]

From 7f35d515d711e255bba5a89a013d9d92034edf41 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Taylan=20Ulrich=20Bay=C4=B1rl=C4=B1/Kammer?=
 <taylanbayirli@gmail.com>
Date: Tue, 21 Jun 2016 00:25:19 +0200
Subject: [PATCH] Hashtable-set! errors on immutable hashtable.

* module/rnrs/hashtables.scm (hashtable-set!): Raise an assertion
  violation error when the hashtable is immutable.
* test-suite/tests/r6rs-hashtables.test: Fix accordingly.
This commit is contained in:
Taylan Ulrich Bayırlı/Kammer 2016-06-21 00:33:50 +02:00 committed by Andy Wingo
parent beea6302e0
commit c1abe68dbc
2 changed files with 7 additions and 4 deletions

View file

@ -122,8 +122,9 @@
(define (hashtable-set! hashtable key obj)
(if (r6rs:hashtable-mutable? hashtable)
(hash-table-set! (r6rs:hashtable-wrapped-table hashtable) key obj))
*unspecified*)
(hash-table-set! (r6rs:hashtable-wrapped-table hashtable) key obj)
(assertion-violation
'hashtable-set! "Hashtable is immutable." hashtable)))
(define (hashtable-delete! hashtable key)
(if (r6rs:hashtable-mutable? hashtable)

View file

@ -20,6 +20,7 @@
(define-module (test-suite test-rnrs-hashtable)
:use-module (ice-9 receive)
:use-module ((rnrs hashtables) :version (6))
:use-module ((rnrs exceptions) :version (6))
:use-module (srfi srfi-1)
:use-module (test-suite lib))
@ -130,8 +131,9 @@
(pass-if "hashtable-copy with mutability #f produces immutable copy"
(let ((copied-table (hashtable-copy (make-eq-hashtable) #f)))
(hashtable-set! copied-table 'foo 1)
(not (hashtable-ref copied-table 'foo #f)))))
(guard (exc (else #t))
(hashtable-set! copied-table 'foo 1)
#f))))
(with-test-prefix "hashtable-clear!"
(pass-if "hashtable-clear! removes all values from hashtable"