[RFC] extending ev++.h to add C++ loop wrappers.

Leandro Lucarella llucax at gmail.com
Thu Jan 17 13:50:57 CET 2008


Marc Lehmann, el 17 de enero a las 08:57 me escribiste:
> On Wed, Jan 16, 2008 at 04:12:02PM -0200, Leandro Lucarella <llucax at gmail.com> wrote:
> > Marc Lehmann, el 16 de enero a las 05:43 me escribiste:
> > I'm trying to go back to this design, but I'm starting to need the loop to
> > be virtual again because, I can't put ev_xxx_destroy () call in the
> > destructor in the ev::loop (to follow the proposed names above).
>
> Ah, because you shouldn't, you can just put the relevant destructor into
> loop_dynamic and loop_default, as a mere loop will not destruct the loop, it
> will be merely a container for the loop pointer.
>
> > if ~loop () is empty and each destructor has it own ev_xxx_destroy ()
> > call, then when using a loop pointer, you can't destroy the loop
> > because of the lack of virtualness:
>
> Thats fine, a virtual destructor isn't really neecssary for a thin
> interface. think about it: you *need* to use the right type to construct,
> and you should use the same type when deleting, i.e. the problem will only
> come up when you:
>
>    loop_dynamic *l = new loop_dynamic;
>    delete (loop *)l;
>
> That is pretty dumb to begin with.

No, the problem is, for example:

void cb (ev::io &w, int revents)
{
        w.loop->unloop();
        delete w.loop;
}

This would be strange anyways, because you probably will know beforehand
that *that* loop is really a dynamic or default loop.

OTOH if w.lopp is a loop_ref instead of a ev_loop*, you can't even do the
delete w.loop because it's a value type. You should do something like
w.loop.destroy (), but that destroy have to be virtual, unless
ev_loop_destroy () can destroy both type of loops (which I think I could
be nice and avoid some problems).

> Besides, I would expect most loops not to be dynamically allocated at all,
> but just be static global objects, or members of some other object. I do
> not see the reason for a dynamically allocating a loop itself.

Agree, but you never know :)

> So... I don't really see the need for a virtual destructor (again, just
> because this is suppused to be a very thin interface).

Ok.

Can I rely on ev_loop_{fork,destroy} accepting default loops when
EV_MULTIPLICITY is set?

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Vaporeso, al verse enfundado por la depresión, decide dar fin a su vida
tomando Chinato Garda mezclado con kerosene al 50%. Ante el duro trance
pierde la movilidad en sus miembros derechos: inferior y superior. En
ese momento es considerado como el hombre líder del movimiento de
izquierda de Occidente.




More information about the libev mailing list