adonthell-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Adonthell-devel] Python instance passing


From: Kai Sterker
Subject: Re: [Adonthell-devel] Python instance passing
Date: Mon, 5 May 2003 11:45:18 +0200

On Mon, 05 May 2003 10:14:44 +0200 Alexandre Courbot wrote:

> Hi everybody,
> 
> Those who follow the diaries know that I've finally (almost) sorted
> out that damn callback stuff. That's finally a good thing, which
> should allow us to switch to the new source tree once it's finalized.

Cool :).

> I have one question though: are we going to keep python::pass_instance
> now that we are using the swig lib which have an equivalent? Trouble
> is, that it works with swig_type_info objects which are obviously not
> available from Adonthell (i.e. it's not as simple as our good old
> pass_instance), but on the other hand it could save some maintainance.
> Kai, since you know the topic better than me, what do you think?

As I said earlier, I'd like to switch to the methods swig provides.
First of all, there is no more need to keep that module dictionary
around. Second, we would no longer depend upon swig internals that may
or may not change again.

As for the "problem" of the missing swig_type_info: that can be easily
retrieved with the SWIG_TypeQuery function. Converted to use swig
functions, our pass_instance method would look as follows:

-[SNIP]-

struct swig_type_info;
extern "C" {
    swig_type_info *SWIG_TypeQuery (const char*);
    PyObject *SWIG_NewPointerObj (void*, swig_type_info*, int);
}

// ...

PyObject *python::pass_instance (void *instance, const char *class_name)
{
    std::string class_ptr = ("_p_") + class_name;
    return SWIG_NewPointerObj (instance,
        SWIG_TypeQuery (class_ptr.c_str ()), 0);
}

-[SNIP]-

Obviously one might want to add some error checking, and it might be
useful to allow setting the owner of the new instance (Python or C/C++).
When passing 0 as last parameter to SWIG_NewPointerObj, it belongs to
C/C++, with 1 it would belong to Python.

Kai




reply via email to

[Prev in Thread] Current Thread [Next in Thread]