diff --git a/doc/projects.html b/doc/projects.html index 0601189e..6a80655c 100644 --- a/doc/projects.html +++ b/doc/projects.html @@ -375,6 +375,27 @@ application modules, including GUI and post-processing of results.

+
PolyBoRi
+ +
+

Michael Brickenstein writes:

+ +
+

The core of PolyBoRi is a C++ library, which provides + high-level data types for Boolean polynomials and monomials, + exponent vectors, as well as for the underlying polynomial + rings and subsets of the powerset of the Boolean variables. As + a unique approach, binary decision diagrams are used as + internal storage type for polynomial structures. On top of + this C++-library we provide a Python interface. This allows + parsing of complex polynomial systems, as well as sophisticated + and extendable strategies for Gröbner basis computation. + Boost.Python has helped us to create this interface in a + very clean way.

+
+
+
Rational Discovery LLC
@@ -435,11 +456,11 @@
-

Revised +

Revised - 15 July, 2003

+ 29 May, 2008

© Copyright Dave - Abrahams 2002-2003.

+ Abrahams 2002-2008.

diff --git a/doc/v2/Dereferenceable.html b/doc/v2/Dereferenceable.html index e208f0ec..f7c53fd2 100644 --- a/doc/v2/Dereferenceable.html +++ b/doc/v2/Dereferenceable.html @@ -4,7 +4,7 @@ - + Boost.Python - Dereferenceable Concept diff --git a/doc/v2/Extractor.html b/doc/v2/Extractor.html old mode 100755 new mode 100644 index 8b5b3b3c..441ca38b --- a/doc/v2/Extractor.html +++ b/doc/v2/Extractor.html @@ -4,7 +4,7 @@ - + Boost.Python - Extractor Concept diff --git a/doc/v2/HolderGenerator.html b/doc/v2/HolderGenerator.html old mode 100755 new mode 100644 index 1ed5118a..58b4265a --- a/doc/v2/HolderGenerator.html +++ b/doc/v2/HolderGenerator.html @@ -4,7 +4,7 @@ - + Boost.Python - Holder Concept diff --git a/doc/v2/object.html b/doc/v2/object.html index 5572cae4..f35fa579 100644 --- a/doc/v2/object.html +++ b/doc/v2/object.html @@ -74,6 +74,32 @@ +
Class + const_objattribute_policies
+ +
+
+
Class + const_objattribute_policies synopsis
+ +
Class + const_objattribute_policies static functions
+
+
+ +
Class + objattribute_policies
+ +
+
+
Class + objattribute_policies synopsis
+ +
Class + objattribute_policies static functions
+
+
+
Class const_item_policies
@@ -328,6 +354,102 @@ static void del(object const&target, char const* key); +

Class + const_objattribute_policies

+ +

The policies which are used for proxies representing an attribute + access to a const object when the attribute name is + given as a const object.

+ +

Class + const_objattribute_policies synopsis

+
+namespace boost { namespace python { namespace api
+{
+  struct const_objattribute_policies
+  {
+      typedef object const& key_type;
+      static object get(object const& target, object const& key);
+  };
+}}}
+
+ +

Class + const_objattribute_policies static functions

+
+static object get(object const& target, object const& key);
+
+ +
+
Requires: key is an object + holding a string.
+ +
Effects: accesses the attribute of target named + by key.
+ +
Returns: An object managing the result of the + attribute access.
+ +
Throws: error_already_set if a + Python exception is raised.
+
+ +

Class + objattribute_policies

+ +

The policies which are used for proxies representing an attribute + access to a mutable object when the attribute name is + given as a const object.

+ +

Class + objattribute_policies synopsis

+
+namespace boost { namespace python { namespace api
+{
+  struct objattribute_policies : const_objattribute_policies
+  {
+      static object const& set(object const& target, object const& key, object const& value);
+      static void del(object const&target, object const& key);
+  };
+}}}
+
+ +

Class + objattribute_policies static functions

+
+static object const& set(object const& target, object const& key, object const& value);
+
+ +
+
Requires: key is an object + holding a string.
+ +
Effects: sets the attribute of target named by + key to value.
+ +
Throws: error_already_set if a + Python exception is raised.
+
+
+static void del(object const&target, object const& key);
+
+ +
+
Requires: key is an object + holding a string.
+ +
Effects: deletes the attribute of target named + by key.
+ +
Throws: error_already_set if a + Python exception is raised.
+
+ + +

Class const_item_policies

@@ -542,6 +664,8 @@ namespace boost { namespace python { namespace api // proxy<const_object_attribute> attr(char const*) const; proxy<object_attribute> attr(char const*); + proxy<const_object_objattribute> attr(object const&) const; + proxy<object_objattribute> attr(object const&); // item access // @@ -608,6 +732,21 @@ proxy<object_attribute> attr(char const* name); name as its key.
+proxy<const_object_objattribute> attr(const object& name) const;
+proxy<object_objattribute> attr(const object& name);
+
+ +
+
Requires: name is a object holding a string.
+ +
Effects: accesses the named attribute of + *this.
+ +
Returns: a proxy object which binds + object(*static_cast<U*>(this)) as its target, and + name as its key.
+
+
 template <class T>
 proxy<const_object_item> operator[](T const& key) const;
 template <class T>
@@ -938,11 +1077,11 @@ object sum_items(object seq)
 

Revised - 13 January, 2006 + 27 May, 2008

© Copyright Dave Abrahams 2006.

+ "http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams 2008.

diff --git a/include/boost/python/iterator.hpp b/include/boost/python/iterator.hpp index 146dcbfe..a64a9207 100644 --- a/include/boost/python/iterator.hpp +++ b/include/boost/python/iterator.hpp @@ -14,6 +14,16 @@ # include # include +# if defined(BOOST_MSVC) && (BOOST_MSVC == 1400) /* +> warning C4180: qualifier applied to function type has no meaning; ignored +Peter Dimov wrote: +This warning is caused by an overload resolution bug in VC8 that cannot be +worked around and will probably not be fixed by MS in the VC8 line. The +problematic overload is only instantiated and never called, and the code +works correctly. */ +# pragma warning(disable: 4180) +# endif + # include # include diff --git a/include/boost/python/object_attributes.hpp b/include/boost/python/object_attributes.hpp old mode 100755 new mode 100644 index 012240b2..26d59911 --- a/include/boost/python/object_attributes.hpp +++ b/include/boost/python/object_attributes.hpp @@ -17,6 +17,7 @@ struct const_attribute_policies { typedef char const* key_type; static object get(object const& target, char const* key); + static object get(object const& target, object const& key); }; struct attribute_policies : const_attribute_policies @@ -25,6 +26,18 @@ struct attribute_policies : const_attribute_policies static void del(object const&target, char const* key); }; +struct const_objattribute_policies +{ + typedef object const key_type; + static object get(object const& target, object const& key); +}; + +struct objattribute_policies : const_objattribute_policies +{ + static object const& set(object const& target, object const& key, object const& value); + static void del(object const&target, object const& key); +}; + // // implementation // @@ -42,11 +55,30 @@ inline const_object_attribute object_operators::attr(char const* name) const return const_object_attribute(x, name); } +template +inline object_objattribute object_operators::attr(object const& name) +{ + object_cref2 x = *static_cast(this); + return object_objattribute(x, name); +} + +template +inline const_object_objattribute object_operators::attr(object const& name) const +{ + object_cref2 x = *static_cast(this); + return const_object_objattribute(x, name); +} + inline object const_attribute_policies::get(object const& target, char const* key) { return python::getattr(target, key); } +inline object const_objattribute_policies::get(object const& target, object const& key) +{ + return python::getattr(target, key); +} + inline object const& attribute_policies::set( object const& target , char const* key @@ -56,6 +88,15 @@ inline object const& attribute_policies::set( return value; } +inline object const& objattribute_policies::set( + object const& target + , object const& key + , object const& value) +{ + python::setattr(target, key, value); + return value; +} + inline void attribute_policies::del( object const& target , char const* key) @@ -63,6 +104,13 @@ inline void attribute_policies::del( python::delattr(target, key); } +inline void objattribute_policies::del( + object const& target + , object const& key) +{ + python::delattr(target, key); +} + }}} // namespace boost::python::api #endif // OBJECT_ATTRIBUTES_DWA2002615_HPP diff --git a/include/boost/python/object_core.hpp b/include/boost/python/object_core.hpp old mode 100755 new mode 100644 index ecd7257f..b4a0ea82 --- a/include/boost/python/object_core.hpp +++ b/include/boost/python/object_core.hpp @@ -59,6 +59,8 @@ namespace api struct const_attribute_policies; struct attribute_policies; + struct const_objattribute_policies; + struct objattribute_policies; struct const_item_policies; struct item_policies; struct const_slice_policies; @@ -67,6 +69,8 @@ namespace api typedef proxy const_object_attribute; typedef proxy object_attribute; + typedef proxy const_object_objattribute; + typedef proxy object_objattribute; typedef proxy const_object_item; typedef proxy object_item; typedef proxy const_object_slice; @@ -108,6 +112,8 @@ namespace api // const_object_attribute attr(char const*) const; object_attribute attr(char const*); + const_object_objattribute attr(object const&) const; + object_objattribute attr(object const&); // item access // diff --git a/include/boost/python/suite/indexing/container_utils.hpp b/include/boost/python/suite/indexing/container_utils.hpp index a25185d0..72710bb8 100644 --- a/include/boost/python/suite/indexing/container_utils.hpp +++ b/include/boost/python/suite/indexing/container_utils.hpp @@ -7,9 +7,12 @@ #ifndef PY_CONTAINER_UTILS_JDG20038_HPP # define PY_CONTAINER_UTILS_JDG20038_HPP +# include +# include # include # include # include +# include namespace boost { namespace python { namespace container_utils { @@ -19,11 +22,13 @@ namespace boost { namespace python { namespace container_utils { { typedef typename Container::value_type data_type; - // l must be a list or some container - - for (int i = 0; i < l.attr("__len__")(); i++) + // l must be iterable + BOOST_FOREACH(object elem, + std::make_pair( + boost::python::stl_input_iterator(l), + boost::python::stl_input_iterator() + )) { - object elem(l[i]); extract x(elem); // try if elem is an exact data_type type if (x.check()) diff --git a/include/boost/python/type_id.hpp b/include/boost/python/type_id.hpp old mode 100755 new mode 100644 index 559a38b5..4a5727d5 --- a/include/boost/python/type_id.hpp +++ b/include/boost/python/type_id.hpp @@ -11,6 +11,7 @@ # include # include # include +# include # include # include # include diff --git a/include/boost/python/with_custodian_and_ward.hpp b/include/boost/python/with_custodian_and_ward.hpp index 906de6d7..9399478f 100644 --- a/include/boost/python/with_custodian_and_ward.hpp +++ b/include/boost/python/with_custodian_and_ward.hpp @@ -68,8 +68,9 @@ struct with_custodian_and_ward : BasePolicy_ bool result = BasePolicy_::precall(args_); - if (!result) + if (!result) { Py_DECREF(life_support); + } return result; } diff --git a/src/errors.cpp b/src/errors.cpp index 39777e98..34ea22f4 100644 --- a/src/errors.cpp +++ b/src/errors.cpp @@ -41,6 +41,10 @@ BOOST_PYTHON_DECL bool handle_exception_impl(function0 f) { PyErr_SetString(PyExc_IndexError, x.what()); } + catch(const std::invalid_argument& x) + { + PyErr_SetString(PyExc_ValueError, x.what()); + } catch(const std::exception& x) { PyErr_SetString(PyExc_RuntimeError, x.what()); diff --git a/test/args.cpp b/test/args.cpp index 238a471e..592a8e50 100644 --- a/test/args.cpp +++ b/test/args.cpp @@ -14,7 +14,7 @@ using namespace boost::python; -#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) +#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) # define make_tuple boost::python::make_tuple #endif diff --git a/test/module_tail.cpp b/test/module_tail.cpp index 02cfc6a3..f9cdca18 100644 --- a/test/module_tail.cpp +++ b/test/module_tail.cpp @@ -13,6 +13,7 @@ # endif # ifdef _MSC_VER +# include // for _set_se_translator() # pragma warning(push) # pragma warning(disable:4297) # pragma warning(disable:4535) diff --git a/test/numpy.cpp b/test/numpy.cpp index e5da7c9b..9472f92e 100644 --- a/test/numpy.cpp +++ b/test/numpy.cpp @@ -10,19 +10,16 @@ #include using namespace boost::python; - -#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) -# define make_tuple boost::python::make_tuple -#endif +namespace py = boost::python; // See if we can invoke array() from C++ numeric::array new_array() { return numeric::array( - make_tuple( - make_tuple(1,2,3) - , make_tuple(4,5,6) - , make_tuple(7,8,9) + py::make_tuple( + py::make_tuple(1,2,3) + , py::make_tuple(4,5,6) + , py::make_tuple(7,8,9) ) ); } @@ -51,7 +48,7 @@ namespace str format("exception type: %sn"); format += "exception value: %sn"; format += "traceback:n%s" ; - object ret = format % boost::python::make_tuple(ty, v, tr); + object ret = format % py::make_tuple(ty, v, tr); return ret; } } @@ -71,7 +68,7 @@ namespace // inherits that behavior from object. void exercise(numeric::array& y, object check) { - y[make_tuple(2,1)] = 3; + y[py::make_tuple(2,1)] = 3; CHECK(y); CHECK(y.astype('D')); CHECK(y.copy()); @@ -116,12 +113,12 @@ void exercise_numarray(numeric::array& y, object check) CHECK(y); CHECK(y.type()); - CHECK(y.factory(make_tuple(1.2, 3.4))); - CHECK(y.factory(make_tuple(1.2, 3.4), "f8")); - CHECK(y.factory(make_tuple(1.2, 3.4), "f8", true)); - CHECK(y.factory(make_tuple(1.2, 3.4), "f8", true, false)); - CHECK(y.factory(make_tuple(1.2, 3.4), "f8", true, false, object())); - CHECK (y.factory(make_tuple(1.2, 3.4), "f8", true, false, object(), make_tuple(1,2,1))); + CHECK(y.factory(py::make_tuple(1.2, 3.4))); + CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8")); + CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true)); + CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true, false)); + CHECK(y.factory(py::make_tuple(1.2, 3.4), "f8", true, false, object())); + CHECK (y.factory(py::make_tuple(1.2, 3.4), "f8", true, false, object(), py::make_tuple(1,2,1))); } diff --git a/test/object.cpp b/test/object.cpp old mode 100755 new mode 100644 index 1d9f6bcf..04afe841 --- a/test/object.cpp +++ b/test/object.cpp @@ -38,26 +38,61 @@ object obj_getattr(object x, char const* name) return x.attr(name); } +object obj_objgetattr(object x, object const& name) +{ + return x.attr(name); +} + object obj_const_getattr(object const& x, char const* name) { return x.attr(name); } +object obj_const_objgetattr(object const& x, object const& name) +{ + return x.attr(name); +} + void obj_setattr(object x, char const* name, object value) { x.attr(name) = value; } +void obj_objsetattr(object x, object const& name, object value) +{ + x.attr(name) = value; +} + void obj_setattr42(object x, char const* name) { x.attr(name) = 42; } +void obj_objsetattr42(object x, object const& name) +{ + x.attr(name) = 42; +} + void obj_moveattr(object& x, char const* src, char const* dst) { x.attr(dst) = x.attr(src); } +void obj_objmoveattr(object& x, object const& src, object const& dst) +{ + x.attr(dst) = x.attr(src); +} + +void obj_delattr(object x, char const* name) +{ + x.attr(name).del(); +} + +void obj_objdelattr(object x, object const& name) +{ + x.attr(name).del(); +} + object obj_getitem(object x, object key) { return x[key]; @@ -108,11 +143,21 @@ bool test_attr(object y, char* name) return y.attr(name); } +bool test_objattr(object y, object& name) +{ + return y.attr(name); +} + bool test_not_attr(object y, char* name) { return !y.attr(name); } +bool test_not_objattr(object y, object& name) +{ + return !y.attr(name); +} + bool test_item(object y, object key) { return y[key]; @@ -301,11 +346,17 @@ BOOST_PYTHON_MODULE(object_ext) def("number", number); def("obj_getattr", obj_getattr); + def("obj_objgetattr", obj_objgetattr); def("obj_const_getattr", obj_const_getattr); + def("obj_const_objgetattr", obj_const_objgetattr); def("obj_setattr", obj_setattr); + def("obj_objsetattr", obj_objsetattr); def("obj_setattr42", obj_setattr42); + def("obj_objsetattr42", obj_objsetattr42); def("obj_moveattr", obj_moveattr); - + def("obj_objmoveattr", obj_objmoveattr); + def("obj_delattr", obj_delattr); + def("obj_objdelattr", obj_objdelattr); def("obj_getitem", obj_getitem); def("obj_getitem3", obj_getitem); @@ -319,7 +370,9 @@ BOOST_PYTHON_MODULE(object_ext) def("test_not", test_not); def("test_attr", test_attr); + def("test_objattr", test_objattr); def("test_not_attr", test_not_attr); + def("test_not_objattr", test_not_objattr); def("test_item", test_item); def("test_not_item", test_not_item); diff --git a/test/object.py b/test/object.py index b51650a6..82634082 100644 --- a/test/object.py +++ b/test/object.py @@ -34,29 +34,68 @@ >>> try: obj_getattr(x, 'foo') ... except AttributeError: pass ... else: print 'expected an exception' +>>> try: obj_objgetattr(x, 'objfoo') +... except AttributeError: pass +... else: print 'expected an exception' >>> obj_setattr(x, 'foo', 1) >>> x.foo 1 +>>> obj_objsetattr(x, 'objfoo', 1) +>>> try:obj_objsetattr(x, 1) +... except TypeError: pass +... else: print 'expected an exception' +>>> x.objfoo +1 >>> obj_getattr(x, 'foo') 1 +>>> obj_objgetattr(x, 'objfoo') +1 +>>> try:obj_objgetattr(x, 1) +... except TypeError: pass +... else: print 'expected an exception' >>> obj_const_getattr(x, 'foo') 1 +>>> obj_const_objgetattr(x, 'objfoo') +1 >>> obj_setattr42(x, 'foo') >>> x.foo 42 +>>> obj_objsetattr42(x, 'objfoo') +>>> x.objfoo +42 >>> obj_moveattr(x, 'foo', 'bar') >>> x.bar 42 +>>> obj_objmoveattr(x, 'objfoo', 'objbar') +>>> x.objbar +42 >>> test_attr(x, 'foo') 1 +>>> test_objattr(x, 'objfoo') +1 >>> test_not_attr(x, 'foo') 0 +>>> test_not_objattr(x, 'objfoo') +0 >>> x.foo = None >>> test_attr(x, 'foo') 0 +>>> x.objfoo = None +>>> test_objattr(x, 'objfoo') +0 >>> test_not_attr(x, 'foo') 1 +>>> test_not_objattr(x, 'objfoo') +1 +>>> obj_delattr(x, 'foo') +>>> obj_objdelattr(x, 'objfoo') +>>> try:obj_delattr(x, 'foo') +... except AttributeError: pass +... else: print 'expected an exception' +>>> try:obj_objdelattr(x, 'objfoo') +... except AttributeError: pass +... else: print 'expected an exception' Items diff --git a/test/pickle3.cpp b/test/pickle3.cpp index 01ce27cf..6472def8 100644 --- a/test/pickle3.cpp +++ b/test/pickle3.cpp @@ -25,7 +25,7 @@ #include #include -#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) +#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) # define make_tuple boost::python::make_tuple #endif diff --git a/test/slice.cpp b/test/slice.cpp index f28e38f5..8b1d1bf5 100644 --- a/test/slice.cpp +++ b/test/slice.cpp @@ -10,7 +10,7 @@ using namespace boost::python; -#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) +#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580)) || BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1500)) # define make_tuple boost::python::make_tuple #endif diff --git a/test/vector_indexing_suite.py b/test/vector_indexing_suite.py index 9bb75700..5fe2efe4 100644 --- a/test/vector_indexing_suite.py +++ b/test/vector_indexing_suite.py @@ -321,6 +321,19 @@ e >>> print_xvec(v) [ a b c d e f g h i j ] +##################################################################### +# extend using a generator expression +##################################################################### +>>> v[:] = ['a','b','c','d','e'] # reset again +>>> def generator(): +... addlist = ['f','g','h','i','j'] +... for i in addlist: +... if i != 'g': +... yield i +>>> v.extend(generator()) +>>> print_xvec(v) +[ a b c d e f h i j ] + ##################################################################### # vector of strings #####################################################################