Вопрос

In using swig to wrap a C++ library, I had been attempting to bypass a compile-time error of an uneql constant being redefined … in this case, to an equal but uneql string literal.

Strangely, in SLIME I was able to simply invoke the CONTINUE restart and bypass this particular error. However, when I try to wrap it with a handler-case and build it via either compile-file or slime-compile-file or via buildapp, the CONTINUE restart seems to be missing. (format t "Restarts: ~{~% • ~A~% ~:*~S~}" (compute-restarts)) concurs. Just to be paranoid, I've tried:

   (continue)
   (invoke-restart 'continue)
   (invoke-restart (find-restart 'cl::continue))

and a few variations.

(unless (continue) (warn "Can't continue")) is also, strangely, not warning me, but the compilation doesn't finish the file, either.

Due to some more awful cases of C++ polymorphism that I want to convert to keyword arguments, I'm continuing onwards with a copied and edited version of the swig generated code, but I'm curious why the restart would be absent and whether I could have done something (some hard-to-locate dynamic setting, perhaps) that would bypass it.

Edit: Lest it be helpful, one variaton has been:

(handler-case
  (compile-file "path/to/swig-made-this-mess")
  ;; contains (defconstant foo "string")

  #+sbcl
  (SB-EXT:DEFCONSTANT-UNEQL (condition)
    (let ((name (SB-EXT:DEFCONSTANT-UNEQL-NAME condition))
          (before (SB-EXT:DEFCONSTANT-UNEQL-OLD-VALUE condition))
          (after (SB-EXT:DEFCONSTANT-UNEQL-NEW-VALUE condition)))
      (if (equal before after)
          (progn
            (warn "Redefining constant to un-EQL but EQUAL value~%~S ← ~S"
                  name after)
            (unless (continue)
              (warn "Unable to CONTINUE~%~%Restarts:~{~% • ~A~%     ~:*~S~}"
                    (compute-restarts))
              (signal condition)))
          (progn
            (warn "Redefining constant to un-EQUAL value:~%~S ←~%before: ~S~%after: ~S"
                  name before after)
            (signal condition))))))
Это было полезно?

Решение

HANDLER-CASE isn't the right tool. By the time its clauses are invoked, the stack has already unwound. HANDLER-BIND's clauses are invoked in the context where the error was signaled before the stack unwinds, so use HANDLER-BIND instead.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top