[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The “finalized” SMOB type

From: David Kastrup
Subject: Re: The “finalized” SMOB type
Date: Sun, 09 Oct 2016 00:02:32 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

address@hidden (Ludovic Courtès) writes:

> Hello,
> Commit 8dff3af087c6eaa83ae0d72aa8b22aef5c65d65d (introduced in 2.0.12)
> changes the type of SMOBs to the “finalized” type just before calling
> the SMOB’s free function.
> This doesn’t play well with free functions that up to now assumed they
> would be getting a SMOB of the type they handle.  One of Guile-SSH’s
> free functions goes like this:
> size_t
> free_session (SCM session_smob)
> {
>   struct session_data *data = _scm_to_session_data (session_smob);
>   [...]
>   return 0;
> }
> … where ‘_scm_to_session_data’ raises a wrong-type-arg error if its
> argument is not a session SMOB.  With 2.0.12, this exception is
> systematically triggered.
> I don’t have a good solution to this and I think Guile-SSH will have to
> work around it anyway, but I think this situation is not uncommon.
> Thoughts?

The alternative to using a single "finalized" type would be to sacrifice
a whole bit for the "finalized" information.  This bit would stop the
type from getting sweeped (for example using the mark_smob hook) while
still allowing the type to be retrieved.

However, once the type is stopped from getting sweeped, all of its
internals are up for being collected and finalized, possibly _before_
the type itself.

Now Guile uses Java collection semantics (set somewhere obscure in the
guardian module if memory serves me right) which is described something

GC_API GC_ATTR_DEPRECATED int GC_java_finalization;
                        /* Mark objects reachable from finalizable      */
                        /* objects in a separate post-pass.  This makes */
                        /* it a bit safer to use non-topologically-     */
                        /* ordered finalization.  Default value is      */
                        /* determined by JAVA_FINALIZATION macro.       */
                        /* Enables register_finalizer_unreachable to    */
                        /* work correctly.                              */
                        /* The setter and getter are unsynchronized.    */
GC_API void GC_CALL GC_set_java_finalization(int);
GC_API int GC_CALL GC_get_java_finalization(void);

This might be enough to make the scheme work.  A whole bit of type field
might be much, however.  I seem to remember that there are only 8 to go
around anyway.

David Kastrup

reply via email to

[Prev in Thread] Current Thread [Next in Thread]