From 7874bbbb9f09cc14ea3e179fd0fa10da5f90cfc7 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Wed, 16 May 2018 10:05:24 +0200 Subject: records: Insert record type ABI checks in constructors. * guix/records.scm (print-record-abi-mismatch-error): New procedure. : Add 'set-exception-printer!' call. (current-abi-identifier, abi-check): New procedures. (make-syntactic-constructor): Add #:abi-cookie parameter. Insert calls to 'abi-check'. (define-record-type*)[compute-abi-cookie]: New procedure. Use it and emit a definition of the 'current-abi-identifier' for TYPE. * tests/records.scm ("ABI checks"): New test. --- tests/records.scm | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'tests/records.scm') diff --git a/tests/records.scm b/tests/records.scm index d6d27bb96a..80e08a9a5f 100644 --- a/tests/records.scm +++ b/tests/records.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès +;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2018 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -288,6 +288,34 @@ (and (string-match "extra.*initializer.*baz" message) (eq? proc 'foo))))) +(test-assert "ABI checks" + (let ((module (test-module))) + (eval '(begin + (define-record-type* foo make-foo + foo? + (bar foo-bar (default 42))) + + (define (make-me-a-record) (foo))) + module) + (unless (eval '(foo? (make-me-a-record)) module) + (error "what?" (eval '(make-me-a-record) module))) + + ;; Redefine with an additional field. + (eval '(define-record-type* foo make-foo + foo? + (baz foo-baz) + (bar foo-bar (default 42))) + module) + + ;; Now 'make-me-a-record' is out of sync because it does an + ;; 'allocate-struct' that corresponds to the previous definition of . + (catch 'record-abi-mismatch-error + (lambda () + (eval '(foo? (make-me-a-record)) module) + #f) + (lambda (key rtd . _) + (eq? rtd (eval ' module)))))) + (test-equal "recutils->alist" '((("Name" . "foo") ("Version" . "0.1") -- cgit v1.2.3