Re: Tutorial: adapted API parts
[email protected] (Joshua N Pritikin)
| Newsgroups | perl.loop |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Dec 04, 2000 at 10:38:09PM +0100, [email protected] wrote: > >For what it's worth, we could make the APIs *appear* the same. > > That's what I meant - just simplifying the interface by making it more > general. > > >However, > >the programmer still needs to decide how the callback will be invoked. i > >don't think it makes sense to autogenerate *both* styles (XS & C) > >implicitly without asking. And it certainly doesn't make sense to adapt > >at run-time by detecting the caller (somehow). Am i missing something? > > Please see the "Perl watcher, C callback" chapter. There's a function > c_callback() used as a Perl invoked watcher callback. The interface is, > as usual (and thanks to Inline): > > void c_callback(pe_event * event) > > I just read C code produced by Inline and found that - correct me if > I'm wrong - it just builds a wrapper around a C function. Oh! Indeed it does. Hm hm. > Somewhere in > the wrapper, the "original" function is called. So we have the wrapper > (to invoke the callback from Perl) and *still* the callback function as > it > was written by the application programmer. > > Now let's assume I want to have the same callback functionality for a > watcher initialized on *C* side. (Whether this makes sense or not - it > could be different scripts and I might want to reuse C callback code > unchanged which was already tested successfully.) > > *If* the C invokation interface would be the same > > void c_callback(pe_event * event) > > , an application programmer could invoke just this same callback - from > C side now. The difference is that no intermediate translation wrapper > is called *but this is done behind the scenes*. I'm calling the > "original function" in C just as the wrapper function does. For the > application programmer who just has to write the callback code this is > not too important, isn't it? I currently think it is not, because there > is no further difference between the callback types except of the > interface. (Maybe I missed something?) > > Well, the wrapper would still be there (unless someone declares the > callback as static). Is this expensive? (Real question, no rhetorics!) > As I understand it at the moment, the wrapper would be automatically > invoked if the callback is called on Perl side, and passed by if the > caller resides on the C shore. OK. Does anyone oppose changing the C callback from: (* (void(*)(void*,pe_event*)) ev->callback)(ev->ext_data, ev); To: (* (void(*)(pe_event*,void*)) ev->callback)(ev, ev->ext_data); ? -- May the best description of competition prevail. (via, but not speaking for Deutsche Bank)