X-Git-Url: https://git.distorted.org.uk/~mdw/clg/blobdiff_plain/e7765a408ed091803f0b93ce9e105d9c3ce53a06..5de2b5f6a587aff7590db74f3aa7eb622cd8904c:/glib/glib.lisp diff --git a/glib/glib.lisp b/glib/glib.lisp index a2731eb..3909ac8 100644 --- a/glib/glib.lisp +++ b/glib/glib.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: glib.lisp,v 1.31 2005-04-24 13:27:20 espen Exp $ +;; $Id: glib.lisp,v 1.35 2006-02-19 22:34:28 espen Exp $ (in-package "GLIB") @@ -47,6 +47,23 @@ #+sbcl(system-area-ub8-copy from 0 to 0 length) to) +(defun clear-memory (from length) + #+cmu(system-area-fill 0 0 from 0 (* 8 length)) + #+sbcl(system-area-ub8-fill 0 from 0 length)) + +(defmacro with-allocated-memory ((var size) &body body) + (if (constantp size) + (let ((alien (make-symbol "ALIEN")) + (size (eval size))) + `(with-alien ((,alien (array #+sbcl(sb-alien:unsigned 8) #+cmu(alien:unsigned 8) ,size))) + (let ((,var (alien-sap ,alien))) + (clear-memory ,var ,size) + ,@body))) + `(let ((,var (allocate-memory ,size))) + (unwind-protect + (progn ,@body) + (deallocate-memory ,var))))) + ;;;; User data mechanism @@ -230,7 +247,8 @@ (defmethod reader-function ((type (eql 'glist)) &rest args) (declare (ignore type)) (destructuring-bind (element-type) args - #'(lambda (location &optional (offset 0)) + #'(lambda (location &optional (offset 0) weak-p) + (declare (ignore weak-p)) (unless (null-pointer-p (sap-ref-sap location offset)) (map-glist 'list #'identity (sap-ref-sap location offset) element-type))))) @@ -339,7 +357,8 @@ (defmethod reader-function ((type (eql 'gslist)) &rest args) (declare (ignore type)) (destructuring-bind (element-type) args - #'(lambda (location &optional (offset 0)) + #'(lambda (location &optional (offset 0) weak-p) + (declare (ignore weak-p)) (unless (null-pointer-p (sap-ref-sap location offset)) (map-glist 'list #'identity (sap-ref-sap location offset) element-type))))) @@ -486,7 +505,8 @@ (destructuring-bind (element-type &optional (length '*)) args (if (eq length '*) (error "Can't create reader function for vector of variable size") - #'(lambda (location &optional (offset 0)) + #'(lambda (location &optional (offset 0) weak-p) + (declare (ignore weak-p)) (unless (null-pointer-p (sap-ref-sap location offset)) (map-c-vector 'vector #'identity (sap-ref-sap location offset) element-type length)))))) @@ -607,7 +627,8 @@ (destructuring-bind (element-type) args (unless (eq (alien-type element-type) (alien-type 'pointer)) (error "Elements in null-terminated vectors need to be of pointer types")) - #'(lambda (location &optional (offset 0)) + #'(lambda (location &optional (offset 0) weak-p) + (declare (ignore weak-p)) (unless (null-pointer-p (sap-ref-sap location offset)) (map-0-vector 'vector #'identity (sap-ref-sap location offset) element-type))))) @@ -704,7 +725,8 @@ (defmethod reader-function ((type (eql 'counted-vector)) &rest args) (declare (ignore type)) (destructuring-bind (element-type) args - #'(lambda (location &optional (offset 0)) + #'(lambda (location &optional (offset 0) weak-p) + (declare (ignore weak-p)) (unless (null-pointer-p (sap-ref-sap location offset)) (map-counted-vector 'vector #'identity (sap-ref-sap location offset) element-type)))))