r10547: fix warning
[clsql.git] / sql / cmucl-compat.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          cmucl-compat.lisp
6 ;;;; Purpose:       Compatiblity library for CMUCL functions
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Feb 2002
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002-2004 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; CLSQL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (in-package #:cl-user)
20
21 (defpackage #:cmucl-compat
22   (:use #:common-lisp)
23   (:export
24    #:shrink-vector
25    #:make-sequence-of-type
26    #:result-type-or-lose
27    #:required-argument
28    ))
29 (in-package #:cmucl-compat)
30
31 #+(or cmu scl)
32 (defmacro required-argument ()
33   `(ext:required-argument))
34
35 #-(or cmu scl)
36 (defun required-argument ()
37   (error "~&A required keyword argument was not supplied"))
38
39 #+(or cmu scl)
40 (defmacro shrink-vector (vec len)
41   `(lisp::shrink-vector ,vec ,len))
42
43 #+sbcl
44 (defmacro shrink-vector (vec len)
45   `(sb-kernel::shrink-vector ,vec ,len))
46
47 #-(or cmu sbcl scl)
48 (defmacro shrink-vector (vec len)
49   "Shrinks a vector. Optimized if vector has a fill pointer.
50 Needs to be a macro to overwrite value of VEC."
51   (let ((new-vec (gensym)))
52     `(cond
53       ((adjustable-array-p ,vec)
54        (adjust-array ,vec ,len))
55       ((typep ,vec 'simple-array)
56        (let ((,new-vec (make-array ,len :element-type
57                                    (array-element-type ,vec))))
58          (check-type ,len fixnum)
59          (locally (declare (optimize (speed 3) (safety 0) (space 0)) )
60            (dotimes (i ,len)
61              (declare (fixnum i))
62              (setf (aref ,new-vec i) (aref ,vec i))))
63          (setq ,vec ,new-vec)))
64       ((typep ,vec 'vector)
65         (setf (fill-pointer ,vec) ,len)
66         ,vec)
67       (t
68        (error "Unable to shrink vector ~S which is type-of ~S" ,vec (type-of ,vec))) 
69        )))
70
71
72 #-(or cmu scl)
73 (defun make-sequence-of-type (type length)
74   "Returns a sequence of the given TYPE and LENGTH."
75   (make-sequence type length))
76
77 #+(or cmu scl)
78 (if (fboundp 'lisp::make-sequence-of-type)
79     (defun make-sequence-of-type (type len)
80       (lisp::make-sequence-of-type type len))
81   (defun make-sequence-of-type (type len)
82     (common-lisp::make-sequence-of-type type len)))
83
84 #-(or cmu scl)
85 (defun result-type-or-lose (type nil-ok)
86   (unless (or type nil-ok)
87     (error "NIL output type invalid for this sequence function"))
88   (case type
89     ((list cons)
90      'list)
91     ((string simple-string base-string simple-base-string)
92      'string)
93     (simple-vector
94      'simple-vector)
95     (vector
96      'vector)
97     (t
98      (error "~S is a bad type specifier for sequence functions." type))
99     ))
100
101 #+(or cmu scl)
102 (defun result-type-or-lose (type nil-ok)
103   (lisp::result-type-or-lose type nil-ok))