diff --git a/example/tutorial/Jamroot b/example/tutorial/Jamroot index 2e7ffe57..1a70cb91 100644 --- a/example/tutorial/Jamroot +++ b/example/tutorial/Jamroot @@ -26,6 +26,14 @@ project # source files after the colon separated by spaces. python-extension hello_ext : hello.cpp ; +# Put the extension and Boost.Python DLL in the current directory, so +# that running script by hand works. +install convenient_copy + : hello_ext + : on SHARED_LIB PYTHON_EXTENSION + . + ; + # A little "rule" (function) to clean up the syntax of declaring tests # of these extension modules. local rule run-test ( test-name : sources + ) diff --git a/include/boost/python/detail/operator_id.hpp b/include/boost/python/detail/operator_id.hpp index 25642fba..ecfc70f1 100644 --- a/include/boost/python/detail/operator_id.hpp +++ b/include/boost/python/detail/operator_id.hpp @@ -53,6 +53,9 @@ enum operator_id op_nonzero, #endif op_repr +#if PY_VERSION_HEX >= 0x03000000 + ,op_truediv +#endif }; }}} // namespace boost::python::detail diff --git a/include/boost/python/object/function.hpp b/include/boost/python/object/function.hpp index e44ca5b2..f29d3448 100644 --- a/include/boost/python/object/function.hpp +++ b/include/boost/python/object/function.hpp @@ -39,6 +39,8 @@ struct BOOST_PYTHON_DECL function : PyObject void doc(object const& x); object const& name() const; + + object const& get_namespace() const { return m_namespace; } private: // helper functions object signature(bool show_return_type=false) const; diff --git a/include/boost/python/object/make_instance.hpp b/include/boost/python/object/make_instance.hpp index 264a05b4..1ffded12 100644 --- a/include/boost/python/object/make_instance.hpp +++ b/include/boost/python/object/make_instance.hpp @@ -10,10 +10,7 @@ # include # include # include -# include # include -# include -# include namespace boost { namespace python { namespace objects { diff --git a/include/boost/python/operators.hpp b/include/boost/python/operators.hpp index 9a60b344..ea2be7b9 100644 --- a/include/boost/python/operators.hpp +++ b/include/boost/python/operators.hpp @@ -212,7 +212,11 @@ namespace self_ns \ BOOST_PYTHON_BINARY_OPERATOR(add, radd, +) BOOST_PYTHON_BINARY_OPERATOR(sub, rsub, -) BOOST_PYTHON_BINARY_OPERATOR(mul, rmul, *) -BOOST_PYTHON_BINARY_OPERATOR(div, rdiv, /) +#if PY_VERSION_HEX >= 0x03000000 + BOOST_PYTHON_BINARY_OPERATOR(truediv, rtruediv, /) +#else + BOOST_PYTHON_BINARY_OPERATOR(div, rdiv, /) +#endif BOOST_PYTHON_BINARY_OPERATOR(mod, rmod, %) BOOST_PYTHON_BINARY_OPERATOR(lshift, rlshift, <<) BOOST_PYTHON_BINARY_OPERATOR(rshift, rrshift, >>) diff --git a/src/object/function.cpp b/src/object/function.cpp index 98c7c966..9328e014 100644 --- a/src/object/function.cpp +++ b/src/object/function.cpp @@ -670,11 +670,26 @@ extern "C" { return python::incref(upcast(&PyCFunction_Type)); } + + static PyObject* function_get_module(PyObject* op, void*) + { + function* f = downcast(op); + object const& ns = f->get_namespace(); + if (!ns.is_none()) { + return python::incref(ns.ptr()); + } + PyErr_SetString( + PyExc_AttributeError, const_cast( + "Boost.Python function __module__ unknown.")); + return 0; + } } static PyGetSetDef function_getsetlist[] = { {const_cast("__name__"), (getter)function_get_name, 0, 0, 0 }, {const_cast("func_name"), (getter)function_get_name, 0, 0, 0 }, + {const_cast("__module__"), (getter)function_get_module, 0, 0, 0 }, + {const_cast("func_module"), (getter)function_get_module, 0, 0, 0 }, {const_cast("__class__"), (getter)function_get_class, 0, 0, 0 }, // see note above {const_cast("__doc__"), (getter)function_get_doc, (setter)function_set_doc, 0, 0}, {const_cast("func_doc"), (getter)function_get_doc, (setter)function_set_doc, 0, 0}, diff --git a/test/pytype_function.py b/test/pytype_function.py index 7927629b..83674632 100755 --- a/test/pytype_function.py +++ b/test/pytype_function.py @@ -7,6 +7,11 @@ >>> print func.__doc__.splitlines()[1] func( (A)arg1) -> A : +>>> print func.__module__ +pytype_function_ext + +>>> print func.__name__ +func """ def run(args = None): import sys