1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: clsql-uffi.cl
6 ;;;; Purpose: Common functions for interfaces using UFFI
7 ;;;; Programmers: Kevin M. Rosenberg
8 ;;;; Date Started: Mar 2002
12 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
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 ;;;; *************************************************************************
19 (in-package #:clsql-uffi)
22 (defun canonicalize-type-list (types auto-list)
23 "Ensure a field type list meets expectations"
24 (declare (optimize (speed 3) (safety 0)))
27 (length-types (length types))
28 (length-auto-list (length auto-list)))
29 ((= i length-auto-list)
31 (declaim (fixnum length-types length-auto-list i))
32 (if (>= i length-types)
33 (push t new-types) ;; types is shorted than num-fields
37 (case (nth i auto-list)
45 (case (nth i auto-list)
51 (if (eq :int32 (nth i auto-list))
55 (if (eq :int64 (nth i auto-list))
62 (uffi:def-function "atoi"
63 ((str (* :unsigned-char)))
66 (uffi:def-function "atol"
67 ((str (* :unsigned-char)))
70 (uffi:def-function "atof"
71 ((str (* :unsigned-char)))
74 (uffi:def-function "atol64"
75 ((str (* :unsigned-char))
77 :returning :unsigned-int)
79 (uffi:def-constant +2^32+ 4294967296)
80 (uffi:def-constant +2^32-1+ (1- +2^32+))
82 (defmacro make-64-bit-integer (high32 low32)
83 `(+ ,low32 (ash ,high32 32)))
85 (defmacro split-64-bit-integer (int64)
86 `(values (ash ,int64 -32) (logand ,int64 +2^32-1+)))
88 (uffi:def-type char-ptr-def (* :unsigned-char))
90 (defun convert-raw-field (char-ptr types index &optional length)
91 (declare (optimize (speed 3) (safety 0) (space 0))
92 (type char-ptr-def char-ptr))
93 (let ((type (if (listp types)
97 ((uffi:null-pointer-p char-ptr)
106 (uffi:with-foreign-object (high32-ptr :int)
107 (let ((low32 (atol64 char-ptr high32-ptr))
108 (high32 (uffi:deref-pointer high32-ptr :int)))
111 (make-64-bit-integer high32 low32)))))
114 (uffi:convert-from-foreign-string char-ptr :locale :none
115 :null-terminated-p nil
117 (uffi:convert-from-foreign-string char-ptr :locale :none))))))))