Clozure / ccl

Clozure Common Lisp
http://ccl.clozure.com
Apache License 2.0
840 stars 105 forks source link

Invalid memory operations in the IDE #503

Open svspire opened 2 days ago

svspire commented 2 days ago

In the IDE in CCL 1.12.2 DarwinX8664, assuming there is some editor window open behind the listener, (describe (gui::target)) consistently throws 'invalid memory operation' . Usually it thows to the Altconsole, from which it is rarely recoverable without restarting CCL.

Narrowing this down a bit: (slot-value (gui::target) 'NS:_SIZE-LIMITS) consistently throws an error in the Listener.

But that's only one of the problems.

Further clue: (slot-value (gui::target) 'NS:_FRAME) ; doesn't throw an error, but it returns nonsense float values

The following two patches completely fix the error throws:

;;; Pretty sure the standard definition of nsobject-description is causing crashes
(defun ccl::nsobject-description (nsobject)
  (if (ccl::initialized-nsobject-p nsobject)
      "initialized generic nsobject"
      "uninitialized generic nsobject"))

; Without this patch, following form throws an error:
; (slot-value  (gui::target) 'NS:_SIZE-LIMITS)
(defmethod print-object ((s ns::ns-size) stream)
  (flet ((maybe-round (x)
           (multiple-value-bind (q r) (round x)
             (if (zerop r) q x))))
    (unless nil ; (ccl::%null-ptr-p s)
      (print-unreadable-object (s stream :type t :identity t)
        (format stream "~s X ~s"
                "foo" ;(maybe-round (ns::ns-size-width s)) ; <-- these are the problem
                "bar" ;(maybe-round (ns::ns-size-height s))
                )))
    (ccl::describe-macptr-allocation-and-address s stream)
    ))

With the above two dummy redefinitions, (describe (gui::target)) does not crash. But those patches are useless beyond stopping the errors because they fail to return enough information or they return nonsense.

I need help tracking this down. Obviously I'd like to fix the above issues, but there's also a systemic problem that has crept in some time over the last few versions of MacOS that's causing our assumptions about how to inspect ObjC objects to fail. I'd like to fix the systemic issue.