David,<br><br>Thanks for responding;&nbsp; I really appreciate it.&nbsp; You cleared up a few things for me,<br>and your suggestions got me half-way there.&nbsp; The converter works now for the member<br>function, but still no luck with the constructor.&nbsp; I'll explain below.&nbsp; 
<br><br>I think there are some good points made here for other boost.python novices like myself, so<br>I want to comment on a few things.&nbsp; Hopefully, folks in the know will correct anything I misstate.<br><br>On 11/10/06, 
<b class="gmail_sendername">David Abrahams</b> &lt;<a href="mailto:dave@boost-consulting.com">dave@boost-consulting.com</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
&quot;Mark Kirk&quot; &lt;<a href="mailto:mklists@gmail.com">mklists@gmail.com</a>&gt; writes:<br>&gt; This Python extension makes its symbols<br>&gt; globally available through a call to sys.setdlopenflags(dl.RTLD_NOW |<br>
&gt; dl.RTLD_GLOBAL).<br><br>That makes everybody's symbols globally available, potentially causing<br>clashes which might be silent ODR violations causing all sorts of<br>havoc.&nbsp;&nbsp;That said, if you control all the C++ names in the system, and use
<br>namespaces carefully, you'll probably be OK.</blockquote><div><br>I should have added that the dlopen flags are reset in the __init__.py after the extension is imported:<br><br>flags = sys.getdlopenflags()<br>sys.setdlopenflags
(dl.RTLD_NOW | dl.RTLD_GLOBAL)<br>import _foo<br># Reset the dlopen flags<br>sys.setdlopenflags(flags)<br>del flags<br><br>This limits the export to just this extension's symbols unless I'm missing something.<br>&nbsp;<br></div>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>&gt; struct foo_from_python<br>&gt; {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; static FOO*&amp; execute(PyObject&amp; p)
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static FOO* a = FooObject_ptr(&amp;p);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^^^^^^<br>hey; what's up with that?<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return a;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt; };</blockquote><div><br>Heh... yeah, that was pretty bogus, but I was hacking around the compiler being upset
<br>about initializing a reference from a temporary (even though it would have been valid after<br>the function call ended).&nbsp; I thought I'd get rid of that &quot;static&quot; cheat later if I could make other<br>things work.&nbsp; 
<br><br>Late Friday afternoon before I saw your mail, a colleague who had been looking at this<br>with me came up with a refinement that worked for converting FOO* in member functions<br>(not constructors):<br><br>struct foo_from_python
<br>{<br>&nbsp;&nbsp;&nbsp; static FOO&amp; execute(PyObject&amp; p)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return *(FooObject_ptr(&amp;p));<br>&nbsp;&nbsp;&nbsp; }<br>};<br><br>BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(FOO);<br>lvalue_from_pytype&lt;foo_from_python, &amp;FooObject_Type&gt;();&nbsp;
</div><br>He used the BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID macro to obviate the<br>need to include the foo_internal.h header.<br><br><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Don't try to convert to pointers; there are no pointers in<br>Boost.Python; only lvalues and rvalues ;-)<br><br>&nbsp;&nbsp;void* extract_foo(PyObject* op)<br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return FooObject_ptr(op);<br>&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;boost::python::converter::registry::insert(
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;extractor_foo, boost::python::type_id&lt;FOO&gt;());</blockquote><div><br>Friday night I saw your mail, which *really* cleared up a few things -- not to try <br>converting pointers being the most important.&nbsp; Like a lot of programmers, I'm afraid
<br>I suffer from an incomplete understanding of lvalue and rvalue.&nbsp; They have a history<br>of ambiguity.&nbsp; I'd considered a pointer variable to be an lvalue since you can assign to<br>it (even though it's holding an address).&nbsp; Thanks for enlightening me.&nbsp; I needed it.
<br><br>With your suggested solution, I could get rid of foo_Internal.h using the opaque specialized type_id macro<br>as above.&nbsp; I believe that macro simply examines the tp_name field in a PyTypeObject rather than using<br>
C++ typeid() (which is wrapped by boost::python::type_id()).&nbsp; Is this an acceptable way to do this since I <br>shouldn't really use foo_internal.h?&nbsp; <br><br>Unfortunately, I'm still unable to get the constructor to work.&nbsp; I get compiler errors from 
boost.python, but,<br>after looking through the boost.python source, I'm still stumped.&nbsp; My metaprogramming fu is just not<br>there.&nbsp; I'm reluctant to post the complete errors here (but I'm happy if someone is up for it),
<br>so here's an abbreviated version of the chain of five errors:<br><br>---------------------<br>sys_include/boost/python/def_visitor.hpp: In static member function `static void boost::python::def_visitor_access::visit(const V&amp;, classT&amp;, const char*, const OptionalArgs&amp;) [with V = boost::python::def_visitor&lt;boost::python::init&lt;ANI*, mpl_::void_, mpl_::void_, (many more mpl_::void_ params, most other params are boost::detail::not_specified)':
<br><br>sys_include/boost/python/def_visitor.hpp:74:&nbsp;&nbsp; instantiated from `void boost::python::def_visitor&lt;DerivedVisitor&gt;::visit(classT&amp;, const char*, const OptionalArgs&amp;) const [with classT = boost::python::class_&lt;bpani, boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified&gt;, OptionalArgs = boost::python::detail::def_helper&lt;const char*, ... 
<br><br>sys_include/boost/python/class.hpp:481:&nbsp;&nbsp; instantiated from `void boost::python::class_&lt;T, X1, X2, X3&gt;::def_impl(T*, const char*, LeafVisitor, const Helper&amp;, const boost::python::def_visitor&lt;Visitor&gt;*) [with T = bpani, Helper = boost::python::detail::def_helper&lt;const char*, boost::python::detail::not_specified, boost::python::detail::not_specified, boost::python::detail::not_specified&gt;, LeafVisitor = boost::python::init&lt;ANI*, mpl_::void_, mpl_::void_,&nbsp; ...
<br><br>sys_include/boost/python/class.hpp:235:&nbsp;&nbsp; instantiated from `boost::python::class_&lt;T, X1, X2, X3&gt;&amp; boost::python::class_&lt;T, X1, X2, X3&gt;::def(const char*, F) [with F = boost::python::init&lt;ANI*, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_&gt;, W = bpani, X1 = boost::python::detail::not_specified, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]'
<br><br>lib/bpfoo/python/pybpfoo.cc:39:&nbsp;&nbsp; instantiated from here<br>sys_include/boost/python/def_visitor.hpp:43: error: no matching function for call to `boost::python::init&lt;ANI*, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, ...
<br>---------------------<br><br>OK, that's still a lot;&nbsp; sorry about that.&nbsp; Again, David if you or anyone has an idea how I can get past this,<br>I'd really appreciate it.&nbsp; Feels like it's close.&nbsp; <br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Well, it's my fault for never making the converter registration<br>interface truly public and documenting it.&nbsp;&nbsp;Sorry about that.</blockquote><div><br>Ha!&nbsp; Well, yeah, that would have made things easier I suppose, but I'm just grateful 
<br>for having boost.python at all.&nbsp; It's made wrapping C++ libs extremely efficient.&nbsp; Unfortunately,<br>this particular problem has become a show-stopper for me.&nbsp; Many of my colleagues will likely<br>need to do this eventually, so we must solve it somehow or come up with another way to 
<br>wrap many of our libs (which would be a drag).<br><br>thanks,<br>mark<br><br></div><br></div>