Permalink
Browse files

Added explicit error checking function for use with IL API functions …

…that do not return simple success/failure and performed minor cleanup.
  • Loading branch information...
1 parent fc314d2 commit dc2c1fb9c4f3b81038be3155ab1bc07ad4777248 @Ralith Ralith committed with Josh Marchán Jan 21, 2010
Showing with 16 additions and 6 deletions.
  1. +9 −4 il.lisp
  2. +4 −1 internal.lisp
  3. +3 −1 package.lisp
View
13 il.lisp
@@ -171,12 +171,12 @@
(defcfun ("ilBindImage" bind-image) :void (image :int))
(defcfun ("ilDeleteImages" %delete-images) :void (num :int) (images :pointer))
-(defun delete-images (images)
- (with-foreign-object (array :uint (length images))
- (loop for i below (length images)
+(defun delete-images (&rest images &aux (count (length images)))
+ (with-foreign-object (array :uint count)
+ (loop for i below count
for image in images
do (setf (mem-aref array :uint i) image))
- (%delete-images (length images) array)))
+ (%delete-images count array)))
(defcfun ("ilLoadImage" %load-image) :boolean (file-name pathname-string))
(deferrwrap load-image (file-name))
@@ -235,3 +235,8 @@
(deferrwrap flip-image))
(defcfun ("ilDetermineType" determine-type) image-type (pathname pathname-string))
+
+(defun check-error ()
+ (let ((error (get-error)))
+ (unless (eq error :no-error)
+ (cl:error (error-condition error)))))
View
@@ -1,9 +1,12 @@
(in-package :%il)
+(defun error-condition (keyword)
+ (make-condition (find-symbol (symbol-name keyword) (find-package :il))))
+
(defmacro maybe-error (call)
`(if ,call
(values)
- (cl:error (make-condition (find-symbol (symbol-name (il::get-error)) (find-package :il))))))
+ (cl:error (error-condition (il::get-error)))))
(defmacro deferrwrap (name &optional args)
`(defun ,name ,args
View
@@ -3,6 +3,7 @@
(:use #:cl #:alexandria)
(:shadow #:error)
(:export
+ #:error-condition
#:maybe-error
#:deferrwrap))
@@ -55,8 +56,9 @@
#:SET-PIXELS
#:SHUTDOWN
#:TEX-IMAGE
- ;; Errors from internal
+ ;; Errors
#:error
+ #:check-error
#:no-error
#:invalid-enum
#:out-of-memory

0 comments on commit dc2c1fb

Please sign in to comment.