[Vala] Problem creating a Source subclass with closures



I'm trying to convert some existing code to use Vala and the GLib main
loop as an exercise in learning the language.  I have this cut-down
(complete) test case which demonstrates a couple of problems:

  public class Event : Object {}
  
  public void processEvent(Event ev) {}
  
  public class QueueHandler : Source {
     public QueueHandler(Queue<Event> queue) {
        unowned Queue<Event> qu = queue;
        SourceFuncs sf = new SourceFuncs();
        sf.prepare = (src, timeout) => {
           if (qu.is_empty()) return false;
           timeout = 0;
           return true;
        };
        sf.check = (src) => { return true; };
        sf.dispatch = (src, cb) => {
           Event? ev = qu.pop_tail();
           if (ev != null) { processEvent(ev); }
           return true;
        };
  
        base(sf, (uint) sizeof(QueueHandler));
     }
  }

First thing is that SourceFuncs doesn't have a constructor, but I can
add one to the vapi:

        [Compact]
        public class SourceFuncs {
                public SourceFuncs() {}
                public SourcePrepareFunc prepare;
                public SourceCheckFunc check;
                public SourceDispatchFunc dispatch;
                public SourceFinalizeFunc finalize;
        }

Once that is done, the compiler runs but crashes, with both 0.11.7 and
0.10.4:  (this message from 0.11.7)

  oselotl.jim> valac -C bug02.vala
  **
  ERROR:arraylist.c:348:vala_array_list_real_get: assertion failed: (_tmp0_)
  Aborted (core dumped)

The backtrace suggests something to do with lambda expressions.  It
only affects the two closures that use 'qu' (i.e. crash goes away if
those are commented out).

I will cut the example down further and add bugzilla entries if
someone will confirm that these seem like valid bugs.


I think I can probably rewrite the code to run all my queues from a
single Source, though, to avoid triggering this problem.

Jim

-- 
 Jim Peters                  (_)/=\~/_(_)                 jim uazu net
                          (_)  /=\  ~/_  (_)
 UazĂș                  (_)    /=\    ~/_    (_)                http://
 in Peru            (_) ____ /=\ ____ ~/_ ____ (_)            uazu.net



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