From b31b6b030494e289391bed12b3fbe62acc38a425 Mon Sep 17 00:00:00 2001 From: espen Date: Sat, 2 Jun 2007 07:26:23 +0000 Subject: [PATCH] Added platform more independent memory access functions --- gffi/defpackage.lisp | 5 +++-- gffi/memory.lisp | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/gffi/defpackage.lisp b/gffi/defpackage.lisp index b0c7b45..578e8ca 100644 --- a/gffi/defpackage.lisp +++ b/gffi/defpackage.lisp @@ -20,7 +20,7 @@ ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -;; $Id: defpackage.lisp,v 1.10 2007-02-19 14:42:54 espen Exp $ +;; $Id: defpackage.lisp,v 1.11 2007-06-02 07:26:24 espen Exp $ (defpackage "GFFI" (:use "COMMON-LISP" "AUTOEXPORT" "PKG-CONFIG" "CLG-UTILS") @@ -46,7 +46,8 @@ #+sbcl(:import-from "SB-ALIEN" "VOID" "C-STRING") ;; Symbols from memory.lisp (:export "MAKE-POINTER" "POINTER-ADDRESS" "NULL-POINTER-P" "POINTER=" - "POINTER+" "REF-POINTER" "REF-BYTE" "ALLOCATE-MEMORY" + "POINTER+" "REF-POINTER" "REF-BYTE" "REF-INT-32" "REF-UINT-32" + "REF-DOUBLE-FLOAT" "REF-SINGLE-FLOAT" "ALLOCATE-MEMORY" "DEALLOCATE-MEMORY" "COPY-MEMORY" "CLEAR-MEMORY" "MEMORY-CLEAR-P" "WITH-MEMORY" "WITH-POINTER" "*MEMORY-ALLOCATOR*" "*MEMORY-DEALLOCATOR*") diff --git a/gffi/memory.lisp b/gffi/memory.lisp index 2bcc394..3712048 100644 --- a/gffi/memory.lisp +++ b/gffi/memory.lisp @@ -20,7 +20,7 @@ ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -;; $Id: memory.lisp,v 1.3 2006-12-21 16:38:19 espen Exp $ +;; $Id: memory.lisp,v 1.4 2007-06-02 07:26:23 espen Exp $ (in-package "GFFI") @@ -71,6 +71,48 @@ #+clisp(ffi:memory-as location 'ffi:uchar offset) byte)) +(defun ref-int-32 (location &optional (offset 0)) + #+(or cmu sbcl)(signed-sap-ref-32 location offset) + #+clisp(ffi:memory-as location 'ffi:sint32 offset)) + +(defun (setf ref-int-32) (value location &optional (offset 0)) + (setf + #+(or cmu sbcl)(signed-sap-ref-32 location offset) + #+clisp(ffi:memory-as location 'ffi:sint32 offset) + value)) + +(defun ref-uint-32 (location &optional (offset 0)) + #+(or cmu sbcl)(sap-ref-32 location offset) + #+clisp(ffi:memory-as location 'ffi:uint32 offset)) + +(defun (setf ref-uint-32) (value location &optional (offset 0)) + (setf + #+(or cmu sbcl)(sap-ref-32 location offset) + #+clisp(ffi:memory-as location 'ffi:uint32 offset) + value)) + +(defun ref-single-float (location &optional (offset 0)) + #+(or cmu sbcl)(sap-ref-single location offset) + #+clisp(ffi:memory-as location 'single-float offset)) + +(defun (setf ref-single-float) (value location &optional (offset 0)) + (setf + #+(or cmu sbcl)(sap-ref-single location offset) + #+clisp(ffi:memory-as location 'single-float offset) + value)) + +(defun ref-double-float (location &optional (offset 0)) + #+(or cmu sbcl)(sap-ref-double location offset) + #+clisp(ffi:memory-as location 'double-float offset)) + +(defun (setf ref-double-float) (value location &optional (offset 0)) + (setf + #+(or cmu sbcl)(sap-ref-double location offset) + #+clisp(ffi:memory-as location 'double-float offset) + value)) + + + (defparameter *memory-allocator* nil) (defparameter *memory-deallocator* nil) -- 2.11.0