Help with converters ...

View: New views
3 Messages — Rating Filter:   Alert me  

Help with converters ...

by Michele De Stefano :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello to everyone.

I'm stuck with this problem. I'm trying to write a "from Python
converter", from a tuple(tuple,tuple) type to C++.
Clarifying more, the Python type is a tuple, containing 2 tuples.

Now, when I try to implement the "convertible" static member function
of the converter class, I write this (I've extracted only the
interesting part):

static void* convertible(PyObject* obj_ptr) {
               
        using namespace boost::python;

        handle<> hndl(borrowed(obj_ptr));
        object in(hndl);
               
        if (!PyTuple_Check(in.ptr())) return NULL;
               
        extract<const tuple&>
             get_tup0(in[0]),
             get_tup1(in[1]);
               
        bool
             t1 = get_tup0.check(),
             t2 = get_tup1.check();

...... the rest of the code is not necessary ....


The problem is that even if I pass a tuple containing two tuples from
Python, t1 and t2 become "false".
Surely I'm not interfacing properly with Python, but I don't understand why.

Can someone help me to understand ?

Thank you in advance.
Michele


--
Michele De Stefano
http://www.linkedin.com/in/micdestefano
http://xoomer.virgilio.it/michele_de_stefano
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig

Re: Help with converters ...

by Hans Meine-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Michele!

On Montag 19 Oktober 2009, Michele De Stefano wrote:
> Now, when I try to implement the "convertible" static member function
> of the converter class, I write this (I've extracted only the
> interesting part):
>
> [...]
> extract<const tuple&>
>              get_tup0(in[0]),
>              get_tup1(in[1]);

This looks like the problem to me; you're effectively trying to get a
*reference* from python, i.e. this can only work if there is already an
*existing* boost::python::tuple object hidden in (in[0]) and (in[1]).
(This will typically only work with BPL-exported C++ objects wrapped into
their python shells.)

I'd try simply removing the const &: extract<tuple>..

--
Ciao, /  /                                                    .o.
     /--/                                                     ..o
    /  / ANS                                                  ooo


_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig

signature.asc (204 bytes) Download Attachment

Re: Help with converters ...

by Michele De Stefano :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hans,

thank you very much. Removing the substituting "const tuple&" with
"tuple" works.

Just to let me understand more your answer, what does it mean "BPL-exported" ?
I'm not so comfortable with acronyms ...


2009/10/19 Hans Meine <hans_meine@...>:

> Hi Michele!
>
> On Montag 19 Oktober 2009, Michele De Stefano wrote:
>> Now, when I try to implement the "convertible" static member function
>> of the converter class, I write this (I've extracted only the
>> interesting part):
>>
>> [...]
>>       extract<const tuple&>
>>              get_tup0(in[0]),
>>              get_tup1(in[1]);
>
> This looks like the problem to me; you're effectively trying to get a
> *reference* from python, i.e. this can only work if there is already an
> *existing* boost::python::tuple object hidden in (in[0]) and (in[1]).
> (This will typically only work with BPL-exported C++ objects wrapped into
> their python shells.)
>
> I'd try simply removing the const &: extract<tuple>..
>
> --
> Ciao, /  /                                                    .o.
>     /--/                                                     ..o
>    /  / ANS                                                  ooo
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig@...
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>



--
Michele De Stefano
http://www.linkedin.com/in/micdestefano
http://xoomer.virgilio.it/michele_de_stefano
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@...
http://mail.python.org/mailman/listinfo/cplusplus-sig