[librep] added rep.ffi.util



commit 13c87580b7699121643a039d3174d993e3b20c23
Author: Christopher Roy Bratusek <zanghar freenet de>
Date:   Sat Sep 25 19:14:06 2010 +0200

    added rep.ffi.util

 ChangeLog             |    6 +++-
 lisp/Makefile.in      |    2 +-
 lisp/rep/ffi/util.jl  |   70 +++++++++++++++++++++++++++++++++++++++++++++++++
 lisp/rep/ffi/util.jlc |  Bin 0 -> 783 bytes
 man/news.texi         |    7 +++++
 5 files changed, 83 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d84ec2e..320d540 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,8 @@
-2010-09-10  Christohper Bratusek <zanghar freenet de>
+2010-09-25  Christopher Bratusek <zanghar freenet de>
+	* lisp/Makefile.in
+	* lisp/rep/ffi/util.jl: added ffi utils. [Sergey Bolshakov]
+
+2010-09-10  Christopher Bratusek <zanghar freenet de>
 	* src/Makefile.in: fix uninstall rule
 
 2010-09-07  Teika Kazura <teika lavabit com>
diff --git a/lisp/Makefile.in b/lisp/Makefile.in
index 8d50388..48635a5 100644
--- a/lisp/Makefile.in
+++ b/lisp/Makefile.in
@@ -26,7 +26,7 @@ INSTALL_FILES = *.jl *.jlc
 INSTALL_DIRS := . rep rep rep/lang rep/vm rep/vm/compiler rep/io \
 	rep/io/file-handlers rep/io/file-handlers/remote rep/i18n \
 	rep/data rep/www rep/util rep/mail rep/threads rep/system \
-	rep/net rep/test rep/xml
+	rep/net rep/test rep/xml rep/ffi
 
 all : lisp
 
diff --git a/lisp/rep/ffi/util.jl b/lisp/rep/ffi/util.jl
new file mode 100644
index 0000000..44c405e
--- /dev/null
+++ b/lisp/rep/ffi/util.jl
@@ -0,0 +1,70 @@
+#| util.jl -- FFI helpers
+
+  Author: Sergey Bolshakov <sbolshakov altlinux ru>
+  Version: $Id: util.jl,v 1.5 2006/07/16 19:40:32 me Exp $
+
+  This file is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2, or (at your option)
+  any later version.
+
+  This file is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this file.  If not, write to the Free Software
+  Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+
+|#
+
+(define-structure rep.ffi.util
+
+    (export ffi-bind
+	    ffi-type-enum)
+
+    (open rep
+	  rep.ffi
+	  rep.data.tables)
+
+  (define (ffi-bind soname tab)
+    (let ((handle (ffi-load-library soname))
+	  (symtab (make-table symbol-hash eq-hash))
+	  (ifacetab (make-table symbol-hash eq-hash)))
+      (mapc
+       (lambda (elt)
+	 (apply
+	  (lambda (key dlsym ret . args)
+	    (table-set symtab key (ffi-lookup-symbol handle dlsym))
+	    (table-set ifacetab key (ffi-interface ret args)))
+	  elt))
+       tab)
+      (lambda (key . args)
+	(and
+	 (table-bound-p symtab key)
+	 (ffi-apply (table-ref ifacetab key)
+		    (table-ref symtab key) args)))))
+
+  (define (enump sym enum-alist)
+    (and (symbolp sym)
+	 (assq sym enum-alist)))
+
+  (define (enum->sym num enum-alist)
+    (let ((p (rassq num enum-alist)))
+      (if p (car p)
+	(signal 'bad-arg `(,num)))))
+
+  (define (sym->enum sym enum-alist)
+    (let ((p (assq sym enum-alist)))
+      (if p (cdr p)
+	(signal 'bad-arg `(,sym)))))
+  
+  (define (ffi-type-enum enum-alist)
+    (ffi-type
+     ffi-type-sint32
+     (lambda (x) (enump x enum-alist))
+     (lambda (x) (sym->enum x enum-alist))
+     (lambda (x) (enum->sym x enum-alist))))
+
+  )
diff --git a/lisp/rep/ffi/util.jlc b/lisp/rep/ffi/util.jlc
new file mode 100644
index 0000000..f4e8b22
Binary files /dev/null and b/lisp/rep/ffi/util.jlc differ
diff --git a/man/news.texi b/man/news.texi
index 20d4991..1f5a376 100644
--- a/man/news.texi
+++ b/man/news.texi
@@ -3,6 +3,13 @@
 @chapter News
 @cindex News
 
+ heading 0.91.1
+ itemize @bullet
+
+ item @code{rep.ffi.util} module [Sergey Bolshakov]
+
+A module containing utils for rep's ffi binding.
+ end itemize
 @heading 0.91.0
 @itemize @bullet
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]