/[cl-plus-ssl]/cl+ssl/ffi-buffer-clisp.lisp
ViewVC logotype

Contents of /cl+ssl/ffi-buffer-clisp.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Sat Oct 24 20:09:40 2009 UTC (4 years, 5 months ago) by avodonosov
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -0 lines
XCVB support (by Fare <fahree@gmail.com>)
1 #+xcvb (module (:depends-on ("package" "reload" "conditions" "ffi" "ffi-buffer-all")))
2
3 (in-package :cl+ssl)
4
5 (defun make-buffer (size)
6 (cffi-sys:%foreign-alloc size))
7
8 (defun buffer-length (buf)
9 (declare (ignore buf))
10 +initial-buffer-size+)
11
12 (defun buffer-elt (buf index)
13 (ffi:memory-as buf 'ffi:uint8 index))
14 (defun set-buffer-elt (buf index val)
15 (setf (ffi:memory-as buf 'ffi:uint8 index) val))
16 (defsetf buffer-elt set-buffer-elt)
17
18 (declaim
19 (inline calc-buf-end))
20
21 ;; to calculate non NIL value of the buffer end index
22 (defun calc-buf-end (buf-start vec vec-start vec-end)
23 (+ buf-start
24 (- (or vec-end (length vec))
25 vec-start)))
26
27 (defun v/b-replace (vec buf &key (start1 0) end1 (start2 0) end2)
28 (when (null end2)
29 (setf end2 (calc-buf-end start2 vec start1 end1)))
30 (replace
31 vec
32 (ffi:memory-as buf (ffi:parse-c-type `(ffi:c-array ffi:uint8 ,(- end2 start2))) start2)
33 :start1 start1
34 :end1 end1))
35
36 (defun b/v-replace (buf vec &key (start1 0) end1 (start2 0) end2)
37 (when (null end1)
38 (setf end1 (calc-buf-end start1 vec start2 end2)))
39 (setf
40 (ffi:memory-as buf (ffi:parse-c-type `(ffi:c-array ffi:uint8 ,(- end1 start1))) start1)
41 (subseq vec start2 end2)))
42
43 (defmacro with-pointer-to-vector-data ((ptr buf) &body body)
44 `(let ((,ptr ,buf))
45 ,@body))

  ViewVC Help
Powered by ViewVC 1.1.5