emacs-devel
[Top][All Lists]
Advanced

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

Re: Lisp object that refers to a C struct


From: Eli Zaretskii
Subject: Re: Lisp object that refers to a C struct
Date: Wed, 17 Oct 2012 18:05:37 +0200

> From: Stefan Monnier <address@hidden>
> Cc: address@hidden
> Date: Tue, 16 Oct 2012 17:43:26 -0400
> 
> > In any case, which one, pseudovector or misc, is better suited for
> > this particular job, in your opinion?  What would you use?
> 
> I guess I'd go with the Lisp_Misc.

OK, thanks.

> The code to free the C struct will be the one you write
> specifically for it, nobody else knows how to free it.

Then the code that GC's this new Lisp object will have to be entirely
specific to the layout of the struct I'm using, right?  It won't be
suitable even for the similar-but-different inotify code, right?  If
so, it's too bad: I hoped I could come up with some Lisp object that
could be a wrapper for an arbitrary C struct, so that any similar
feature that will need to pass opaque objects to Lisp could do that,
instead of adding yet another object type.

If it's possible to do this in some generic way, could you please
explain how?

> > That code must be run whenever the object is GC'ed, at the very least.
> > It would be even better not to leave this to GC at all, but instead
> > delete the object whenever the watch is canceled, since otherwise we
> > leave behind a thread that does nothing except wasting system
> > resources, for a time interval whose length cannot be predicted
> > or controlled.
> 
> If you make sure there's at most 1 file-watcher object per C struct,
> then you can easily zero-out its pointer-field after freeing the
> C struct, so you can make sure you protect yourself from
> dangling pointers.  And if you make sure the GC calls you back when
> freeing the file-watcher, then you can make sure that you don't leak the
> C structs.

You mean, have the free_my_object function (to be called by GC) call
my own code?  Or is there a more generic way?



reply via email to

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