port.lisp 1012 B

12345678910111213141516171819202122232425262728293031323334353637
  1. (in-package :mach)
  2. ;;
  3. ;; This file defines the mach_port_t foreign type.
  4. ;;
  5. (define-foreign-type <port-type> ()
  6. ()
  7. (:documentation "mach_port_t CFFI type.")
  8. (:actual-type :unsigned-int)
  9. (:simple-parser port))
  10. (defconstant +port-null+ 0 "MACH_PORT_NULL")
  11. ;; MACH_PORT_DEAD is ~0 casted to mach_port_t
  12. ;; which means that it's largest representable number in 'port' bits
  13. (defconstant +port-dead+ (largest-representable-number
  14. (num-bits (foreign-type-size 'port))))
  15. (defmethod translate-from-foreign (value (type <port-type>))
  16. "Translates a port value to a more lispy one"
  17. (cond
  18. ((eq +port-null+ value) nil) ; MACH_PORT_NULL is just... nil.
  19. ((eq +port-dead+ value) :dead) ; MACH_PORT_DEAD is :dead.
  20. (t ; Else, it's a 'boring' integer.
  21. value)))
  22. (defmethod translate-to-foreign (value (type <port-type>))
  23. "Translates a lispy port value to a foreign one"
  24. (cond
  25. ((null value) +port-null+)
  26. ((eq value :dead) +port-null+)
  27. (t
  28. value)))