r11859: Canonicalize whitespace
[uffi.git] / tests / strtol.lisp
index 8252f7fb65e97a3f691f5590e636baefa969e973..ee20f1317ee5c0517ee7a6f766d0f58286cf9bd1 100644 (file)
 (in-package #:uffi-tests)
 
 (uffi:def-foreign-type char-ptr (* :unsigned-char))
-  
+
 ;; This example does not use :cstring to pass the input string since
 ;; the routine needs to do pointer arithmetic to see how many characters
 ;; were parsed
 
-(uffi:def-function ("strtol" c-strtol) 
+(uffi:def-function ("strtol" c-strtol)
     ((nptr char-ptr)
      (endptr (* char-ptr))
      (base :int))
@@ -33,26 +33,26 @@ Condition flag is T if all of string parses as a long, NIL if
 their was no string at all, or an integer indicating position in string
 of first non-valid character"
   (let* ((str-native (uffi:convert-to-foreign-string str))
-        (endptr (uffi:allocate-foreign-object 'char-ptr))
-        (value (c-strtol str-native endptr base))
-        (endptr-value (uffi:deref-pointer endptr 'char-ptr)))
+         (endptr (uffi:allocate-foreign-object 'char-ptr))
+         (value (c-strtol str-native endptr base))
+         (endptr-value (uffi:deref-pointer endptr 'char-ptr)))
 
     (unwind-protect
-        (if (uffi:null-pointer-p endptr-value)
-            (values value t)
-            (let ((next-char-value (uffi:deref-pointer endptr-value :unsigned-char))
-                  (chars-parsed (- (uffi:pointer-address endptr-value)
-                                   (uffi:pointer-address str-native))))
-              (cond
-                ((zerop chars-parsed)
-                 (values nil nil))
-                ((uffi:null-char-p next-char-value)
-                 (values value t))
-                (t
-                 (values value chars-parsed)))))
+         (if (uffi:null-pointer-p endptr-value)
+             (values value t)
+             (let ((next-char-value (uffi:deref-pointer endptr-value :unsigned-char))
+                   (chars-parsed (- (uffi:pointer-address endptr-value)
+                                    (uffi:pointer-address str-native))))
+               (cond
+                 ((zerop chars-parsed)
+                  (values nil nil))
+                 ((uffi:null-char-p next-char-value)
+                  (values value t))
+                 (t
+                  (values value chars-parsed)))))
       (progn
-       (uffi:free-foreign-object str-native)
-       (uffi:free-foreign-object endptr)))))
+        (uffi:free-foreign-object str-native)
+        (uffi:free-foreign-object endptr)))))
 
 (deftest :strtol.1 (strtol "123") 123 t)
 (deftest :strtol.2 (strtol "0") 0 t)
@@ -60,5 +60,5 @@ of first non-valid character"
 (deftest :strtol.4 (strtol "a") nil nil)
 
 
-                          
+