libevent and exceptions
e-t172
idontlikespam at nospam.com
Thu Mar 22 12:40:24 PDT 2007
When using the C libevent library
(http://www.monkey.org/~provos/libevent/), i can't throw any exceptions
from inside an event callback (trying to do so results in a segmentation
fault).
Example :
import std.stdio;
import std.math;
import std.date : TicksPerSecond;
import c.libevent; // C bindings, if you want to see them just tell me
void main()
{
auto base = event_init();
auto event = new event;
event_set(event, -1, EV_TIMEOUT, &foo, null);
int time = 3 * TicksPerSecond;
auto tv = new timeval;
tv.tv_sec = cast(int) floor(time / TicksPerSecond);
tv.tv_usec = cast(int) ceil((time / TicksPerSecond) * 1000000);
event_add(event, tv);
event_base_loop(base, 0);
}
extern(C) void foo(int fd, short type, void* arg)
{
writefln("Boo.");
throw new Exception("Booboo.");
}
Result :
$ dmd excptest.d c/libevent.d -L-levent -L-L/usr/local/libevent/lib
gcc excptest.o libevent.o -o excptest -m32 -lphobos -lpthread -lm
-Xlinker -levent -Xlinker -L/usr/local/libevent/lib -Xlinker
-L/usr/local/dmd/lib
$ ./excptest
Boo.
Segmentation fault
Any ideas how to make this work ?
e-t172
More information about the Digitalmars-d-learn
mailing list