Skip to content

Commit f759e9e

Browse files
author
Ralf W. Grosse-Kunstleve
committed
merging current boost/python and libs/python from trunk into release branch
[SVN r66066]
1 parent 846c5d9 commit f759e9e

File tree

7 files changed

+38
-4
lines changed

7 files changed

+38
-4
lines changed

example/tutorial/Jamroot

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ project
2626
# source files after the colon separated by spaces.
2727
python-extension hello_ext : hello.cpp ;
2828

29+
# Put the extension and Boost.Python DLL in the current directory, so
30+
# that running script by hand works.
31+
install convenient_copy
32+
: hello_ext
33+
: <install-dependencies>on <install-type>SHARED_LIB <install-type>PYTHON_EXTENSION
34+
<location>.
35+
;
36+
2937
# A little "rule" (function) to clean up the syntax of declaring tests
3038
# of these extension modules.
3139
local rule run-test ( test-name : sources + )

include/boost/python/detail/operator_id.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ enum operator_id
5353
op_nonzero,
5454
#endif
5555
op_repr
56+
#if PY_VERSION_HEX >= 0x03000000
57+
,op_truediv
58+
#endif
5659
};
5760

5861
}}} // namespace boost::python::detail

include/boost/python/object/function.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ struct BOOST_PYTHON_DECL function : PyObject
3939
void doc(object const& x);
4040

4141
object const& name() const;
42+
43+
object const& get_namespace() const { return m_namespace; }
4244

4345
private: // helper functions
4446
object signature(bool show_return_type=false) const;

include/boost/python/object/make_instance.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
# include <boost/python/converter/registered.hpp>
1111
# include <boost/python/detail/decref_guard.hpp>
1212
# include <boost/python/detail/none.hpp>
13-
# include <boost/type_traits/is_class.hpp>
1413
# include <boost/type_traits/is_union.hpp>
15-
# include <boost/mpl/assert.hpp>
16-
# include <boost/mpl/or.hpp>
1714

1815
namespace boost { namespace python { namespace objects {
1916

include/boost/python/operators.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ namespace self_ns \
212212
BOOST_PYTHON_BINARY_OPERATOR(add, radd, +)
213213
BOOST_PYTHON_BINARY_OPERATOR(sub, rsub, -)
214214
BOOST_PYTHON_BINARY_OPERATOR(mul, rmul, *)
215-
BOOST_PYTHON_BINARY_OPERATOR(div, rdiv, /)
215+
#if PY_VERSION_HEX >= 0x03000000
216+
BOOST_PYTHON_BINARY_OPERATOR(truediv, rtruediv, /)
217+
#else
218+
BOOST_PYTHON_BINARY_OPERATOR(div, rdiv, /)
219+
#endif
216220
BOOST_PYTHON_BINARY_OPERATOR(mod, rmod, %)
217221
BOOST_PYTHON_BINARY_OPERATOR(lshift, rlshift, <<)
218222
BOOST_PYTHON_BINARY_OPERATOR(rshift, rrshift, >>)

src/object/function.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,11 +670,26 @@ extern "C"
670670
{
671671
return python::incref(upcast<PyObject>(&PyCFunction_Type));
672672
}
673+
674+
static PyObject* function_get_module(PyObject* op, void*)
675+
{
676+
function* f = downcast<function>(op);
677+
object const& ns = f->get_namespace();
678+
if (!ns.is_none()) {
679+
return python::incref(ns.ptr());
680+
}
681+
PyErr_SetString(
682+
PyExc_AttributeError, const_cast<char*>(
683+
"Boost.Python function __module__ unknown."));
684+
return 0;
685+
}
673686
}
674687

675688
static PyGetSetDef function_getsetlist[] = {
676689
{const_cast<char*>("__name__"), (getter)function_get_name, 0, 0, 0 },
677690
{const_cast<char*>("func_name"), (getter)function_get_name, 0, 0, 0 },
691+
{const_cast<char*>("__module__"), (getter)function_get_module, 0, 0, 0 },
692+
{const_cast<char*>("func_module"), (getter)function_get_module, 0, 0, 0 },
678693
{const_cast<char*>("__class__"), (getter)function_get_class, 0, 0, 0 }, // see note above
679694
{const_cast<char*>("__doc__"), (getter)function_get_doc, (setter)function_set_doc, 0, 0},
680695
{const_cast<char*>("func_doc"), (getter)function_get_doc, (setter)function_set_doc, 0, 0},

test/pytype_function.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
>>> print func.__doc__.splitlines()[1]
88
func( (A)arg1) -> A :
99
10+
>>> print func.__module__
11+
pytype_function_ext
12+
13+
>>> print func.__name__
14+
func
1015
"""
1116
def run(args = None):
1217
import sys

0 commit comments

Comments
 (0)