RE: Matt Lewis! Help! (was RE: Wrapping C - Callback troubles)

new topic     » topic index » view thread      » older message » newer message

Andy Serpa wrote:
> 
> Andy Serpa wrote:
> > 
> > Bernie Ryan wrote:
> > > 
> > > Andy Serpa wrote:
> > > > Here's another problem.  I'm making the Berkeley DB wrapper which allows
> > > >
> > > > 
> > > > 
> > > > for certain callback functions to be used.  One particular one I'm 
> > > > trying to set up is supposed to be a void function.  The callback works 
> > > > (my function is called), but when it returns a value (any value) it 
> > > > crashes.  (Callback functions are required to return something.)  Is 
> > > 
> > > Andy:
> > > 
> > >   When you are having troble with "C" always post
> > >   the complete "C" declaration to the list so that way
> > >   maybe someone can help you deciper what you are
> > >   trying to wrap.
> > > 
> > 
> > Well, here is the particular function in question that SETS the callback 
> > 
> > 
> > function:
> > 
> > void
> > DB->set_errcall(DB *,
> >     void (*db_errcall_fcn)(const char *errpfx, char *msg));
> > 
> > Pretty straightforward -- I give it a DB handle (previously created) and 
> > 
> > 
> > a callback address for my routine which takes two args.
> > 
> > 
> > But that's not the problem.  Setting the callback function is no 
> > problem, and my Euphoria function is being called with the correct args. 
> > 
> > 
> >  The problem is when my function exits (returns a value) the whole thing 
> > crashes with an exception.  I was just wondering is that because it is a 
> > 
> > 
> > supposed to be void function?  (It seems like I should be able to return 
> > 
> > 
> > anything in that case, but maybe it wants me to return nothing?)  
> > Anybody know anything about that?
> > 
> > There are some other callbacks you can set that do take return values.  
> > I'm gonna try those and see if that works...
> > 
> > 
> > If anyone is interested, the entire docs for the library I'm wrapping 
> > are at:
> > 
> > http://www.sleepycat.com/docs/index.html
> > 
> > 
> Ok, here's what I've discovered:
> 
> A) The .dll library is calling my routines via cdecl, so I'm using Matt 
> Lewis' fptr.e to set up the callbacks (as well as for every other damn 
> call in the whole wrapper -- thank you Matt Lewis.)
> 
> B) I set-up a different callback function that does take a return value, 
> 
> and it works fine.  The funny thing about that is that it takes two 
> parameters, but they show up as parameters 2 & 3 instead of 1 & 2.  In 
> other words, in order to get this function to work I had to define it 
> with 3 parameters instead of two (via new_pfunc_cdecl).  When peeking 
> parameter 1 it always equals 0.  (You peek the args when using fptr.e 
> for this stuff.)
> 
> C) My other callback function -- the one that crashes -- is supposed to 
> be a void function taking two parameters.  In that one, the parameters 
> *do* show up as parameters 1 & 2.  (I tried declaring an extra one 
> anyway, still crashes.)
> 
> 
> I don't know ANYTHING about this stuff, but my tentative theory is that 
> the place where parameter 1 goes in a cdecl call is for the return 
> value, and since the void function doesn't need a return value, then 
> that space isn't there?
> 
> The crashes are all invalid page faults, by the way.
> 
> 
> So getting back to my problem -- is all this trouble caused by the fact 
> that the function is supposed to be void and it is trying to return a 
> value?  And is there any way around it?
> 
> 

Ok, here's what I've further discovered:

A) I was wrong about the function having the parameters in the wrong 
place -- that function does in fact take 3 parameters, not 2.  The first 
one just is not used and it wasn't clear in the docs.  So that means all 
parameters do appear to show up in their correct places.

B) I set up some other callback functions, some which are void and some 
which return values.  One of the void ones works, and one of the others 
that returns a value always crashes.  So I guess it is not the "void" 
thing that is the problem. (If I don't use cdecl they all always crash.)

So, I've got a number of callback functions all defined via fptr.e and 
new_pfunc_cdecl.  Some always work, some always crash on exit, and there 
doesn't seem to be any commonality between those that crash and those 
that don't.  So I'm thinking that maybe the ASM function in fptr.e that 
handles all this isn't quite right, but I really have no idea?  Matt?

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu