[Top][All Lists]

[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 17:50:09 +0200

> From: "Stephen J. Turnbull" <address@hidden>
> Cc: Stefan Monnier <address@hidden>,
>     address@hidden
> Date: Wed, 17 Oct 2012 15:21:40 +0900
> Eli Zaretskii writes:
>  > > What happens if someone passes you this same integer some time after
>  > > you've freed the C struct?
> More interesting, what happens if somebody chooses "I feel lucky" and
> passes you a random integer that happens to be a "live" watch?

I don't follow: what do you mean "somebody passes me a random

There are only 2 APIs that expose this integer to Lisp: one that
starts watching for file changes, and another that cancels an existing
watch.  The former returns the integer we are talking about, the
latter accepts that integer and uses it to access the underlying C
struct, shut down the thread that was doing the watch, and delete the
struct and all the other resources the watch was using.

So if they pass me the integer that happens to reference a live watch,
they can only do that through the "remove" API, in which case the
watch will stop.

Or did you mean something else?

> ISTM it fails safe (ie, doesn't crash).

It's fail-safe, yes (well, barring bugs ;-).

> But it's not good.

Why not?  If a luser asked to shut down a watch, and just "happened"
to specify a live one, she gets what she asked for.  It's not like
Emacs _needs_ those watches for some of its internal workings.

> So really you want this to be entirely internal somehow.  The only
> way to do that is to have an opaque type that you can only get a
> pointer to from the watch constructor.

I don't think we have opaque data types in Emacs.

reply via email to

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