On Tue, May 21, 2024 at 01:57:45PM +0200, Grégory Vanuxem wrote:
> 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?

AFAIK ')fin' is doing "nothing", is just returns back to whatever Lisp
was doing befor calling FriCAS.  To understand relation with Lisp,
look at 'src/lisp/fricas-lisp.lisp', in particular 'save-core-restart'.


> 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).

The function to start FriCAS is 'fricas_restart'.  'fricas_restart'
is doing some initialization which may be unnecessary when executed
second time.  OTOH re-doing initalization should be harmless and
some probably is needed.

Note that ')fin' is really unsuppored by FriCAS, basically
it is "pray that Lisp will do what you want".  In particular IIRC
it simply quits FriCAS when using ECL and I think it never fully
worked with Clozure CL.

> 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).

I think that ')fin' is irrelevant, you should get the same effect
using ')lisp' or if that is inconvenient you can put code in the
file and use ')read'.  The main difference is that FriCAS needs
specific settings of several global variables and FriCAS catches
errors (there are several use of 'CATCH' and there is 'handler-bind').
This _should_ make no difference.  What _may_ matter is order of
initialization.  In particular FriCAS performs some initializations
before dumping image.  But several thing do not survive to
restarted image, so need to be done later, after start of new image.

> 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.

If there are any side effects, they are purely due to Clozure CL.

-- 
                              Waldek Hebisch

-- 
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/ZkzoyJ93yR2Jhd1j%40fricas.org.

Reply via email to