10 messages in com.mysql.lists.ndb-connectorsRe: [Fwd: Re: [Swig-user] C++ wrappin...
FromSent OnAttachments
Monty Taylor07 May 2007 14:52 
Mika Raento07 May 2007 23:37 
Monty Taylor08 May 2007 00:06 
Mika Raento08 May 2007 00:21 
Monty Taylor08 May 2007 00:46 
Mika Raento08 May 2007 00:57 
Mika Raento08 May 2007 01:27 
Mika Raento08 May 2007 01:58 
Mika Raento08 May 2007 03:36 
Monty Taylor08 May 2007 11:05 
Subject:Re: [Fwd: Re: [Swig-user] C++ wrapping question]
From:Mika Raento (mik@iki.fi)
Date:05/08/2007 12:57:59 AM
List:com.mysql.lists.ndb-connectors

Monty Taylor kirjoitti:

Mika Raento wrote:

I'm looking into the target-language option. Basically what is needed to do that is to:

1. in each target language, have a place to stash the extra reference (e.g., a module level hash in perl) 2. shadow startTransaction/asynchPrepare to stash an extra reference to Ndb/Ndb+transaction (NdbOperations are owned by the transaction) 3. shadow close/callback to remove the extra reference

Well, you know, it might be possible at the C level per language, too. In Python, I can call Py_INCREF(ob) where ob is a PyObject*, which increments the ref count. Then it would be easy to place a Py_DECREF(ob) in the transaction->close() method wrapper, since I'm sure you don't mind if the object is reaped when it goes out of scope after calling close.

Sure. I'll look into both options. I need to figure out how to hook into the right places in the C (well, C++) wrapper to take into account SWIG exception handling etc. I was thinking it might be easier in the target language (and I confess I'm not very fluent in the perl C API - the Python API is much more familiar).

Hey - while you're look at the callback stashing, check out the directors version of callbacks. I wasn't able to make a very good test case, so they may actually work. I actually got a segfault, but now I'm thinking maybe this was related to the issue you're talking about here? It requires making a class in Perl that derives from BaseCallback and overrides the callback method. You'll also have to add (directors="1") to the %module statement. BUT - it might offer a nice way to hook in the transaction. Or - maybe it's not very perl-ish. I sort of like your anonymous callback method in async.pl and the fact that it works.

I did have a look. I'd say that deriving from a base class is the way to go for languages that normally do callbacks that way, but callable objects/anonymous subs/closures are the more natural way to do it in perl/Python/other such things. Because of the scoping for anon subs, you can add whatever state you need into them.

Mika