|
:malloc-free allocation -- here: instance methods: msg#00058lisp.clisp.general
Hi, Berkeley DB's C-level interface uses DB->get(...) instead of a fixed function like DB_get(...) How could one interface to this? A possible way is explored here. On instance methods One could use (def-c-struct DB (get (c-function (:arguments ...) ...)) (put (c-function ...)) ...many others function slots) to have CLISP create callable foreign-function objects that match C's DB->put(). (def-call-out db-create ; which you already must have (:arguments (DB (c-ptr c-pointer) :out) ...)) Then (funcall (slot 'get ; create foreign-function object out of DB->get slot (foreign-value (foreign-address-variable ; which nobody has but me ; - much like cast: foreign-address -> foreign-variable (nth-value 1 (db-create ...)) ; that DB pointer 'DB))) db-txn key data flags) One should memoize the foreign-function object, instead of creating a new one for each call. However, duplicating the DB structure in Lisp, if the BDB C structure changes, Lisp doesn't know -- not nice! Unreliable :( A wrapper around the latter remembers me of typical OO frameworks for Scheme, where you pass the function name as argument (to a closure, which does the dispatch): (DB-invoke 'get DB-handle ...args) or (DB-invoke DB-handle 'get ...args) In CL/CLOS, people tend to prefer (DB-get DB-handle ...args) (DB-put DB-handle ...args) It could still be defined as: (defmethod DB-get ((DB-handle DB-class) &rest args) (apply (memoizing-DB-foreign-function-factory DB-handle 'get) args)) Of course, DB-get could be turned into reader slots of the DB-class CLOS miror -- use slots for presumably often used functions like get and put. [memoizing-]DB-foreign-function-factory could be implemented in C, to avoid the problem about the C DB struct being changed by the BDB people, without Lisp noticing this change. This would prevent getting out of sync with BDB/ db.h Regards, Jorg Hohle. ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | :malloc-free allocation (was: FFI guru/wizard award to be rewarde d): 00058, Hoehle, Joerg-Cyril |
|---|---|
| Next by Date: | What are CLISP's "selling" points?: 00058, Hoehle, Joerg-Cyril |
| Previous by Thread: | :malloc-free allocation (was: FFI guru/wizard award to be rewarde d)i: 00058, Hoehle, Joerg-Cyril |
| Next by Thread: | :malloc-free allocation -- here: instance methods: 00058, Aurelio Bignoli |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |