[C++-sig] Re: wrapping function taking pointer to pointer

Jason.Sibthorpe at aculab.com Jason.Sibthorpe at aculab.com
Fri Sep 12 16:58:55 CEST 2003


Thanks!

>A list of what?  is ptrptr expected to be able to change the char*s
>that the char** points to?  Is it expected to be able to change the
>chars that those char*s point to?  What result would you like to see
>in Python if it does?
mmm... sorry for the vague problem description


>There are no docs for your particular problem.  At the moment, there
>isn't even a way to write a converter which would use the above
>conversion any time a function accepting a char** was called.

Is it due to insurmountable technical issues, or lack of time, or 
priorities, or a combination thereof?  

It seems to me that this sort of thing (automatic conversion) is quite 
desirable.

Thanks again for your help.

-Jason

-----Original Message-----
From: David Abrahams [mailto:dave at boost-consulting.com]
Sent: 12 September 2003 14:26
To: c++-sig at python.org
Subject: [C++-sig] Re: wrapping function taking pointer to pointer


jason sibthorpe <j8sn at yahoo.com> writes:

>>> Hi all,
>>>
>>> Could someone point me towards the documentation
> (if any exists)
>>> for wrapping a function taking a pointer to a
> pointer to some
>>> type.
>>>
>>> void ptrptr(char **in)
>>> {}
>>>
>>> BOOST_PYTHON_MODULE(test)
>>> {
>>>     def("ptrptr", &ptrptr);
>>> }
>>
>>There's no one way to do this.
>>
>>> When calling the function from python I get the
> following
>>>
>>> <snip>
>>> did not match C++ signature:
>>>     inptrptr(char**)
>>
>>What kind of Python object do you *expect* to be able
> to pass to
>>inptrptr?
>>
>>-- 
>>Dave Abrahams
>>Boost Consulting
>>www.boost-consulting.com
>
>
> Hi Dave,
>
> Thanks for responding.
>
> I am interested in understanding the process rather
> than dealing with a single type 

Errh.  The process is complicated.  You can read a little about it at
http://www.boost-consulting.com/boost/libs/python/doc/internals.html

> but, for the purposes of this discussion, the c++ type is char** and
> I would think that a python list do the trick.

A list of what?  is ptrptr expected to be able to change the char*s
that the char** points to?  Is it expected to be able to change the
chars that those char*s point to?  What result would you like to see
in Python if it does?

I am guessing that you want to convert a list of strings to a
zero-terminated array of char*s?

The easy way to do that is to write a thin wrapper over ptrptr as
in:

        void ptrptr_wrap(list strings)
        {
            std::size_t const length = extract<std::size_t>(
                strings.attr("__len__")());

            boost::shared_array<char*> in(new char*[length + 1]);
            for (std::size_t i = 0; i < length; ++i)
            {
                in[i] = const_cast<char*>(
                    extract<char const*>(strings[i])());
            }
            in[length] = 0;

            ptrptr(in.get());
        };

> A doco* would be greatly appreciated.

There are no docs for your particular problem.  At the moment, there
isn't even a way to write a converter which would use the above
conversion any time a function accepting a char** was called.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com


_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig




More information about the Cplusplus-sig mailing list