chiark / gitweb /
Broken make-glist and glist copy function fixed
authorespen <espen>
Tue, 1 Apr 2008 21:17:59 +0000 (21:17 +0000)
committerespen <espen>
Tue, 1 Apr 2008 21:17:59 +0000 (21:17 +0000)
glib/glib.lisp

index e8f6f47c5f0579120f53ee351d2240b2aa9a9c54..220002efd145a059d09b7cfc9b2d3f74997fbcd8 100644 (file)
@@ -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.
 
 ;; 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.42 2007-10-17 14:30:41 espen Exp $
+;; $Id: glib.lisp,v 1.43 2008-04-01 21:17:59 espen Exp $
 
 
 (in-package "GLIB")
 
 
 (in-package "GLIB")
@@ -152,19 +152,22 @@ (defbinding quark-to-string () (static string)
 (deftype glist (type) 
   `(or null (cons ,type list)))
 
 (deftype glist (type) 
   `(or null (cons ,type list)))
 
-(defbinding (%glist-append "g_list_append") () pointer
+(defbinding (%glist-prepend "g_list_prepend") () pointer
   (glist (or null pointer))
   (nil null))
 
   (glist (or null pointer))
   (nil null))
 
+(defbinding (%glist-reverse "g_list_reverse") () pointer
+  (glist (or null pointer)))
+
 (defun make-glist (element-type list &optional temp-p)
   (let ((writer (if (functionp element-type)
                    element-type
                  (writer-function element-type :temp temp-p))))
     (loop
      for element in list
 (defun make-glist (element-type list &optional temp-p)
   (let ((writer (if (functionp element-type)
                    element-type
                  (writer-function element-type :temp temp-p))))
     (loop
      for element in list
-     as glist = (%glist-append nil) then (%glist-append glist)
+     as glist = (%glist-prepend nil) then (%glist-prepend glist)
      do (funcall writer element glist)
      do (funcall writer element glist)
-     finally (return glist))))
+     finally (return (%glist-reverse glist)))))
 
 (defun glist-next (glist)
   (unless (null-pointer-p glist)
 
 (defun glist-next (glist)
   (unless (null-pointer-p glist)
@@ -324,12 +327,11 @@ (define-type-method copy-function ((type glist) &key inlined)
       #'(lambda (from to &optional (offset 0))
          (unless (null-pointer-p (ref-pointer from offset))
            (loop
       #'(lambda (from to &optional (offset 0))
          (unless (null-pointer-p (ref-pointer from offset))
            (loop
-            as from-list = (ref-pointer from offset) 
-                           then (glist-next from-list)
-            as to-list = (setf (ref-pointer to offset) (%glist-append nil)) 
-                         then (%glist-append to-list)
+            as from-list = (ref-pointer from offset) then (glist-next from-list)
+            as to-list = (%glist-prepend nil) then (%glist-prepend to-list)
             do (funcall copy-element from-list to-list)
             do (funcall copy-element from-list to-list)
-            while (glist-next from-lisT)))))))
+            while (glist-next from-list)
+            finally (setf (ref-pointer to offset) (%glist-reverse to-list))))))))
 
 
 ;;;; Single linked list (GSList)
 
 
 ;;;; Single linked list (GSList)