[Gambas-user] Pb instanciating inotify watch

Tobias Boege taboege at gmail.com
Thu Mar 7 09:59:18 CET 2019


On Thu, 07 Mar 2019, Bruce wrote:
> On 7/3/19 6:04 pm, Cedron Dawg wrote:
> > I'm feeling prescient.  I wrote this a few hours ago:
> > 
> > https://forum.gambas.one/viewtopic.php?f=4&t=669
> > 
> > It's called "The True True"
> > 
> > Not exactly spot on, but close.
> >
> Nothing is false! Therefore everything is true.
> This is getting very confusing.
> b
> 

What is? The Watch.Events case or the arithmetic properties of True?
I thought I made a good summary of the situation with this paragraph:

> >> Every use of `Watch.Events[Mask] = Value` sets all events in the
> >> Mask (an OR of event constants representing a set of events) to Value,
> >> without affecting the state of events outside the set. That's how
> >> it was supposed to be, how it was initially implemented, how it is
> >> documented inside the source code, how the array interface makes sense,
> >> it's just not what the current implementation does.

Before my change an hour ago, the Watch.Events object would roughly
do this (details omitted and written in Gambas):

  Public Sub _put(Value As Boolean, Mask As Integer)
    $hInotify.Events = Mask
  End

where $hInotify is a hypothetical object representing the kernel's
inotify watch and assigning to its Events property subscribes and
unsubscribes certain events. What it should have done according
to documentation, what it did initially and what it does now is:

  Public Sub _put(Value As Boolean, Mask As Integer)
    If Value Then
      $hInotify.Events = $hInotify.Events Or Mask
    Else
      $hInotify.Events = $hInotify.Events And Not Mask
    Endif
  End

Notice how:

  - it doesn't ignore the Value argument anymore,
  - turns on/off only the events given in the Mask
    and leaves the other bits alone,
  - the Mask can be a single event constant or an
    OR of multiple of them.

The faulty implementation was part of a big refactor done by Benoît
back in the day. I suspect he misjudged what the array accessors did
before rewriting them from scratch. That's how the implementation
and interface/intent drifted apart. And anyway, I imagine most users
never touching Watch.Events directly because a Watch object auto-
magically watches everything you wrote an event handler for.
(That's what all gb.inotify users in the Gambas source tree do.)
That could explain why it wasn't discovered before.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk


More information about the User mailing list