Mercurial > hg > xemacs-beta
comparison tests/automated/lisp-tests.el @ 5241:d579d76f3dcc
Be more careful about side-effects from Lisp code, #'reduce
src/ChangeLog addition:
2010-07-24 Aidan Kehoe <kehoea@parhasard.net>
* lisp.h (PARSE_KEYWORDS):
Always accept a nil :allow-other-keys keyword argument, as
described in the ALLOW-OTHER-KEYS-NIL Common Lisp issue writeup,
and as necessary for Paul Dietz' tests for #'reduce.
* fns.c (mapping_interaction_error): New.
(Freduce): Call mapping_interaction_error when KEY or FUNCTION
have modified a string SEQUENCE such that the byte length of the
string has changed, or such that the current cursor pointer
doesn't point to the beginning of a character.
Cf. the MAPPING-DESTRUCTIVE-INTERACTION Common Lisp issue
writeup.
When traversing a list, GCPRO the part of it we still have to
traverse, to avoid any crashes if FUNCTION or KEY amputate it
behind us and force a garbage collection.
tests/ChangeLog addition:
2010-07-24 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el:
Test a couple of things #'reduce was just made more careful
about.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sat, 24 Jul 2010 15:56:57 +0100 |
parents | 71ee43b8a74d |
children | 808131ba4a57 |
comparison
equal
deleted
inserted
replaced
5240:fca0cf0971de | 5241:d579d76f3dcc |
---|---|
2339 (Assert (eq | 2339 (Assert (eq |
2340 (gethash (* 2 most-positive-fixnum) hashing) | 2340 (gethash (* 2 most-positive-fixnum) hashing) |
2341 (gethash hashed-bignum hashing)) | 2341 (gethash hashed-bignum hashing)) |
2342 "checking hashing works correctly with #'eql tests and bignums")))) | 2342 "checking hashing works correctly with #'eql tests and bignums")))) |
2343 | 2343 |
2344 ;; | |
2345 (when (decode-char 'ucs #x0192) | |
2346 (Check-Error | |
2347 invalid-state | |
2348 (let ((str "aaaaaaaaaaaaa") | |
2349 (called 0) | |
2350 modified) | |
2351 (reduce #'+ str | |
2352 :key #'(lambda (object) | |
2353 (prog1 | |
2354 object | |
2355 (incf called) | |
2356 (or modified | |
2357 (and (> called 5) | |
2358 (setq modified | |
2359 (fill str (read #r"?\u0192"))))))))))) | |
2360 | |
2361 (Assert | |
2362 (eql 55 | |
2363 (let ((sequence '(1 2 3 4 5 6 7 8 9 10)) | |
2364 (called 0) | |
2365 modified) | |
2366 (reduce #'+ | |
2367 sequence | |
2368 :key | |
2369 #'(lambda (object) (prog1 | |
2370 object | |
2371 (incf called) | |
2372 (and (eql called 5) | |
2373 (setcdr (nthcdr 3 sequence) nil)) | |
2374 (garbage-collect)))))) | |
2375 "checking we can amputate lists without crashing #'reduce") | |
2376 | |
2344 ;;; end of lisp-tests.el | 2377 ;;; end of lisp-tests.el |