From 1454d61edaaf79bc9462c4d6816ffc647dfea414 Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Tue, 1 Feb 2011 22:02:24 +0100 Subject: [PATCH] WITH-C-ENVIRONMENT: initialize pointer array to NULLs --- src/os/os-unix.lisp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/os/os-unix.lisp b/src/os/os-unix.lisp index 32cbc06..629609d 100644 --- a/src/os/os-unix.lisp +++ b/src/os/os-unix.lisp @@ -121,9 +121,7 @@ of SETF ENVIRONMENT." (maphash (lambda (k v) (setf (mem-aref argv :pointer (incf offset)) (foreign-string-alloc (concatenate 'string k "=" v)))) - variables) - ;; final null pointer - (setf (mem-aref argv :pointer argc) (null-pointer)))) + variables))) (defun deallocate-null-ended-list (argv) (loop :for i :from 0 @@ -132,7 +130,7 @@ of SETF ENVIRONMENT." :else :do (foreign-free ptr))) (defmacro with-c-environment ((var environment) &body body) - (with-gensyms (body-fn ptr) + (with-gensyms (body-fn ptr count) `(flet ((,body-fn (,ptr) (let ((,var ,ptr)) ,@body))) @@ -142,13 +140,15 @@ of SETF ENVIRONMENT." ((eql t) (,body-fn isys:*environ*)) (environment - (with-foreign-object (,ptr :pointer (1+ (hash-table-count - (environment-variables ,environment)))) - (unwind-protect - (progn - (allocate-env ,ptr (environment-variables ,environment)) - (,body-fn ,ptr)) - (deallocate-null-ended-list ,ptr)))))))) + (let ((,count (1+ (hash-table-count + (environment-variables ,environment))))) + (with-foreign-object (,ptr :pointer ,count) + (isys:bzero ,ptr (* ,count (isys:sizeof :pointer))) + (unwind-protect + (progn + (allocate-env ,ptr (environment-variables ,environment)) + (,body-fn ,ptr)) + (deallocate-null-ended-list ,ptr))))))))) ;;;; Current directory -- 2.11.4.GIT