From 4d0afb9bedcc103e882dce47d0cdc57a0b79e433 Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Sun, 10 Mar 2002 17:43:56 +0000 Subject: [PATCH] r1538: *** empty log message *** --- doc/Makefile | 6 ++- doc/ref.sgml | 127 ++++++++++++++++++++++++++++++++++++--------- examples/getenv.cl | 5 +- src/immediates.cl | 14 +++-- tests/getenv.cl | 5 +- 5 files changed, 122 insertions(+), 35 deletions(-) diff --git a/doc/Makefile b/doc/Makefile index 63e83e0..baccb85 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -5,7 +5,7 @@ # Programer: Kevin M. Rosenberg # Date Started: Mar 2002 # -# CVS Id: $Id: Makefile,v 1.3 2002/03/10 12:54:01 kevin Exp $ +# CVS Id: $Id: Makefile,v 1.4 2002/03/10 17:43:56 kevin Exp $ # # Copyright (c) 2002 by Kevin M. Rosenberg # @@ -38,6 +38,10 @@ DSSSL_HTML=/usr/share/sgml/docbook/dsssl-stylesheets-1.76/html/docbook.dsl DSSSL_PRINT=/usr/share/sgml/docbook/dsssl-stylesheets-1.76/print/docbook.dsl +# Custom version +#DSSSL_HTML=/home/kevin/lisp/docbook/html/lisp.dsl +#DSSSL_PRINT=/home/kevin/lisp/docbook/print/lisp.dsl + # Nothing to configure beyond this point DOCFILE_BASE_DEFAULT=uffi diff --git a/doc/ref.sgml b/doc/ref.sgml index 6b79478..103363a 100644 --- a/doc/ref.sgml +++ b/doc/ref.sgml @@ -70,9 +70,6 @@ the keyword package. - - :byte - Unsigned 8-bit - :char - Signed 8-bits @@ -98,26 +95,19 @@ :unsigned-long - Unsigned 32-bits - :single-float - 32-bit floating point + :float - 32-bit floating point - :double-float - 64-bit floating point + :double - 64-bit floating point - - - :cstring - - - A null-terminated string used for passing and returning with a function. - + :cstring - +A null-terminated string used for passing and returning with a function. + - - - :void - - - An absence of a value. Used in generic pointers and in - return types from functions. + :void - +The absence of a value. Used in generic pointers and in return types from functions. * - Used to declare a pointer to an object @@ -210,6 +200,12 @@ Objects + + Overview + + Objects are entities that can allocated and freed. + + allocate-foreign-object @@ -277,8 +273,8 @@ always need to have memory for them. convert-to-cstring Converts a Lisp string to a - cstring. These - cstring's should be freed with + cstring. The + cstring should be freed with free-cstring. @@ -294,6 +290,22 @@ always need to have memory for them. Binds a lexical variable to a newly allocated cstring. Automatically frees cstring. + + Examples + + +(def-function ("getenv" c-getenv) + ((name :cstring)) + :returning :cstring) + +(defun getenv (key) + "Returns an environment variable, or NIL if it does not exist" + (check-type key string) + (with-cstring (key-cstring key) + (convert-from-cstring (c-getenv key-cstring)))) + + + covert-from-foreign-string @@ -320,12 +332,79 @@ always need to have memory for them. Functions - - def-function - - This macro generates a &c; function definition. + + + def-function + Declares a function. + + Macro + + + Syntax + + def-function name args &key module returning + + + + Arguments and Values + + + name + + A string or list specificying the function name. If it is a string, that names the foreign function. A Lisp name is created by translating #\_ to #\- and by converting to upper-case in case-insensitive Lisp implementations. If it is a list, the first item is a string specifying the foreign function name and the second it is a symbol stating the Lisp name. + + + + + args + + A list of argument declarations. Use &nil; to specify no arguments. + + + + + module + + A string specifying which module (or library) that the foreign function resides. (Required by Lispworks) + + + + returning + + A declaration specifying the result type of the +foreign function. + + + + + + + Description + Declares a foreign function. - + + + Examples + +(def-function "gethostname" + ((name :cstring) + (len :int)) + :returning :int) + + + + Side Effects + None. + + + Affected by + None. + + + Exceptional Situations + None. + + diff --git a/examples/getenv.cl b/examples/getenv.cl index c6da2a0..043e7fc 100644 --- a/examples/getenv.cl +++ b/examples/getenv.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Copyright (c) 2002 Kevin M. Rosenberg ;;;; -;;;; $Id: getenv.cl,v 1.5 2002/03/10 11:13:07 kevin Exp $ +;;;; $Id: getenv.cl,v 1.6 2002/03/10 17:42:35 kevin Exp $ ;;;; ;;;; This file is part of UFFI. ;;;; @@ -38,8 +38,7 @@ "Returns an environment variable, or NIL if it does not exist" (check-type key string) (uffi:with-cstring (key-native key) - (let ((value-cstring (c-getenv key-native))) - (uffi:convert-from-cstring value-cstring)))) + (uffi:convert-from-cstring (c-getenv key-native)))) #+test-uffi (progn diff --git a/src/immediates.cl b/src/immediates.cl index ae1013c..4dcfec6 100644 --- a/src/immediates.cl +++ b/src/immediates.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Copyright (c) 2002 Kevin M. Rosenberg ;;;; -;;;; $Id: immediates.cl,v 1.3 2002/03/10 11:13:07 kevin Exp $ +;;;; $Id: immediates.cl,v 1.4 2002/03/10 17:42:35 kevin Exp $ ;;;; ;;;; This file is part of the UFFI. ;;;; @@ -74,6 +74,7 @@ supports this." (defconstant +cmu-def-type-list+ '((:char . (alien:signed 8)) (:unsigned-char . (alien:unsigned 8)) + (:byte . (alien:unsigned 8)) (:short . (alien:signed 16)) (:unsigned-short . (alien:unsigned 16)) (:int . (alien:signed 32)) @@ -90,7 +91,9 @@ supports this." (:short . c-call:short) (:pointer-void . (* t)) (:cstring . c-call:cstring) - (:char . c-call:char) (:unsigned-char . (alien:unsigned 8)) + (:char . c-call:char) + (:unsigned-char . (alien:unsigned 8)) + (:byte . (alien:unsigned 8)) (:int . alien:integer) (:unsigned-int . c-call:unsigned-int) (:long . c-call:long) (:unsigned-long . c-call:unsigned-long) (:float . c-call:float) (:double . c-call:double) @@ -101,7 +104,9 @@ supports this." (:short . :short) (:pointer-void . (* :void)) (:cstring . (* :char)) - (:char . :char) (:unsigned-char . :unsigned-char) + (:char . :char) + (:unsigned-char . :unsigned-char) + (:byte . :byte) (:int . :int) (:unsigned-int . :unsigned-int) (:long . :long) (:unsigned-long . :unsigned-long) (:float . :float) (:double . :double) @@ -112,7 +117,8 @@ supports this." (:short . :short) (:pointer-void . (:pointer :void)) (:cstring . (:pointer :char)) - (:char . :char) (:unsigned-char . (:unsigned :char)) + (:char . :char) + (:unsigned-char . (:unsigned :char)) (:int . :int) (:unsigned-int . (:unsigned :int)) (:long . :long) (:unsigned-long . (:unsigned :long)) (:float . :float) (:double . :double) diff --git a/tests/getenv.cl b/tests/getenv.cl index c6da2a0..043e7fc 100644 --- a/tests/getenv.cl +++ b/tests/getenv.cl @@ -9,7 +9,7 @@ ;;;; ;;;; Copyright (c) 2002 Kevin M. Rosenberg ;;;; -;;;; $Id: getenv.cl,v 1.5 2002/03/10 11:13:07 kevin Exp $ +;;;; $Id: getenv.cl,v 1.6 2002/03/10 17:42:35 kevin Exp $ ;;;; ;;;; This file is part of UFFI. ;;;; @@ -38,8 +38,7 @@ "Returns an environment variable, or NIL if it does not exist" (check-type key string) (uffi:with-cstring (key-native key) - (let ((value-cstring (c-getenv key-native))) - (uffi:convert-from-cstring value-cstring)))) + (uffi:convert-from-cstring (c-getenv key-native)))) #+test-uffi (progn -- 2.34.1