List:NDB Connectors« Previous MessageNext Message »
From:Mika Raento Date:May 8 2007 7:58am
Subject:Re: [Fwd: Re: [Swig-user] C++ wrapping question]
View as plain text  
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
Thread
[Fwd: Re: [Swig-user] C++ wrapping question]Monty Taylor7 May
  • Re: [Fwd: Re: [Swig-user] C++ wrapping question]Mika Raento8 May
    • Re: [Fwd: Re: [Swig-user] C++ wrapping question]Monty Taylor8 May
      • Re: [Fwd: Re: [Swig-user] C++ wrapping question]Mika Raento8 May
        • Re: [Fwd: Re: [Swig-user] C++ wrapping question]Monty Taylor8 May
          • Re: [Fwd: Re: [Swig-user] C++ wrapping question]Mika Raento8 May
            • Re: [Fwd: Re: [Swig-user] C++ wrapping question]Mika Raento8 May
              • Re: [Fwd: Re: [Swig-user] C++ wrapping question]Mika Raento8 May
          • compilation fails from bzrMika Raento8 May
            • Re: compilation fails from bzrMonty Taylor8 May