[Pythonmac-SIG] Troubles using Boost.Python and Mac types

John C. Daub hsoi at hsoi.com
Tue Aug 7 19:46:08 CEST 2007


Hello.

I've been using Python for a little while and am now embedding it in an
application which is primarily Cocoa based but has a core library that's
written in C++ and uses a lot of Core Foundation. I'm trying to wrap up our
file specifier class using Boost.Python, but am having difficulties in
figuring out how to get Boost.Python to work with types it doesn't
understand, such as a CFStringRef.

My C++ file specifier class is called FSItem, and it's the main class I need
to wrap up. As a sample case, it has a method:

    virtual CFStringRef  CopyAsPath() const;

This will convert the FSItem to a path and return it as a CFStringRef, which
the caller must CFRelease(). When I first created my module I did so like
this:

BOOST_PYTHON_MODULE(Gonzo)
{
    boost::python::class_<Gonzo::FSItem>("FSItem")
        .def("copyaspath", &Gonzo::FSItem::CopyAsPath)
    ;
}

Of course, that generated a compile error that I needed a
return_value_policy<> that understood CFStringRef's.

I've been struggling to come up with the way to make this happen. I need to
convert the CFStringRef to something the script can understand, and I do
know about CFStringRefObj_New() from Python/pymactoolbox.h. And try as I
might to find sample code, documentation, etc. well... while I get some
things, I just can't get over the last hump of exactly how to implement a
ResultConverterGenerator for a CFStringRef.

My questions:

1. Does anyone know how to create a ResultConverterGenerator for a
CFStringRef?

2. What's the API contract regarding CFStringRefObj_New()? Does it assume
ownership of the CFStringRef given to it? The source code seems to do that,
but I want to make sure.

3. I posted here due to the Mac-ness of this all, but as I'm a newbie to
this realm I'm not sure it's the right/best forum. Would the C++ SIG mailing
list be the better place?


Thank you. 

-- 
John C. Daub }:-)>=
<mailto:hsoi at hsoi.com> <http://www.hsoi.com/>
"We live thinking we will never die. We die thinking we had never lived.
Cut it out." -- Jason Becker





More information about the Pythonmac-SIG mailing list