-;;;; Callback and user data mechanism
-
-(declaim (fixnum *user-data-count*))
-
-(defvar *user-data* (make-hash-table))
-(defvar *user-data-count* 0)
-
-(defun register-user-data (object &optional destroy-function)
- (check-type destroy-function (or null symbol function))
-; (incf *user-data-count*)
- (setq *user-data-count* (the fixnum (1+ *user-data-count*)))
- (setf
- (gethash *user-data-count* *user-data*)
- (cons object destroy-function))
- *user-data-count*)
-
-
-(defun find-user-data (id)
- (check-type id fixnum)
- (multiple-value-bind (user-data p) (gethash id *user-data*)
- (values (car user-data) p)))
-
-
-(defun register-callback-function (function)
- (check-type function (or null symbol function))
- ; We treat callbacks just as ordinary user data
- (register-user-data function))
-
-
-(defun callback-trampoline (callback-id nargs arg-array)
- (declare (fixnum callback-id nargs))
- (let* ((return-arg (unless (null-pointer-p arg-array)
- (arg-array-ref arg-array nargs)))
- (return-type (if return-arg
- (type-from-number (arg-type return-arg))
- nil))
- (args nil)
- (callback-function (find-user-data callback-id)))
-
- (dotimes (n nargs)
- (push (arg-value (arg-array-ref arg-array (- nargs n 1))) args))