Hello,

I try to understand why a Clozure CL 'terminate' method is not called
from the interpreter. I have a CL class jlref, when a jlref object is
no longer referenced the CL garbage collector reclaims it. It is
possible in different CL implementations to add a 'hook' to do some
job at that time. Personally I then unreference the real Julia object
in such a way it can be GC reclaimed in Julia, jlref is just a class
that holds information about it.

For SBCL I have no problem, but 'ccl:terminate' which should be
automatically called is never called. But, and this is the main point,
following an advice in a Clozure mailing list, I tried to use/define
this method directly at execution time using ')fin', and surprisingly,
using ')fin' automatically triggers 'terminate' on every objects that
are/(were ?) reclaimed.

So my question, what does ')fin' do? And do you happen to know where I
need to look in the FriCAS source code to better understand its
effect?

Furthermore, in src/interp/int-top.boot, the documentation says that
to return to the interpreterafer after ')fin'  '(restart)' should be
used. In fact, before some change in the FriCAS source I think, so I
used (|spad|). Again following an advice. And, again, with Clozure CL,
contrary to SBCL, that leads to strange things after returning to the
interpreter and executing foreign code (principally bad addresses and
therefore segfault).

So maybe I first need to know a better CL command, to return to the
interpreter? But also, of course, to know why the ccl:terminate is not
called in the interpreter. R. Munyer in the CCL mailing list found a
way, see the attached transcript file, but he uses ')fin' and no
Clozure CL FFI. I tried to use different (eva-when) to define the
ccl:terminate method without success since the code is build/compiled
(src/lisp).

To resume, since I suspect that different thread issues may also
occur, I would like to better understand the side effects of ')fin'
and how to cleanly return to the interpreter after  'fin' session with
Clozure CL.

Regards,

- Greg

ccl:terminate mechanism:
https://ccl.clozure.com/manual/chapter13.12.html#f_terminate-when-unreachable

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to fricas-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/fricas-devel/CAHnU2dbj90tgj6N3ijM7LyhC__-opXfBjX0PfBfYqJH85c-B0A%40mail.gmail.com.
$ fricas
Checking for foreign routines
FRICAS="/usr/local/lib/fricas/target/x86_64-linux-gnu"
spad-lib="/usr/local/lib/fricas/target/x86_64-linux-gnu/lib/libspad.so"
foreign routines found
openServer result 0
                       FriCAS Computer Algebra System
              Version: FriCAS 1.3.10 built with openmcl 1.12.2
                 Timestamp: Mon 20 May 2024 02:34:03 AM UTC
-----------------------------------------------------------------------------
   Issue )copyright to view copyright notices.
   Issue )summary for a summary of useful system commands.
   Issue )quit to leave FriCAS and return to shell.
-----------------------------------------------------------------------------

(1) -> )lisp *package*
Value = #<Package "BOOT">
(1) -> )lisp (defclass garbage-counter () ((n :initarg :n)))
Value = #<STANDARD-CLASS GARBAGE-COUNTER>
(1) -> )fin
Clozure Common Lisp Version 1.12.2  LinuxX8664

For more information about CCL, please see http://ccl.clozure.com.

CCL is free software.  It is distributed under the terms of the Apache
Licence, Version 2.0.
? *package*
#<Package "BOOT">
?
(defmethod initialize-instance :after
    ((x garbage-counter) &rest initargs)
  (declare (ignore initargs))
  (ccl:terminate-when-unreachable x))
#<STANDARD-METHOD INITIALIZE-INSTANCE :AFTER (GARBAGE-COUNTER)>
?
(let ((s *terminal-io*))
  (defmethod ccl:terminate ((x garbage-counter))
    (let ((n (1+ (slot-value x 'n))))
      (make-instance 'garbage-counter :n n)
      (format s "~&garbage-counter: ~s~%" n)
      (finish-output s))))
#<STANDARD-METHOD CCL:TERMINATE (GARBAGE-COUNTER)>
? (|spad|)
(1) -> )lisp (progn (make-instance 'garbage-counter :n 0) t)
Value = T
(1) -> )lisp (ccl:gc)
Value = NIL
(1) ->
garbage-counter: 1
)lisp (ccl:gc)
Value = NIL
(1) ->
garbage-counter: 2

Reply via email to