From: Andreas L. <no...@sb...> - 2001-10-21 23:30:36
|
On Mon, 2001-10-22 at 00:24, Eric Bezault wrote: > Andreas Leitner wrote: > > > > Problem fixed. The see code was still looking for EP_EVENT_PARSER, > > whereas it has been renamed to XP_EVENT_PARSER. I have also now > > added code that checks if the class we resolve is actually in the > > system. An exception is raised otherwise. This code is protected > > via an #ifdef and can be enabled by setting ${GOBO_C_DEBUG} before > > executing geant compile in library/xml/impl/expat/spec/c. > > I had a chance to have a look at the C code in > library/xml/impl/expat/spec/c when I tried to > make it work with MSVC++ 6.0 this week, and > personally I don't think that it is a good way > of programming to access the Eiffel routines > from C by name using Cecil. It is no safe (see > the exception raisings that you added), it is > error-prone (see the segfault you got just > because you renamed a class), and it is not > efficient (class names and feature names are > probably searched for in hash tables each time > the corresponding Eiffel routine is to be > called, even if the routine won't change between > two calls. > > A much better solution is to pass the function > pointers of the Eiffel routines from the Eiffel > side to the C side in an initialization routine, > and then the C code has these functions pointers > in global variables once and for all, and there > is no need for Cecil to get them by name anymore. This makes sense. IIRC that dynamic stuff came from Berend. Berend was there any other reason not to use function pointers? > Example: > > In Eiffel code: > > f is > do > ... > end > > g is > do > ... > end > > initialize is > -- Pass function pointers of `f' and > -- `g' to C. > do > c_initialize ($f, $g) > end Ok, we just need to make sure the globals are thread safe. > feature {NONE} -- External > > c_initialize (fp, gp: POINTER) is > -- Pass function pointers of `f' and > -- `g' to C. > external > "C" > end > > In C code: > > EIF_PROCEDURE eif_f, eif_g; > > void c_initialize (EIF_PROCEDURE fp, EIF_PROCEDURE gp) > { > eif_f = fp; > eif_g = gp; > } using something like c_assume_initialize should make this thread safe (if there is a thread issue to begin with - not sure): void c_assure_initialize (EIF_PROCEDURE fp, EIF_PROCEDURE gp) { if (eif_f != null) eif_f = fp; if (eif_g != null) eif_g = gp; } Btw, do you know if procedures can be moved around in ISE? Maybe this sounds like a stupid question, but I really don't know. Meaning do we need to protect the function pointers? Anyway, if Berend has no reason why the other approach doesn't work, I'll convert the code. thanks, Andreas |