guile-user
[Top][All Lists]
Advanced

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

guile-wiredtiger; moving to ffi


From: Amirouche Boubekki
Subject: guile-wiredtiger; moving to ffi
Date: Tue, 04 Aug 2015 23:04:25 +0200
User-agent: Roundcube Webmail/1.1.2

Héllo guilers,


Today I share with you the current version of guile-wiredtiger.

wiredtiger is similar to gdbm ie. a key/value store persisted to disk with the following features:

- records are ordered by keys using the lexicographic order
- ACID with different semantics (speed vs consistency)
- column aware with index support

It's the storage engine of recent versions mongodb.

Wiredtiger documentation is good, I recommend it:

  http://source.wiredtiger.com/

This is the second version of those bindings, I first did
the bindings using the C API for some reason. I end using
ffi which is not as difficult as I though thanks to nalaginrut and ijp work.

I come up with a little `foreign` macro, to help me with
this work. It has two parts:

- the function pointer
- the lambda that wraps the call to the function pointer
  to process input and output

```
;; Small syntax change to keep the `foreign` readable
(define* ((dynamic-link* shared-object) func-name)
  (dynamic-func func-name shared-object))

;;; foreign macro

(define-syntax-rule (foreign
                     ;; function pointer and signature
                     (ret function-pointer args ...)
                     ;; foreign-function lambda wrapper
                     wrapper)
  (let ((foreign-function (pointer->procedure ret
                                              function-pointer
                                              (list args ...))))
    (lambda (. rest)
        (apply wrapper (append (list foreign-function) rest)))))
```

It's not a tremendous change. It groups all the code that
binds a given function.

A small "hiccup" arise when the function pointer must be retrieved from an argument passed to the final procedure.
Like it's the case in the following example:

```
(define (%connection-close connection)  ;; XXX: we need connection here
  (foreign
(int (connection-structure-close (connection-structure connection)) *pointer* *pointer*)
   (lambda (foreign-function config)
     (let* (;; XXX: prepare foreign-function arguments

            ;; ... some code is missing here

            ;; call the foreign function
(code (foreign-function (connection-handle connection) %config)))
       ;; XXX: process returned `code`
       (eq? code 0))))

;; XXX: define a procedure that easy to call
(define*-public (connection-close connection #:optional (config ""))
  ((%connection-close connection) config))
```

I attached guile-wiredtiger with a basic reference
documentation and a simple example command line tool
that can index text and search. Scoring is left as an
exercice ;)

Also, here is a package for guix

```
(define-public wiredtiger
  (package
    (name "python-wiredtiger")
    (version "2.6.1")
    (source (origin
              (method url-fetch)
(uri (list (string-append "http://source.wiredtiger.com/releases/wiredtiger-";
                                        version ".tar.bz2")))
              (sha256
               (base32
"173gv4yqb47jdbrvn80fbcf94s5sqixag997rw1jhjakxkdiv5xl"))))
    (inputs `(("linux-libre-headers" ,linux-libre-headers)
              ("python-2", python-2)))
    (build-system gnu-build-system)
    (home-page "http://wiredtiger.com/";)
    (synopsis "database engine")
(description "wiredtiger is a key value store that support ACID transactions
and more")
    (license license:gpl2+)))
```

Regards,


Amirouche

Attachment: wiredtiger.scm
Description: Text document

Attachment: wiredtiger.md
Description: Text document

Attachment: haystack.scm
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]