On Wed, 2006-11-08 at 01:02 -0800, Erick Tryzelaar wrote: > Erick Tryzelaar wrote:
> > Of course, this leads to a new bug :) This errors out with this: > > > > foo2.cpp: In function 'void > > flxusr::foo2::_init_(flxusr::foo2::thread_frame_t*)': > > foo2.cpp:67: error: cannot convert 'flxusr::foo2::_pt6472*' to 'void > > (*)(int)' for argument '2' to 'void (* signal(int, void (*)(int)))(int)' > > compilation terminated due to -Wfatal-errors. [] > > This obviously cannot be cast to "void (*)(int)" as it's a struct. I > > think there's some fancy thing you can do with "callback" and "-->", > > but I haven't figured it out yet. Yeah, nor have I :) First, Felix 'callback' will make C callbacks. However it generates code for the correct type, and the callback function must have a parameter void *client_data for passing the Felix function class closure pointer through. Signal is deprecated anyhow .. don't use it. Instead use the sigaction family of functions: ////////////// man sigaction ////////////////////////// int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); DESCRIPTION The sigaction() system call is used to change the action taken by a process on receipt of a specific signal. struct sigaction { void (*sa_handler)(int); void (*sa_sigaction)(int, siginfo_t *, void *); sigset_t sa_mask; int sa_flags; void (*sa_restorer)(void); } On some architectures a union is involved: do not assign to both sa_handler and sa_sigaction. .... CONFORMING TO POSIX, SVr4. SVr4 does not document the EINTR condition. /////////////////////////////////////////////////// the sa_sigaction member has a void* in it. Second, you need to be dead sure that the Felix function you use is not going to use the garbage collector or whatever. And also that it isn't itself collected when you have it over to the OS. You can examine the code generated by: callback proc sa_sigaction: int * ptr[siginfo_t] * sa_sigaction; What this does is make a C function like: void cback(int, siginfo_t*, felix_proc_type*) { /// code to execute the felix proc goes here } which will accept a Felix procedure of type int * ptr[siginfo_t] Note that the 'sa_sigaction' argument is a placeholder for the callback client data pointer, which will be the pointer to the felix function closure object. The PROBLEM is that this function has type as shown: void cback(int, siginfo_t*, felix_proc_type*) but the specification requires: void cback(int, siginfo_t*, void*) and void* isn't equal to felix_proc_type*. Although you can cast felix_proc_type* to void*, and the specified function will therefore work just fine with a Felix closure pointer, the issue here is the C FUNCTION type. C does not allow any casts at all between function types. There is no legal fix for this problem. There IS an illegal fix on most systems: cast the function pointer type to void* then to the type you want. The problem is Felix doesn't know when to do this. If you model cstruct sigaction { ... sa_sigaction: int * ptr[siginfo_t] * address --> void; ... } it should work, provided you can manage to cast the callback pointer to the right type when assigning to sa_sigaction. Yeah, note the --> here which means sa_sigaction is a C function pointer. -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language