diff --git a/doc/enums.html b/doc/enums.html index 32d61447..03b663ac 100644 --- a/doc/enums.html +++ b/doc/enums.html @@ -75,7 +75,7 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround from_python(x, boost::python::type<long>())); } - PyObject* to_python(MyEnumType x) + PyObject* to_python(boost::python::semantics, MyEnumType x) { return to_python(static_cast<long>(x)); } @@ -91,8 +91,8 @@ initialization. These bind the corresponding enum values to the appropriate names so they can be used from Python:
-mymodule.add(boost::python::to_python(enum_value_1), "enum_value_1");
-mymodule.add(boost::python::to_python(enum_value_2), "enum_value_2");
+mymodule.add(boost::python::to_python(boost::python::search_namespace, enum_value_1), "enum_value_1");
+mymodule.add(boost::python::to_python(boost::python::search_namespace, enum_value_2), "enum_value_2");
 ...
 
@@ -100,8 +100,8 @@ You can also add these to an extension class definition, if your enum happens to be local to a class and you want the analogous interface in Python:
-my_class_builder.add(boost::python::to_python(enum_value_1), "enum_value_1");
-my_class_builder.add(boost::python::to_python(enum_value_2), "enum_value_2");
+my_class_builder.add(boost::python::to_python(boost::python::search_namespace, enum_value_1), "enum_value_1");
+my_class_builder.add(boost::python::to_python(boost::python::search_namespace, enum_value_2), "enum_value_2");
 ...
 

diff --git a/doc/pointers.html b/doc/pointers.html index fdbee797..1440bbd1 100644 --- a/doc/pointers.html +++ b/doc/pointers.html @@ -65,9 +65,9 @@ wrapped T, you may want to provide an automatic thin wrappers. You can do this simply as follows:

-BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround
-  PyObject* to_python(const Foo* p) {
-     return to_python(*p); // convert const Foo* in terms of const Foo&
+BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is an MSVC / gcc 2.95.2 bug workaround
+  PyObject* to_python(boost::python::semantics, const Foo* p) {
+     return to_python(boost::python::search_namespace, *p); // convert const Foo* in terms of const Foo&
   }
 BOOST_PYTHON_END_CONVERSION_NAMESPACE
 
@@ -83,12 +83,12 @@ code before the last Python reference to it disappears:
 BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround
-  PyObject* to_python(Foo* p)
+  PyObject* to_python(boost::python::semantics, Foo* p)
   {
       return boost::python::python_extension_class_converters<Foo>::ptr_to_python(p);
   }
 
-  PyObject* to_python(const Foo* p)
+  PyObject* to_python(boost::python::semantics, const Foo* p)
   {
       return to_python(const_cast<Foo*>(p));
   }
diff --git a/doc/special.html b/doc/special.html
index 0caa1924..b928210d 100644
--- a/doc/special.html
+++ b/doc/special.html
@@ -699,7 +699,7 @@ void throw_key_error_if_end(
 {
     if (p == m.end())
     {
-        PyErr_SetObject(PyExc_KeyError, boost::python::converters::to_python(key));
+        PyErr_SetObject(PyExc_KeyError, to_python(boost::python::search_namespace, key));
         throw boost::python::error_already_set();
     }
 }
diff --git a/doc/under-the-hood.html b/doc/under-the-hood.html
index 733f0f54..f676fbb0 100644
--- a/doc/under-the-hood.html
+++ b/doc/under-the-hood.html
@@ -27,7 +27,7 @@
       provide an argument list
       because they can't be named in C++). Then, it calls the appropriate
       overloaded functions PyObject*
-      to_python(S) and 
+      to_python(boost::python::semantics, S) and 
       S'from_python(PyObject*,
       type<S>) which convert between any C++
       type S and a PyObject*, the type which represents a
diff --git a/example/do_it_yourself_converters.cpp b/example/do_it_yourself_converters.cpp
index 6d2d2d6a..064f2f0c 100644
--- a/example/do_it_yourself_converters.cpp
+++ b/example/do_it_yourself_converters.cpp
@@ -95,11 +95,11 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
 
   // Convert a MillerIndex object to a Python tuple.
   //
-  PyObject* to_python(const MillerIndex& hkl)
+  PyObject* to_python(python::semantics, const MillerIndex& hkl)
   {
     python::tuple result(3);
     for (int i = 0; i < 3; i++)
-      result.set_item(i, python::ref(to_python(hkl.v[i])));
+      result.set_item(i, hkl.v[i]);
     return result.reference().release();
   }
 
diff --git a/example/dvect.h b/example/dvect.h
index 8ffe7b50..21351572 100644
--- a/example/dvect.h
+++ b/example/dvect.h
@@ -14,16 +14,14 @@ namespace vects {
     {
       std::vector::iterator v_it = begin();
       for (int i = 0; i < tuple.size(); i++)
-        v_it[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
-          boost::python::type());
+        v_it[i] = from_python(tuple[i].get(), boost::python::type());
     }
 
     boost::python::tuple as_tuple() const
     {
       boost::python::tuple t(size());
       for (int i = 0; i < size(); i++)
-        t.set_item(i,
-          boost::python::ref(BOOST_PYTHON_CONVERSION::to_python((*this)[i])));
+        t.set_item(i, (*this)[i]);
       return t;
     }
   };
diff --git a/example/ivect.h b/example/ivect.h
index a0187307..3e025e4c 100644
--- a/example/ivect.h
+++ b/example/ivect.h
@@ -14,16 +14,14 @@ namespace vects {
     {
       std::vector::iterator v_it = begin();
       for (int i = 0; i < tuple.size(); i++)
-        v_it[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
-          boost::python::type());
+        v_it[i] = from_python(tuple[i].get(), boost::python::type());
     }
 
     boost::python::tuple as_tuple() const
     {
       boost::python::tuple t(size());
       for (int i = 0; i < size(); i++)
-        t.set_item(i,
-          boost::python::ref(BOOST_PYTHON_CONVERSION::to_python((*this)[i])));
+          t.set_item(i, (*this)[i]);
       return t;
     }
   };
diff --git a/example/pickle2.cpp b/example/pickle2.cpp
index d6aa3201..269fc190 100644
--- a/example/pickle2.cpp
+++ b/example/pickle2.cpp
@@ -45,8 +45,6 @@ namespace { // Avoid cluttering the global namespace.
 
   // Support for pickle.
 
-  using BOOST_PYTHON_CONVERSION::from_python;
-
   python::ref world_getinitargs(const world& w) {
       python::tuple result(1);
       result.set_item(0, w.get_country());
diff --git a/example/pickle3.cpp b/example/pickle3.cpp
index bfa7dc54..53054ea6 100644
--- a/example/pickle3.cpp
+++ b/example/pickle3.cpp
@@ -94,7 +94,6 @@ BOOST_PYTHON_MODULE_INIT(pickle3)
 
 namespace {
 
-  using BOOST_PYTHON_CONVERSION::from_python;
   using boost::python::type;
   using boost::python::ref;
   using boost::python::tuple;
diff --git a/example/simple_vector.cpp b/example/simple_vector.cpp
index 2b3aa290..67c06c6d 100644
--- a/example/simple_vector.cpp
+++ b/example/simple_vector.cpp
@@ -25,8 +25,7 @@ namespace { // Avoid cluttering the global namespace.
     {
       std::vector::iterator vd = begin();
       for (int i = 0; i < tuple.size(); i++)
-        vd[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
-          python::type());
+        vd[i] = from_python(tuple[i].get(), python::type());
     }
   };
 
@@ -57,8 +56,8 @@ namespace { // Avoid cluttering the global namespace.
   python::tuple as_tuple(const std::vector& vd)
   {
     python::tuple t(vd.size());
-    for (int i = 0; i < vd.size(); i++) t.set_item(i,
-      python::ref(BOOST_PYTHON_CONVERSION::to_python(vd[i])));
+    for (int i = 0; i < vd.size(); i++)
+        t.set_item(i, vd[i]);
     return t;
   }
 
diff --git a/include/boost/python/class_builder.hpp b/include/boost/python/class_builder.hpp
index 4a9ec1b2..a4ed33e9 100644
--- a/include/boost/python/class_builder.hpp
+++ b/include/boost/python/class_builder.hpp
@@ -19,117 +19,118 @@ class class_builder
     : python_extension_class_converters // Works around MSVC6.x/GCC2.95.2 bug described below
 {
  public:
+    /// Construct a class named name in the given module
     class_builder(module_builder& module, const char* name)
         : m_class(new detail::extension_class(name))
     {
         module.add(ref(as_object(m_class.get()), ref::increment_count), name);
     }
-    
-    ~class_builder()
-    {}
 
+    /// Tell Boost.Python that for the purposes of pickling, the state is
+    /// completely captured in the object's __dict__.
     inline void dict_defines_state() {
-      add(ref(BOOST_PYTHON_CONVERSION::to_python(1)), "__dict_defines_state__");
-    }
-    inline void getstate_manages_dict() {
-      add(ref(BOOST_PYTHON_CONVERSION::to_python(1)), "__getstate_manages_dict__");
+      add(ref(to_python(search_namespace, 1)), "__dict_defines_state__");
     }
     
-    // define constructors
+    inline void getstate_manages_dict() {
+      add(ref(to_python(search_namespace, 1)), "__getstate_manages_dict__");
+    }
+    
+    /// define constructors
     template 
     void def(const signature& s)
         { m_class->def(s); }
 
-    // export heterogeneous reverse-argument operators 
-    // (type of lhs: 'left', of rhs: 'right')
-    // usage:  foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
-    //                       boost::python::left_operand());
+    /// export heterogeneous reverse-argument operators 
+    /// (type of lhs: 'left', of rhs: 'right')
+    /// usage:  foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
+    ///                       boost::python::left_operand());
     template 
     void def(operators o1, left_operand o2)
         { m_class->def(o1, o2); }
 
-    // export heterogeneous operators (type of lhs: 'left', of rhs: 'right')
-    // usage:  foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
-    //                       boost::python::right_operand());
+    /// export heterogeneous operators (type of lhs: 'left', of rhs: 'right')
+    /// usage:  foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
+    ///                       boost::python::right_operand());
     template 
     void def(operators o1, right_operand o2)
         { m_class->def(o1, o2); }
 
-    // define a function that passes Python arguments and keywords
-    // to C++ verbatim (as a 'tuple const &' and 'dictionary const &' 
-    // respectively). This is useful for manual argument passing.
-    // It's also the only possibility to pass keyword arguments to C++.
-    // Fn must have a signatur that is compatible to 
-    //     PyObject * (*)(PyObject * aTuple, PyObject * aDictionary)
+    /// define a function that passes Python arguments and keywords
+    /// to C++ verbatim (as a 'tuple const &' and 'dictionary const &' 
+    /// respectively). This is useful for manual argument passing.
+    /// It's also the only way to pass keyword arguments to C++.
+    /// Fn must have a signature that is compatible with
+    ///     PyObject * (*)(PyObject * aTuple, PyObject * aDictionary)
     template 
     void def_raw(Fn fn, const char* name)
         { m_class->def_raw(fn, name); }
 
-    // define member functions. In fact this works for free functions, too -
-    // they act like static member functions, or if they start with the
-    // appropriate self argument (as a pointer or reference), they can be used
-    // just like ordinary member functions -- just like Python!
+    /// define member functions. In fact this works for free functions, too -
+    /// they act like static member functions, or if they start with the
+    /// appropriate self argument (as a pointer or reference), they can be used
+    /// just like ordinary member functions -- just like Python!
     template 
     void def(Fn fn, const char* name)
         { m_class->def(fn, name); }
 
-    // Define a virtual member function with a default implementation.
-    // default_fn should be a function which provides the default implementation.
-    // Be careful that default_fn does not in fact call fn virtually!
+    /// Define a virtual member function with a default implementation.
+    /// default_fn should be a function which provides the default implementation.
+    /// Be careful that default_fn does not in fact call fn virtually!
     template 
     void def(Fn fn, const char* name, DefaultFn default_fn)
         { m_class->def(fn, name, default_fn); }
 
-    // Provide a function which implements x., reading from the given
-    // member (pm) of the T obj
+    /// Provide a function which implements x., reading from the given
+    /// member (pm) of the T obj
     template 
     void def_getter(MemberType T::*pm, const char* name)
         { m_class->def_getter(pm, name); }
     
-    // Provide a function which implements assignment to x., writing to
-    // the given member (pm) of the T obj
+    /// Provide a function which implements assignment to x., writing to
+    /// the given member (pm) of the T obj
     template 
     void def_setter(MemberType T::*pm, const char* name)
         { m_class->def_getter(pm, name); }
     
-    // Expose the given member (pm) of the T obj as a read-only attribute
+    /// Expose the given member (pm) of the T obj as a read-only attribute
     template 
     void def_readonly(MemberType T::*pm, const char* name)
         { m_class->def_readonly(pm, name); }
     
-    // Expose the given member (pm) of the T obj as a read/write attribute
+    /// Expose the given member (pm) of the T obj as a read/write attribute
     template 
     void def_read_write(MemberType T::*pm, const char* name)
         { m_class->def_read_write(pm, name); }
         
-    // define the standard coercion needed for operator overloading
+    /// define the standard coercion needed for operator overloading
     void def_standard_coerce()
         { m_class->def_standard_coerce(); }
     
-    // declare the given class a base class of this one and register 
-    // conversion functions
+    /// declare the given class a base class of this one and register 
+    /// conversion functions
     template 
     void declare_base(class_builder const & base)
     {
         m_class->declare_base(base.get_extension_class());
     }
 
-    // declare the given class a base class of this one and register 
-    // upcast conversion function
+    /// declare the given class a base class of this one and register 
+    /// upcast conversion function
     template 
     void declare_base(class_builder const & base, without_downcast_t)
     {
         m_class->declare_base(base.get_extension_class(), without_downcast);
     }
 
-    // get the embedded ExtensioClass object
+    /// get the embedded ExtensioClass object
     detail::extension_class * get_extension_class() const 
     {
         return m_class.get();
     }
 
-    // set an arbitrary attribute. Useful for non-function class data members,
-    // e.g. enums
+    /// set an arbitrary attribute. Useful for non-function class data members,
+    /// e.g. enums
     void add(PyObject* x, const char* name)
         { m_class->set_attribute(name, x); }
     void add(ref x, const char* name)
@@ -143,8 +144,8 @@ class class_builder
         m_class->declare_base(base);
     }
         
-    // declare the given class a base class of this one and register 
-    // upcast conversion function
+    /// declare the given class a base class of this one and register 
+    /// upcast conversion function
     template 
     void declare_base(detail::extension_class * base, without_downcast_t)
     {
diff --git a/include/boost/python/classes.hpp b/include/boost/python/classes.hpp
index d38fbba5..688b0bef 100644
--- a/include/boost/python/classes.hpp
+++ b/include/boost/python/classes.hpp
@@ -284,14 +284,14 @@ PyObject* class_t::instance_mapping_subscript(PyObject* obj, PyObject* key) c
 template 
 PyObject* class_t::instance_sequence_item(PyObject* obj, int n) const
 {
-    ref key(to_python(n));
+    ref key(to_python(search_namespace, n));
     return downcast(obj)->get_subscript(key.get());
 }
 
 template 
 int class_t::instance_sequence_ass_item(PyObject* obj, int n, PyObject* value) const
 {
-    ref key(to_python(n));
+    ref key(to_python(search_namespace, n));
     downcast(obj)->set_subscript(key.get(), value);
     return 0;
 }
diff --git a/include/boost/python/conversions.hpp b/include/boost/python/conversions.hpp
index 47f80989..cf102aea 100644
--- a/include/boost/python/conversions.hpp
+++ b/include/boost/python/conversions.hpp
@@ -52,9 +52,9 @@ class py_enum_as_int_converters
             from_python(x, boost::python::type()));
     }
 
-    friend PyObject* to_python(EnumType x)
+    friend PyObject* to_python(boost::python::semantics, EnumType x)
     {
-        return to_python(static_cast(x));
+        return to_python(boost::python::search_namespace, static_cast(x));
     }
 };
 BOOST_PYTHON_END_CONVERSION_NAMESPACE
@@ -116,70 +116,70 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
 //
 // Converters
 //
-PyObject* to_python(long);
+PyObject* to_python(boost::python::search_namespace, long);
 long from_python(PyObject* p, boost::python::type);
 long from_python(PyObject* p, boost::python::type);
 
-PyObject* to_python(unsigned long);
+PyObject* to_python(boost::python::search_namespace, unsigned long);
 unsigned long from_python(PyObject* p, boost::python::type);
 unsigned long from_python(PyObject* p, boost::python::type);
 
-PyObject* to_python(int);
+PyObject* to_python(boost::python::search_namespace, int);
 int from_python(PyObject*, boost::python::type);
 int from_python(PyObject*, boost::python::type);
     
-PyObject* to_python(unsigned int);
+PyObject* to_python(boost::python::search_namespace, unsigned int);
 unsigned int from_python(PyObject*, boost::python::type);
 unsigned int from_python(PyObject*, boost::python::type);
 
-PyObject* to_python(short);
+PyObject* to_python(boost::python::search_namespace, short);
 short from_python(PyObject*, boost::python::type);
 short from_python(PyObject*, boost::python::type);
     
-PyObject* to_python(unsigned short);
+PyObject* to_python(boost::python::search_namespace, unsigned short);
 unsigned short from_python(PyObject*, boost::python::type);
 unsigned short from_python(PyObject*, boost::python::type);
 
-PyObject* to_python(char);
+PyObject* to_python(boost::python::search_namespace, char);
 char from_python(PyObject*, boost::python::type);
 char from_python(PyObject*, boost::python::type);
 
-PyObject* to_python(signed char);
+PyObject* to_python(boost::python::search_namespace, signed char);
 signed char from_python(PyObject*, boost::python::type);
 signed char from_python(PyObject*, boost::python::type);
 
-PyObject* to_python(unsigned char);
+PyObject* to_python(boost::python::search_namespace, unsigned char);
 unsigned char from_python(PyObject*, boost::python::type);
 unsigned char from_python(PyObject*, boost::python::type);
 
-PyObject* to_python(float);
+PyObject* to_python(boost::python::search_namespace, float);
 float from_python(PyObject*, boost::python::type);
 float from_python(PyObject*, boost::python::type);
     
-PyObject* to_python(double);
+PyObject* to_python(boost::python::search_namespace, double);
 double from_python(PyObject*, boost::python::type);
 double from_python(PyObject*, boost::python::type);
     
-PyObject* to_python(bool);
+PyObject* to_python(boost::python::search_namespace, bool);
 bool from_python(PyObject*, boost::python::type);
 bool from_python(PyObject*, boost::python::type);
 
-PyObject* to_python(void);
+PyObject* to_python(boost::python::search_namespace, void);
 void from_python(PyObject*, boost::python::type);
 
-PyObject* to_python(const char* s);
+PyObject* to_python(boost::python::search_namespace, const char* s);
 const char* from_python(PyObject*, boost::python::type);
 
-PyObject* to_python(const std::string& s);
+PyObject* to_python(boost::python::search_namespace, const std::string& s);
 std::string from_python(PyObject*, boost::python::type);
 std::string from_python(PyObject*, boost::python::type);
 
-inline PyObject* to_python(const std::complex& x)
+inline PyObject* to_python(boost::python::search_namespace, const std::complex& x)
 {
     return boost::python::detail::complex_to_python(x);
 }
 
-inline PyObject* to_python(const std::complex& x)
+inline PyObject* to_python(boost::python::search_namespace, const std::complex& x)
 {
     return boost::python::detail::complex_to_python(x);
 }
@@ -205,7 +205,7 @@ inline std::complex from_python(PyObject* p,
 }
 
 // For when your C++ function really wants to pass/return a PyObject*
-PyObject* to_python(PyObject*);
+PyObject* to_python(boost::python::search_namespace, PyObject*);
 PyObject* from_python(PyObject*, boost::python::type);
 
 // Some standard conversions to/from smart pointer types. You can add your own
@@ -259,13 +259,13 @@ boost::shared_ptr from_python(PyObject*p, boost::python::type
-PyObject* to_python(std::auto_ptr p)
+PyObject* to_python(boost::python::search_namespace, std::auto_ptr p)
 {
     return new boost::python::wrapped_pointer, T>(p);
 }
 
 template 
-PyObject* to_python(boost::shared_ptr p)
+PyObject* to_python(boost::python::search_namespace, boost::shared_ptr p)
 {
     return new boost::python::wrapped_pointer, T>(p);
 }
@@ -276,43 +276,43 @@ PyObject* to_python(boost::shared_ptr p)
 //
 
 #ifndef BOOST_MSVC6_OR_EARLIER
-inline PyObject* to_python(double d)
+inline PyObject* to_python(boost::python::search_namespace, double d)
 {
     return PyFloat_FromDouble(d);
 }
 
-inline PyObject* to_python(float f)
+inline PyObject* to_python(boost::python::search_namespace, float f)
 {
     return PyFloat_FromDouble(f);
 }
 #endif // BOOST_MSVC6_OR_EARLIER
 
-inline PyObject* to_python(long l)
+inline PyObject* to_python(boost::python::search_namespace, long l)
 {
 	return PyInt_FromLong(l);
 }
 
-inline PyObject* to_python(int x)
+inline PyObject* to_python(boost::python::search_namespace, int x)
 {
 	return PyInt_FromLong(x);
 }
 
-inline PyObject* to_python(short x)
+inline PyObject* to_python(boost::python::search_namespace, short x)
 {
 	return PyInt_FromLong(x);
 }
 
-inline PyObject* to_python(bool b)
+inline PyObject* to_python(boost::python::search_namespace, bool b)
 {
 	return PyInt_FromLong(b);
 }
 
-inline PyObject* to_python(void)
+inline PyObject* to_python(boost::python::search_namespace, void)
 {
     return boost::python::detail::none();
 }
 
-inline PyObject* to_python(const char* s)
+inline PyObject* to_python(boost::python::search_namespace, const char* s)
 {
 	return PyString_FromString(s);
 }
@@ -322,7 +322,7 @@ inline std::string from_python(PyObject* p, boost::python::type());
 }
 
-inline PyObject* to_python(PyObject* p)
+inline PyObject* to_python(boost::python::search_namespace, PyObject* p)
 {
     Py_INCREF(p);
     return p;
diff --git a/include/boost/python/cross_module.hpp b/include/boost/python/cross_module.hpp
index 7c1fe507..ff4d56f1 100644
--- a/include/boost/python/cross_module.hpp
+++ b/include/boost/python/cross_module.hpp
@@ -66,8 +66,8 @@ class python_import_extension_class_converters
         return python_import_extension_class_converters();
     }
 
-    PyObject* to_python(const T& x) const {
-        return boost::python::detail::import_extension_class::get_converters()->to_python(x);
+    PyObject* to_python(boost::python::semantics, const T& x) const {
+        return boost::python::detail::import_extension_class::get_converters()->to_python(boost::python::search_namespace, x);
     }
 
     friend T* from_python(PyObject* p, boost::python::type t, bool sig = false) {
@@ -101,8 +101,8 @@ class python_import_extension_class_converters
     friend const std::auto_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) {
         return boost::python::detail::import_extension_class::get_converters()->from_python_caTr(p, t);
     }
-    friend PyObject* to_python(std::auto_ptr x, bool sig = false) {
-        return boost::python::detail::import_extension_class::get_converters()->to_python(x);
+    friend PyObject* to_python(boost::python::semantics, std::auto_ptr x, bool sig = false) {
+        return boost::python::detail::import_extension_class::get_converters()->to_python(boost::python::search_namespace, x);
     }
 
     friend boost::shared_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) {
@@ -114,7 +114,7 @@ class python_import_extension_class_converters
     friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) {
         return boost::python::detail::import_extension_class::get_converters()->from_python_csTr(p, t);
     }
-    friend PyObject* to_python(boost::shared_ptr x, bool sig = false) {
+    friend PyObject* to_python(boost::python::semantics, boost::shared_ptr x, bool sig = false) {
         return boost::python::detail::import_extension_class::get_converters()->to_python(x);
     }
 };
@@ -142,22 +142,22 @@ struct export_converter_object_base
 
     virtual PyObject* to_python(const T& x) = 0;
 
-    virtual T* from_python_Ts(PyObject* p, boost::python::type t) = 0;
-    virtual const T* from_python_cTs(PyObject* p, boost::python::type t) = 0;
-    virtual const T* from_python_cTscr(PyObject* p, boost::python::type t) = 0;
-    virtual T* from_python_Tscr(PyObject* p, boost::python::type t) = 0;
-    virtual T& from_python_Tr(PyObject* p, boost::python::type t) = 0;
-    virtual const T& from_python_cTr(PyObject* p, boost::python::type t) = 0;
-    virtual const T& from_python_T(PyObject* p, boost::python::type t) = 0;
+    virtual T* from_python_Ts(PyObject* p, type t) = 0;
+    virtual const T* from_python_cTs(PyObject* p, type t) = 0;
+    virtual const T* from_python_cTscr(PyObject* p, type t) = 0;
+    virtual T* from_python_Tscr(PyObject* p, type t) = 0;
+    virtual T& from_python_Tr(PyObject* p, type t) = 0;
+    virtual const T& from_python_cTr(PyObject* p, type t) = 0;
+    virtual const T& from_python_T(PyObject* p, type t) = 0;
 
-    virtual std::auto_ptr& from_python_aTr(PyObject* p, boost::python::type&> t) = 0;
-    virtual std::auto_ptr from_python_aT(PyObject* p, boost::python::type > t) = 0;
-    virtual const std::auto_ptr& from_python_caTr(PyObject* p, boost::python::type&> t) = 0;
+    virtual std::auto_ptr& from_python_aTr(PyObject* p, type&> t) = 0;
+    virtual std::auto_ptr from_python_aT(PyObject* p, type > t) = 0;
+    virtual const std::auto_ptr& from_python_caTr(PyObject* p, type&> t) = 0;
     virtual PyObject* to_python(std::auto_ptr x) = 0;
 
-    virtual boost::shared_ptr& from_python_sTr(PyObject* p, boost::python::type&> t) = 0;
-    virtual const boost::shared_ptr& from_python_sT(PyObject* p, boost::python::type > t) = 0;
-    virtual const boost::shared_ptr& from_python_csTr(PyObject* p, boost::python::type&> t) = 0;
+    virtual boost::shared_ptr& from_python_sTr(PyObject* p, type&> t) = 0;
+    virtual const boost::shared_ptr& from_python_sT(PyObject* p, type > t) = 0;
+    virtual const boost::shared_ptr& from_python_csTr(PyObject* p, type&> t) = 0;
     virtual PyObject* to_python(boost::shared_ptr x) = 0;
 };
 
@@ -171,52 +171,52 @@ struct export_converter_object_noncopyable : export_converter_object_base
         throw import_error();
     }
 
-    virtual T* from_python_Ts(PyObject* p, boost::python::type t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual T* from_python_Ts(PyObject* p, type t) {
+        return from_python(p, t);
     }
-    virtual const T* from_python_cTs(PyObject* p, boost::python::type t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual const T* from_python_cTs(PyObject* p, type t) {
+        return from_python(p, t);
     }
-    virtual const T* from_python_cTscr(PyObject* p, boost::python::type t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual const T* from_python_cTscr(PyObject* p, type t) {
+        return from_python(p, t);
     }
-    virtual T* from_python_Tscr(PyObject* p, boost::python::type t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual T* from_python_Tscr(PyObject* p, type t) {
+        return from_python(p, t);
     }
-    virtual T& from_python_Tr(PyObject* p, boost::python::type t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual T& from_python_Tr(PyObject* p, type t) {
+        return from_python(p, t);
     }
-    virtual const T& from_python_cTr(PyObject* p, boost::python::type t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual const T& from_python_cTr(PyObject* p, type t) {
+        return from_python(p, t);
     }
-    virtual const T& from_python_T(PyObject* p, boost::python::type t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual const T& from_python_T(PyObject* p, type t) {
+        return from_python(p, t);
     }
 
-    virtual std::auto_ptr& from_python_aTr(PyObject* p, boost::python::type&> t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual std::auto_ptr& from_python_aTr(PyObject* p, type&> t) {
+        return from_python(p, t);
     }
-    virtual std::auto_ptr from_python_aT(PyObject* p, boost::python::type > t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual std::auto_ptr from_python_aT(PyObject* p, type > t) {
+        return from_python(p, t);
     }
-    virtual const std::auto_ptr& from_python_caTr(PyObject* p, boost::python::type&> t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual const std::auto_ptr& from_python_caTr(PyObject* p, type&> t) {
+        return from_python(p, t);
     }
     virtual PyObject* to_python(std::auto_ptr x) {
-        return BOOST_PYTHON_CONVERSION::to_python(x);
+        return to_python(x);
     }
 
-    virtual boost::shared_ptr& from_python_sTr(PyObject* p, boost::python::type&> t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual boost::shared_ptr& from_python_sTr(PyObject* p, type&> t) {
+        return from_python(p, t);
     }
-    virtual const boost::shared_ptr& from_python_sT(PyObject* p, boost::python::type > t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual const boost::shared_ptr& from_python_sT(PyObject* p, type > t) {
+        return from_python(p, t);
     }
-    virtual const boost::shared_ptr& from_python_csTr(PyObject* p, boost::python::type&> t) {
-        return BOOST_PYTHON_CONVERSION::from_python(p, t);
+    virtual const boost::shared_ptr& from_python_csTr(PyObject* p, type&> t) {
+        return from_python(p, t);
     }
     virtual PyObject* to_python(boost::shared_ptr x) {
-        return BOOST_PYTHON_CONVERSION::to_python(x);
+        return to_python(x);
     }
 };
 
@@ -225,7 +225,7 @@ template 
 struct export_converter_object : export_converter_object_noncopyable
 {
     virtual PyObject* to_python(const T& x) {
-        return BOOST_PYTHON_CONVERSION::py_extension_class_converters(boost::python::type()).to_python(x);
+        return BOOST_PYTHON_CONVERSION::py_extension_class_converters(type()).to_python(x);
     }
 };
 
@@ -247,29 +247,29 @@ class import_extension_class
       m_py_class = py_class;
     }
 
-    static boost::python::export_converter_object_base* get_converters();
+    static export_converter_object_base* get_converters();
 
   private:
     static std::string m_module;
     static std::string m_py_class;
-    static boost::python::export_converter_object_base* imported_converters;
+    static export_converter_object_base* imported_converters;
 };
 
 template  std::string import_extension_class::m_module;
 template  std::string import_extension_class::m_py_class;
 template 
-boost::python::export_converter_object_base*
+export_converter_object_base*
 import_extension_class::imported_converters = 0;
 
 template 
-boost::python::export_converter_object_base*
+export_converter_object_base*
 import_extension_class::get_converters() {
   if (imported_converters == 0) {
     void* cobject
       = import_converter_object(m_module, m_py_class,
                                 converters_attribute_name);
     imported_converters
-      = static_cast*>(cobject);
+      = static_cast*>(cobject);
     check_export_converters_api(
       export_converters_api_major,
       export_converters_api_minor,
diff --git a/include/boost/python/detail/extension_class.hpp b/include/boost/python/detail/extension_class.hpp
index 5c8e720a..5f893f26 100644
--- a/include/boost/python/detail/extension_class.hpp
+++ b/include/boost/python/detail/extension_class.hpp
@@ -179,31 +179,32 @@ template  >
 class python_extension_class_converters
 {
  public:
-    // Get an object which can be used to convert T to/from python. This is used
-    // as a kind of concept check by the global template
-    //
-    //     PyObject* to_python(const T& x)
-    //
-    // below this class, to prevent the confusing messages that would otherwise
-    // pop up. Now, if T hasn't been wrapped as an extension class, the user
-    // will see an error message about the lack of an eligible
-    // py_extension_class_converters() function.
-    friend python_extension_class_converters py_extension_class_converters(boost::python::type)
+    /// Get an object which can be used to convert T to/from python. This is used
+    /// as a kind of concept check by the free template function
+    ///
+    ///     PyObject* to_python(boost::python::semantics, const T& x)
+    ///
+    /// below this class, to prevent the confusing messages that would otherwise
+    /// pop up. Now, if T hasn't been wrapped as an extension class, the user
+    /// will see an error message about the lack of an eligible
+    /// py_extension_class_converters() function.
+    friend python_extension_class_converters py_extension_class_converters(
+        boost::python::type)
     { 
         return python_extension_class_converters();
     }
 
-    // This is a member function because in a conforming implementation, friend
-    // funcitons defined inline in the class body are all instantiated as soon
-    // as the enclosing class is instantiated. If T is not copyable, that causes
-    // a compiler error. Instead, we access this function through the global
-    // template 
-    //
-    //     PyObject* to_python(const T& x)
-    //
-    // defined below this class. Since template functions are instantiated only
-    // on demand, errors will be avoided unless T is noncopyable and the user
-    // writes code which causes us to try to copy a T.
+    /// This is a member function because in a conforming implementation, friend
+    /// funcitons defined inline in the class body are all instantiated as soon
+    /// as the enclosing class is instantiated. If T is not copyable, that causes
+    /// a compiler error. Instead, we access this function through the global
+    /// template 
+    ///
+    ///     PyObject* to_python(boost::python::semantics, const T& x)
+    ///
+    /// defined below this class. Since template functions are instantiated only
+    /// on demand, errors will be avoided unless T is noncopyable and the user
+    /// writes code which causes us to try to copy a T.
     PyObject* to_python(const T& x) const
     {
         boost::python::reference result(create_instance());
@@ -213,6 +214,7 @@ class python_extension_class_converters
         return result.release();
     }
 
+    /// Extract a pointer to T from the given PyObject. Will throw argument_error if obj == None.
     friend
     T* non_null_from_python(PyObject* obj, boost::python::type)
     {
@@ -235,16 +237,19 @@ class python_extension_class_converters
         throw boost::python::argument_error();
     }
 
-    // Convert to T*
+    /// Convert obj to T*. If obj == None, returns 0.
     friend T* from_python(PyObject* obj, boost::python::type)
     {
+        // forward declaration needed for ordinary lookup.
+        T* non_null_from_python(PyObject*, boost::python::type);
+        
         if (obj == Py_None)
             return 0;
         else
             return non_null_from_python(obj, boost::python::type());
     }
 
-    // Extract from obj a mutable reference to the PtrType object which is holding a T.
+    /// Extract from obj a mutable reference to the PtrType object which is holding a T.
     template 
     static PtrType& smart_ptr_reference(PyObject* obj, boost::python::type)
     {
@@ -263,10 +268,10 @@ class python_extension_class_converters
         throw boost::python::argument_error();
     }
 
-    // Extract from obj a reference to the PtrType object which is holding a
-    // T. If it weren't for auto_ptr, it would be a constant reference. Do not
-    // modify the referent except by copying an auto_ptr! If obj is None, the
-    // reference denotes a default-constructed PtrType
+    /// Extract from obj a reference to the PtrType object which is holding a
+    /// T. If it weren't for auto_ptr, it would be a constant reference. Do not
+    /// modify the referent except by copying an auto_ptr! If obj is None, the
+    /// reference denotes a default-constructed PtrType
     template 
     static PtrType& smart_ptr_value(PyObject* obj, boost::python::type)
     {
@@ -277,7 +282,9 @@ class python_extension_class_converters
         }
         return smart_ptr_reference(obj, boost::python::type());
     }
-        
+
+    /// Wrap x in a Python object which implements the functionality of a
+    /// regular wrapped T by dereferencing a copy of x.
     template 
     static PyObject* smart_ptr_to_python(PtrType x)
     {
@@ -293,6 +300,9 @@ class python_extension_class_converters
         return result.release();
     }
 
+    /// Create a Python object which is an instance of the Python type wrapper
+    /// for T.  The result does not actually contain the neccessary instance of
+    /// T. This function is an implementation detail.
     static boost::python::reference create_instance()
     {
         PyTypeObject* class_object = boost::python::detail::class_registry::class_object();
@@ -303,15 +313,15 @@ class python_extension_class_converters
             new boost::python::detail::extension_instance(class_object));
     }
 
-    // Convert to const T*
+    /// Convert p to const T*
     friend const T* from_python(PyObject* p, boost::python::type)
         { return from_python(p, boost::python::type()); }
 
-    // Convert to const T* const&
+    /// Convert p to const T* const&
     friend const T* from_python(PyObject* p, boost::python::type)
          { return from_python(p, boost::python::type()); }
   
-    // Convert to T* const&
+    /// Convert p to T* const&
     friend T* from_python(PyObject* p, boost::python::type)
          { return from_python(p, boost::python::type()); }
  
@@ -319,11 +329,11 @@ class python_extension_class_converters
     friend T& from_python(PyObject* p, boost::python::type)
         { return *boost::python::detail::check_non_null(non_null_from_python(p, boost::python::type())); }
 
-    // Convert to const T&
+    // Convert p to const T&
     friend const T& from_python(PyObject* p, boost::python::type)
         { return from_python(p, boost::python::type()); }
 
-    // Convert to T
+    /// Convert p to T
     friend const T& from_python(PyObject* p, boost::python::type)
         { return from_python(p, boost::python::type()); }
 
@@ -336,7 +346,7 @@ class python_extension_class_converters
     friend const std::auto_ptr& from_python(PyObject* p, boost::python::type&>)
         { return smart_ptr_value(p, boost::python::type >()); }
 
-    friend PyObject* to_python(std::auto_ptr x)
+    friend PyObject* to_python(boost::python::semantics, std::auto_ptr x)
         { return smart_ptr_to_python(x); }
 
     friend boost::shared_ptr& from_python(PyObject* p, boost::python::type&>)
@@ -348,7 +358,7 @@ class python_extension_class_converters
     friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type&>)
         { return smart_ptr_value(p, boost::python::type >()); }
 
-    friend PyObject* to_python(boost::shared_ptr x)
+    friend PyObject* to_python(boost::python::semantics, boost::shared_ptr x)
         { return smart_ptr_to_python(x); }
 };
 
@@ -357,7 +367,7 @@ class python_extension_class_converters
 // T is a wrapped class. See the first 2 functions declared in
 // python_extension_class_converters above for more info.
 template 
-PyObject* to_python(const T& x)
+PyObject* to_python(boost::python::semantics, const T& x)
 {
     return py_extension_class_converters(boost::python::type()).to_python(x);
 }
diff --git a/include/boost/python/detail/functions.hpp b/include/boost/python/detail/functions.hpp
index 055255e7..5c68e85d 100644
--- a/include/boost/python/detail/functions.hpp
+++ b/include/boost/python/detail/functions.hpp
@@ -94,9 +94,9 @@ struct raw_arguments_function : function
                  ref(keywords, ref::increment_count) :
                  ref(PyDict_New()));
             
-        return to_python(
-            (*m_pf)(from_python(args, boost::python::type()),
-                    from_python(dict.get(), boost::python::type()))); 
+        return to_python(search_namespace,
+            (*m_pf)(from_python(args, type()),
+                    from_python(dict.get(), type()))); 
     }
     
     const char* description() const
@@ -263,7 +263,7 @@ PyObject* getter_function::do_call(
     if (!PyArg_ParseTuple(args, const_cast("O"), &self))
         return 0;
 
-    return to_python(
+    return to_python(search_namespace,
         from_python(self, type())->*m_pm);
 }
 
diff --git a/include/boost/python/objects.hpp b/include/boost/python/objects.hpp
index 34052e1f..c8b4840f 100644
--- a/include/boost/python/objects.hpp
+++ b/include/boost/python/objects.hpp
@@ -297,7 +297,7 @@ struct list::slice_proxy
 
 BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
 
-PyObject* to_python(const boost::python::tuple&);
+PyObject* to_python(boost::python::search_namespace, const boost::python::tuple&);
 boost::python::tuple from_python(PyObject* p, boost::python::type);
 
 inline boost::python::tuple from_python(PyObject* p, boost::python::type)
@@ -305,7 +305,7 @@ inline boost::python::tuple from_python(PyObject* p, boost::python::type());
 }
 
-PyObject* to_python(const boost::python::list&);
+PyObject* to_python(boost::python::search_namespace, const boost::python::list&);
 boost::python::list from_python(PyObject* p, boost::python::type);
 
 inline boost::python::list from_python(PyObject* p, boost::python::type)
@@ -313,7 +313,7 @@ inline boost::python::list from_python(PyObject* p, boost::python::type());
 }
 
-PyObject* to_python(const boost::python::string&);
+PyObject* to_python(boost::python::search_namespace, const boost::python::string&);
 boost::python::string from_python(PyObject* p, boost::python::type);
 
 inline boost::python::string from_python(PyObject* p, boost::python::type)
@@ -321,7 +321,7 @@ inline boost::python::string from_python(PyObject* p, boost::python::type());
 }
 
-PyObject* to_python(const boost::python::dictionary&);
+PyObject* to_python(boost::python::search_namespace, const boost::python::dictionary&);
 boost::python::dictionary from_python(PyObject* p, boost::python::type);
 
 inline boost::python::dictionary from_python(PyObject* p, boost::python::type)
diff --git a/include/boost/python/operators.hpp b/include/boost/python/operators.hpp
index da88ec6c..0227b563 100644
--- a/include/boost/python/operators.hpp
+++ b/include/boost/python/operators.hpp
@@ -237,11 +237,11 @@ namespace detail
       {                                                                                 \
           PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const        \
           {                                                                             \
-              tuple args(ref(arguments, ref::increment_count));                                 \
+              tuple args(ref(arguments, ref::increment_count));                         \
                                                                                         \
-              return BOOST_PYTHON_CONVERSION::to_python(                                          \
-                  BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) oper      \
-                  BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()));        \
+              return to_python(search_namespace                                         \
+                  from_python(args[0].get(), type()) oper                         \
+                  from_python(args[1].get(), type()));                           \
           }                                                                             \
                                                                                         \
           const char* description() const                                               \
@@ -253,11 +253,11 @@ namespace detail
       {                                                                                 \
           PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const        \
           {                                                                             \
-              tuple args(ref(arguments, ref::increment_count));                                 \
+              tuple args(ref(arguments, ref::increment_count));                         \
                                                                                         \
-              return BOOST_PYTHON_CONVERSION::to_python(                                          \
-                  BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()) oper      \
-                  BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()));        \
+              return to_python(search_namespace                                         \
+                  from_python(args[1].get(), type()) oper                         \
+                  from_python(args[0].get(), type()));                           \
           }                                                                             \
                                                                                         \
           const char* description() const                                               \
@@ -278,10 +278,10 @@ namespace detail
       {                                                                                         \
           PyObject* do_call(PyObject* arguments, PyObject* /* keywords */) const                \
           {                                                                                     \
-              tuple args(ref(arguments, ref::increment_count));                                         \
+              tuple args(ref(arguments, ref::increment_count));                                 \
                                                                                                 \
-              return BOOST_PYTHON_CONVERSION::to_python(                                                  \
-                  oper(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type())));        \
+              return to_python(search_namespace,                                                \
+                  oper(from_python(args[0].get(), type())));                           \
           }                                                                                     \
                                                                                                 \
           const char* description() const                                                       \
@@ -335,9 +335,9 @@ namespace detail
                   throw argument_error();
               }
 
-              return BOOST_PYTHON_CONVERSION::to_python(
-                  pow(BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()),
-                   BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()))); 
+              return to_python(search_namespace,
+                  pow(from_python(args[0].get(), type()),
+                   from_python(args[1].get(), type()))); 
           }
 
           const char* description() const
@@ -358,9 +358,9 @@ namespace detail
                   throw argument_error();
               }
 
-              return BOOST_PYTHON_CONVERSION::to_python(
-                  pow(BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()),
-                   BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()))); 
+              return to_python(search_namespace,
+                  pow(from_python(args[1].get(), type()),
+                   from_python(args[0].get(), type()))); 
           }
 
           const char* description() const
@@ -386,13 +386,13 @@ namespace detail
               PyObject * res = PyTuple_New(2);
 
               PyTuple_SET_ITEM(res, 0,
-                BOOST_PYTHON_CONVERSION::to_python(
-                   BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) /
-                   BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()))); 
+                               to_python(search_namespace,
+                                         from_python(args[0].get(), type()) /
+                                         from_python(args[1].get(), type()))); 
               PyTuple_SET_ITEM(res, 1,
-                BOOST_PYTHON_CONVERSION::to_python(
-                   BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) %
-                   BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type())));
+                               to_python(search_namespace,
+                                         from_python(args[0].get(), type()) %
+                                         from_python(args[1].get(), type())));
 
               return res; 
           }
@@ -411,13 +411,13 @@ namespace detail
               PyObject * res = PyTuple_New(2);
 
               PyTuple_SET_ITEM(res, 0,
-                BOOST_PYTHON_CONVERSION::to_python(
-                   BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()) /
-                   BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()))); 
+                               to_python(search_namespace,
+                                         from_python(args[1].get(), type()) /
+                                         from_python(args[0].get(), type()))); 
               PyTuple_SET_ITEM(res, 1,
-                BOOST_PYTHON_CONVERSION::to_python(
-                   BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()) %
-                   BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type())));
+                               to_python(search_namespace,
+                                         from_python(args[1].get(), type()) %
+                                         from_python(args[0].get(), type())));
 
               return res; 
           }
@@ -443,12 +443,12 @@ namespace detail
           { 
               tuple args(ref(arguments, ref::increment_count));
 
-              return BOOST_PYTHON_CONVERSION::to_python(
-                  (BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) <
-                   BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type())) ?
+              return to_python(search_namespace,
+                  (from_python(args[0].get(), type()) <
+                   from_python(args[1].get(), type())) ?
                        - 1 :
-                       (BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()) <
-                       BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type())) ?
+                       (from_python(args[1].get(), type()) <
+                       from_python(args[0].get(), type())) ?
                            1 :
                            0) ; 
           }
@@ -465,12 +465,12 @@ namespace detail
           { 
               tuple args(ref(arguments, ref::increment_count));
 
-              return BOOST_PYTHON_CONVERSION::to_python(
-                  (BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type()) <
-                   BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type())) ?
+              return to_python(search_namespace,
+                  (from_python(args[1].get(), type()) <
+                   from_python(args[0].get(), type())) ?
                        - 1 :
-                       (BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) <
-                       BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type())) ?
+                       (from_python(args[0].get(), type()) <
+                       from_python(args[1].get(), type())) ?
                            1 :
                            0) ; 
           }
@@ -510,13 +510,13 @@ namespace detail
 // _STL::string, but std::string.
 # ifdef BOOST_PYTHON_USE_SSTREAM
               std::ostringstream s;
-              s << BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type());
-              return BOOST_PYTHON_CONVERSION::to_python(s.str()); 
+              s << from_python(args[0].get(), type());
+              return to_python(search_namespace, s.str()); 
 # else
               std::ostrstream s;
-              s << BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type()) << char();
+              s << from_python(args[0].get(), type()) << char();
               auto unfreezer unfreeze(s);
-              return BOOST_PYTHON_CONVERSION::to_python(const_cast(s.str())); 
+              return to_python(search_namespace, const_cast(s.str())); 
 # endif
           }
 
diff --git a/include/boost/python/reference.hpp b/include/boost/python/reference.hpp
index c633b9d7..6c05dd05 100644
--- a/include/boost/python/reference.hpp
+++ b/include/boost/python/reference.hpp
@@ -29,7 +29,7 @@ struct py_ptr_conversions : Base
     inline friend T from_python(PyObject* x, boost::python::type)
         { return T(boost::python::downcast(x).get(), T::increment_count); }
     
-    inline friend PyObject* to_python(T x)
+    inline friend PyObject* to_python(boost::python::semantics, T x)
         { return boost::python::as_object(x.release()); }
     
 };
@@ -165,7 +165,7 @@ typedef reference ref;
 template 
 ref make_ref(const T& x)
 {
-    return ref(to_python(x));
+    return ref(to_python(search_namespace, x));
 }
 
 }} // namespace boost::python
diff --git a/src/conversions.cpp b/src/conversions.cpp
index 4bfe2011..7744630c 100644
--- a/src/conversions.cpp
+++ b/src/conversions.cpp
@@ -22,6 +22,8 @@
 
 namespace boost { namespace python {
 
+enum semantics { search_namespace }; // Used to find to_python functions via koenig lookup.
+
 // IMPORTANT: this function may only be called from within a catch block!
 void handle_exception()
 {
@@ -142,7 +144,7 @@ PyObject* integer_to_python(T value)
         throw boost::python::error_already_set();
     }
     
-    return to_python(value_as_long);
+    return to_python(boost::python::search_namespace, value_as_long);
 }
 
 int from_python(PyObject* p, boost::python::type type)
@@ -150,7 +152,7 @@ int from_python(PyObject* p, boost::python::type type)
     return integer_from_python(p, type);
 }
 
-PyObject* to_python(unsigned int i)
+PyObject* to_python(boost::python::semantics, unsigned int i)
 {
     return integer_to_python(i);
 }
@@ -170,7 +172,7 @@ float from_python(PyObject* p, boost::python::type)
     return static_cast(from_python(p, boost::python::type()));
 }
 
-PyObject* to_python(unsigned short i)
+PyObject* to_python(boost::python::semantics, unsigned short i)
 {
     return integer_to_python(i);
 }
@@ -180,7 +182,7 @@ unsigned short from_python(PyObject* p, boost::python::type type
     return integer_from_python(p, type);
 }
 
-PyObject* to_python(char c)
+PyObject* to_python(boost::python::semantics, char c)
 {
     if (c == '\0') return PyString_FromString("");
     return PyString_FromStringAndSize(&c, 1);
@@ -198,7 +200,7 @@ char from_python(PyObject* p, boost::python::type)
     return PyString_AsString(p)[0];
 }
 
-PyObject* to_python(unsigned char i)
+PyObject* to_python(boost::python::semantics, unsigned char i)
 {
     return integer_to_python(i);
 }
@@ -208,7 +210,7 @@ unsigned char from_python(PyObject* p, boost::python::type type)
     return integer_from_python(p, type);
 }
 
-PyObject* to_python(signed char i)
+PyObject* to_python(boost::python::semantics, signed char i)
 {
     return integer_to_python(i);
 }
@@ -218,7 +220,7 @@ signed char from_python(PyObject* p, boost::python::type type)
     return integer_from_python(p, type);
 }
 
-PyObject* to_python(unsigned long x)
+PyObject* to_python(boost::python::semantics, unsigned long x)
 {
     return integer_to_python(x);
 }
@@ -244,7 +246,7 @@ const char* from_python(PyObject* p, boost::python::type)
     return s;
 }
 
-PyObject* to_python(const std::string& s)
+PyObject* to_python(boost::python::semantics, const std::string& s)
 {
     return PyString_FromStringAndSize(s.data(), s.size());
 }
@@ -268,12 +270,12 @@ bool from_python(PyObject* p, boost::python::type)
 
 #ifdef BOOST_MSVC6_OR_EARLIER
 // An optimizer bug prevents these from being inlined.
-PyObject* to_python(double d)
+PyObject* to_python(boost::python::semantics, double d)
 {
     return PyFloat_FromDouble(d);
 }
 
-PyObject* to_python(float f)
+PyObject* to_python(boost::python::semantics, float f)
 {
     return PyFloat_FromDouble(f);
 }
diff --git a/src/extension_class.cpp b/src/extension_class.cpp
index f71976b9..5afb5108 100644
--- a/src/extension_class.cpp
+++ b/src/extension_class.cpp
@@ -42,7 +42,7 @@ namespace detail {
 
 BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
 
-inline PyObject* to_python(boost::python::detail::operator_dispatcher* n) { return n; }
+inline PyObject* to_python(boost::python::semantics, boost::python::detail::operator_dispatcher* n) { return n; }
 
 BOOST_PYTHON_END_CONVERSION_NAMESPACE
 
diff --git a/src/gen_callback.py b/src/gen_callback.py
index f178212b..4a68e6bf 100644
--- a/src/gen_callback.py
+++ b/src/gen_callback.py
@@ -38,7 +38,7 @@ struct callback
 %{    template <%(class A%n%:, %)>
 %}    static R call_method(PyObject* self, const char* name%(, const A%n& a%n%))
     {%(
-        ref p%n(to_python(a%n));%)
+        ref p%n(to_python(search_namespace, a%n));%)
         ref result(PyEval_CallMethod(self, const_cast(name),
                                      const_cast("(%(O%))")%(,
                                      p%n.get()%)));
@@ -49,7 +49,7 @@ struct callback
 %{    template <%(class A%n%:, %)>
 %}    static R call(PyObject* self%(, const A%n& a%n%))
     {%(
-        ref p%n(to_python(a%n));%)
+        ref p%n(to_python(search_namespace, a%n));%)
         ref result(PyEval_CallFunction(self, const_cast("(%(O%))")%(,
                                        p%n.get()%)));
         detail::callback_adjust_refcount(result.get(), type());
@@ -70,7 +70,7 @@ struct callback
 %{    template <%(class A%n%:, %)>
 %}    static void call_method(PyObject* self, const char* name%(, const A%n& a%n%))
     {%(
-        ref p%n(to_python(a%n));%)
+        ref p%n(to_python(search_namespace, a%n));%)
         ref result(PyEval_CallMethod(self, const_cast(name),
                                      const_cast("(%(O%))")%(,
                                      p%n.get()%)));
@@ -79,7 +79,7 @@ struct callback
 %{    template <%(class A%n%:, %)>
 %}    static void call(PyObject* self%(, const A%n& a%n%))
     {%(
-        ref p%n(to_python(a%n));%)
+        ref p%n(to_python(search_namespace, a%n));%)
         ref result(PyEval_CallFunction(self, const_cast("(%(O%))")%(,
                                        p%n.get()%)));
     }
diff --git a/src/gen_caller.py b/src/gen_caller.py
index 26bd88c6..b6b59be5 100644
--- a/src/gen_caller.py
+++ b/src/gen_caller.py
@@ -97,14 +97,14 @@ def gen_caller(member_function_args, free_function_args = None):
     return (header % (member_function_args, free_function_args)
             + body_sections[0]
             + gen_functions(member_function, member_function_args,
-                            'R', '', 'return to_python(', ');')
+                            'R', '', 'return to_python(search_namespace, ', ');')
             + body_sections[1]
             + gen_functions(member_function, member_function_args,
-                            'R', ' const', 'return to_python(', ');')
+                            'R', ' const', 'return to_python(search_namespace, ', ');')
             + body_sections[2]
             
             + gen_functions(free_function, free_function_args,
-                            'R', 'return to_python(', ');')
+                            'R', 'return to_python(search_namespace, ', ');')
             + body_sections[3]
 
             # specialized part for void return values begins here
diff --git a/src/gen_extclass.py b/src/gen_extclass.py
index 8de8a1ae..d829b9ef 100644
--- a/src/gen_extclass.py
+++ b/src/gen_extclass.py
@@ -3,7 +3,7 @@ import string
 
 def gen_extclass(args):
     return (
-"""//  (C) Copyright David Abrahams 2000. Permission to copy, use, modify, sell and
+"""//  (C) Copyright David Abrahams 2000-2001. Permission to copy, use, modify, sell and
 //  distribute this software is granted provided this copyright notice appears
 //  in all copies. This software is provided "as is" without express or implied
 //  warranty, and with no claim as to its suitability for any purpose.
@@ -171,35 +171,44 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
 // and U. T is the class the user really intends to wrap. U is a class derived
 // from T with some virtual function overriding boilerplate, or if there are no
 // virtual functions, U = held_instance.
+//
+// A look-alike of this class in root/boost/python/cross_module.hpp
+// is used for the implementation of the cross-module support
+// (export_converters and import_converters). If from_python
+// and to_python converters are added or removed from the class
+// below, the class python_import_extension_class_converters has
+// to be modified accordingly.
+//
 template  >
 class python_extension_class_converters
 {
  public:
-    // Get an object which can be used to convert T to/from python. This is used
-    // as a kind of concept check by the global template
-    //
-    //     PyObject* to_python(const T& x)
-    //
-    // below this class, to prevent the confusing messages that would otherwise
-    // pop up. Now, if T hasn't been wrapped as an extension class, the user
-    // will see an error message about the lack of an eligible
-    // py_extension_class_converters() function.
-    friend python_extension_class_converters py_extension_class_converters(boost::python::type)
+    /// Get an object which can be used to convert T to/from python. This is used
+    /// as a kind of concept check by the free template function
+    ///
+    ///     PyObject* to_python(boost::python::semantics, const T& x)
+    ///
+    /// below this class, to prevent the confusing messages that would otherwise
+    /// pop up. Now, if T hasn't been wrapped as an extension class, the user
+    /// will see an error message about the lack of an eligible
+    /// py_extension_class_converters() function.
+    friend python_extension_class_converters py_extension_class_converters(
+        boost::python::type)
     { 
         return python_extension_class_converters();
     }
 
-    // This is a member function because in a conforming implementation, friend
-    // funcitons defined inline in the class body are all instantiated as soon
-    // as the enclosing class is instantiated. If T is not copyable, that causes
-    // a compiler error. Instead, we access this function through the global
-    // template 
-    //
-    //     PyObject* to_python(const T& x)
-    //
-    // defined below this class. Since template functions are instantiated only
-    // on demand, errors will be avoided unless T is noncopyable and the user
-    // writes code which causes us to try to copy a T.
+    /// This is a member function because in a conforming implementation, friend
+    /// funcitons defined inline in the class body are all instantiated as soon
+    /// as the enclosing class is instantiated. If T is not copyable, that causes
+    /// a compiler error. Instead, we access this function through the global
+    /// template 
+    ///
+    ///     PyObject* to_python(boost::python::semantics, const T& x)
+    ///
+    /// defined below this class. Since template functions are instantiated only
+    /// on demand, errors will be avoided unless T is noncopyable and the user
+    /// writes code which causes us to try to copy a T.
     PyObject* to_python(const T& x) const
     {
         boost::python::reference result(create_instance());
@@ -209,6 +218,7 @@ class python_extension_class_converters
         return result.release();
     }
 
+    /// Extract a pointer to T from the given PyObject. Will throw argument_error if obj == None.
     friend
     T* non_null_from_python(PyObject* obj, boost::python::type)
     {
@@ -231,16 +241,19 @@ class python_extension_class_converters
         throw boost::python::argument_error();
     }
 
-    // Convert to T*
+    /// Convert obj to T*. If obj == None, returns 0.
     friend T* from_python(PyObject* obj, boost::python::type)
     {
+        // forward declaration needed for ordinary lookup.
+        T* non_null_from_python(PyObject*, boost::python::type);
+        
         if (obj == Py_None)
             return 0;
         else
             return non_null_from_python(obj, boost::python::type());
     }
 
-    // Extract from obj a mutable reference to the PtrType object which is holding a T.
+    /// Extract from obj a mutable reference to the PtrType object which is holding a T.
     template 
     static PtrType& smart_ptr_reference(PyObject* obj, boost::python::type)
     {
@@ -259,10 +272,10 @@ class python_extension_class_converters
         throw boost::python::argument_error();
     }
 
-    // Extract from obj a reference to the PtrType object which is holding a
-    // T. If it weren't for auto_ptr, it would be a constant reference. Do not
-    // modify the referent except by copying an auto_ptr! If obj is None, the
-    // reference denotes a default-constructed PtrType
+    /// Extract from obj a reference to the PtrType object which is holding a
+    /// T. If it weren't for auto_ptr, it would be a constant reference. Do not
+    /// modify the referent except by copying an auto_ptr! If obj is None, the
+    /// reference denotes a default-constructed PtrType
     template 
     static PtrType& smart_ptr_value(PyObject* obj, boost::python::type)
     {
@@ -273,7 +286,9 @@ class python_extension_class_converters
         }
         return smart_ptr_reference(obj, boost::python::type());
     }
-        
+
+    /// Wrap x in a Python object which implements the functionality of a
+    /// regular wrapped T by dereferencing a copy of x.
     template 
     static PyObject* smart_ptr_to_python(PtrType x)
     {
@@ -289,6 +304,9 @@ class python_extension_class_converters
         return result.release();
     }
 
+    /// Create a Python object which is an instance of the Python type wrapper
+    /// for T.  The result does not actually contain the neccessary instance of
+    /// T. This function is an implementation detail.
     static boost::python::reference create_instance()
     {
         PyTypeObject* class_object = boost::python::detail::class_registry::class_object();
@@ -299,15 +317,15 @@ class python_extension_class_converters
             new boost::python::detail::extension_instance(class_object));
     }
 
-    // Convert to const T*
+    /// Convert p to const T*
     friend const T* from_python(PyObject* p, boost::python::type)
         { return from_python(p, boost::python::type()); }
 
-    // Convert to const T* const&
+    /// Convert p to const T* const&
     friend const T* from_python(PyObject* p, boost::python::type)
          { return from_python(p, boost::python::type()); }
   
-    // Convert to T* const&
+    /// Convert p to T* const&
     friend T* from_python(PyObject* p, boost::python::type)
          { return from_python(p, boost::python::type()); }
  
@@ -315,11 +333,11 @@ class python_extension_class_converters
     friend T& from_python(PyObject* p, boost::python::type)
         { return *boost::python::detail::check_non_null(non_null_from_python(p, boost::python::type())); }
 
-    // Convert to const T&
+    // Convert p to const T&
     friend const T& from_python(PyObject* p, boost::python::type)
         { return from_python(p, boost::python::type()); }
 
-    // Convert to T
+    /// Convert p to T
     friend const T& from_python(PyObject* p, boost::python::type)
         { return from_python(p, boost::python::type()); }
 
@@ -332,7 +350,7 @@ class python_extension_class_converters
     friend const std::auto_ptr& from_python(PyObject* p, boost::python::type&>)
         { return smart_ptr_value(p, boost::python::type >()); }
 
-    friend PyObject* to_python(std::auto_ptr x)
+    friend PyObject* to_python(boost::python::semantics, std::auto_ptr x)
         { return smart_ptr_to_python(x); }
 
     friend boost::shared_ptr& from_python(PyObject* p, boost::python::type&>)
@@ -344,7 +362,7 @@ class python_extension_class_converters
     friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type&>)
         { return smart_ptr_value(p, boost::python::type >()); }
 
-    friend PyObject* to_python(boost::shared_ptr x)
+    friend PyObject* to_python(boost::python::semantics, boost::shared_ptr x)
         { return smart_ptr_to_python(x); }
 };
 
@@ -353,7 +371,7 @@ class python_extension_class_converters
 // T is a wrapped class. See the first 2 functions declared in
 // python_extension_class_converters above for more info.
 template 
-PyObject* to_python(const T& x)
+PyObject* to_python(boost::python::semantics, const T& x)
 {
     return py_extension_class_converters(boost::python::type()).to_python(x);
 }
diff --git a/src/objects.cpp b/src/objects.cpp
index cc46b2ba..973462a5 100644
--- a/src/objects.cpp
+++ b/src/objects.cpp
@@ -49,9 +49,9 @@ PyObject* object::get() const
 
 BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
 
-PyObject* to_python(const boost::python::tuple& x)
+PyObject* to_python(boost::python::semantics, const boost::python::tuple& x)
 {
-    return object_to_python(x);
+    return boost::python::object_to_python(x);
 }
 
 boost::python::tuple from_python(PyObject* p, boost::python::type type)
@@ -59,7 +59,7 @@ boost::python::tuple from_python(PyObject* p, boost::python::type());
+      const int number = from_python(state[0].get(), boost::python::type());
       if (number != 42)
           w.set_secret_number(number);
   }
@@ -1117,13 +1117,13 @@ PyObject* raw(const boost::python::tuple& args, const boost::python::dictionary&
         throw boost::python::argument_error();
     }
     
-    RawTest* first = BOOST_PYTHON_CONVERSION::from_python(args[0].get(), boost::python::type());
-    int second = BOOST_PYTHON_CONVERSION::from_python(args[1].get(), boost::python::type());
+    RawTest* first = from_python(args[0].get(), boost::python::type());
+    int second = from_python(args[1].get(), boost::python::type());
     
-    int third = BOOST_PYTHON_CONVERSION::from_python(keywords[boost::python::string("third")].get(), boost::python::type());
-    int fourth = BOOST_PYTHON_CONVERSION::from_python(keywords[boost::python::string("fourth")].get(), boost::python::type());
+    int third = from_python(keywords[boost::python::string("third")].get(), boost::python::type());
+    int fourth = from_python(keywords[boost::python::string("fourth")].get(), boost::python::type());
     
-    return BOOST_PYTHON_CONVERSION::to_python(first->i_ + second + third + fourth);
+    return to_python(boost::python::search_namespace, first->i_ + second + third + fourth);
 }
 
 void init_module()