+(defun make-alien-slot-name (alien-type slot-name)
+ (intern (format nil "~A-~A" alien-type slot-name)
+ (symbol-package slot-name)))
+
+(declaim (inline alien-to-protocol-class))
+(defun alien-to-protocol-class (alien alien-type instance protocol-class slots)
+ "Copy SLOTS from the alien object ALIEN of type ALIEN-TYPE to INSTANCE, an instance of PROTOCOL-CLASS.
+We assume that SLOT names are the same in the alien object and in
+the protocol-class."
+ (unless instance
+ (setf instance (make-instance protocol-class)))
+ (loop for slot in slots
+ do (setf (slot-value instance slot)
+ (sb-alien:slot alien slot)))
+ instance)
+
+(defun protocol-class-to-alien (instance protocol-class alien alien-type slots)
+ (loop for slot in slots
+ do (setf (sb-alien:slot alien slot) (slot-value instance slot)))
+ instance)
+