• madhu's avatar
    backend/openmcl.lisp: (to-format): ensure bivalent streams get created · d93f2397
    madhu authored
    Explicitly specifying :FORMAT :TEXT to CCL:MAKE-SOCKET
    makes the socket monovalent.  (This is at odds with the doc)
    So use :BIVALENT instead of TEXT in the ccl backend
    
    (in-package "CL-USER")
    (defun test-bivalence (sock)
      (list :write-byte (ignore-errors (write-byte 95 sock))
    	:write-char (ignore-errors (write-byte #\G sock))
    	:format (ccl:socket-format sock)
    	:external-format (stream-external-format sock)
    	:element-type (stream-element-type sock)))
    
    (defmacro getf-and-remf (place indicator default)
      `(let ((val (getf ,place ,indicator)))
         (cond (val (remf ,place ,indicator) val)
    	   (t ,default))))
    
    (defun make-sock (&rest make-socket-args)
      (let* ((args (copy-seq make-socket-args))
    	 (remote-host (getf-and-remf args :remote-host "localhost"))
    	 (remote-port (getf-and-remf args :remote-port 22)))
        (apply #'ccl:make-socket
    	  :remote-host remote-host
    	  :remote-port remote-port
    	  args)))
    
    (test-bivalence (make-sock)); => (:WRITE-BYTE 95 :WRITE-CHAR #\G :FORMAT :TEXT :EXTERNAL-FORMAT #<EXTERNAL-FORMAT :ISO-8859-1/:UNIX #x302001C9C8ED> :ELEMENT-TYPE CHARACTER)
    
    ;; :TEXT FAILs to be bivalent
    (test-bivalence (make-sock :format :text)) ; => (:WRITE-BYTE NIL :WRITE-CHAR NIL :FORMAT :TEXT :EXTERNAL-FORMAT #<EXTERNAL-FORMAT :ISO-8859-1/:UNIX #x302001C9C8ED> :ELEMENT-TYPE CHARACTER)
    
    (test-bivalence (make-sock :format :binary)) ;  => (:WRITE-BYTE 95 :WRITE-CHAR #\G :FORMAT :BIVALENT :EXTERNAL-FORMAT  #<EXTERNAL-FORMAT :ISO-8859-1/:UNIX #x302001C9C8ED> :ELEMENT-TYPE (UNSIGNED-BYTE 8))
    
    (test-bivalence (make-sock :format :bivalent)) ;  => (:WRITE-BYTE 95 :WRITE-CHAR #\G :FORMAT :TEXT :EXTERNAL-FORMAT #<EXTERNAL-FORMAT :ISO-8859-1/:UNIX #x302001C9C8ED> :ELEMENT-TYPE CHARACTER)
    d93f2397
openmcl.lisp 10.3 KB