Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55078 - in sandbox-branches/bhy/py3k: boost/python libs/python/src libs/python/test
From: divinekid_at_[hidden]
Date: 2009-07-22 01:39:00


Author: bhy
Date: 2009-07-22 01:38:59 EDT (Wed, 22 Jul 2009)
New Revision: 55078
URL: http://svn.boost.org/trac/boost/changeset/55078

Log:
implemented list.sort with keyword argument support, by using args_proxy and kwds_proxy. Not a nice solution though...

Text files modified:
   sandbox-branches/bhy/py3k/boost/python/list.hpp | 10 ++++++++--
   sandbox-branches/bhy/py3k/libs/python/src/list.cpp | 8 ++++++++
   sandbox-branches/bhy/py3k/libs/python/test/list.cpp | 6 ++++++
   sandbox-branches/bhy/py3k/libs/python/test/list.py | 2 +-
   4 files changed, 23 insertions(+), 3 deletions(-)

Modified: sandbox-branches/bhy/py3k/boost/python/list.hpp
==============================================================================
--- sandbox-branches/bhy/py3k/boost/python/list.hpp (original)
+++ sandbox-branches/bhy/py3k/boost/python/list.hpp 2009-07-22 01:38:59 EDT (Wed, 22 Jul 2009)
@@ -37,8 +37,12 @@
       void reverse(); // reverse *IN PLACE*
 
       void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
+#if PY_VERSION_HEX >= 0x03000000
+ void sort(args_proxy const &args,
+ kwds_proxy const &kwds);
+#else
       void sort(object_cref cmpfunc);
-
+#endif
 
    protected:
       list_base(); // new list
@@ -113,13 +117,15 @@
         base::remove(object(value));
     }
 
+#if PY_VERSION_HEX <= 0x03000000
     void sort() { base::sort(); }
-
+
     template <class T>
     void sort(T const& value)
     {
         base::sort(object(value));
     }
+#endif
     
  public: // implementation detail -- for internal use only
     BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, base)

Modified: sandbox-branches/bhy/py3k/libs/python/src/list.cpp
==============================================================================
--- sandbox-branches/bhy/py3k/libs/python/src/list.cpp (original)
+++ sandbox-branches/bhy/py3k/libs/python/src/list.cpp 2009-07-22 01:38:59 EDT (Wed, 22 Jul 2009)
@@ -132,10 +132,18 @@
     }
 }
 
+#if PY_VERSION_HEX >= 0x03000000
+void list_base::sort(args_proxy const &args,
+ kwds_proxy const &kwds)
+{
+ this->attr("sort")(args, kwds);
+}
+#else
 void list_base::sort(object_cref cmpfunc)
 {
     this->attr("sort")(cmpfunc);
 }
+#endif
 
 // For some reason, moving this to the end of the TU suppresses an ICE
 // with vc6.

Modified: sandbox-branches/bhy/py3k/libs/python/test/list.cpp
==============================================================================
--- sandbox-branches/bhy/py3k/libs/python/test/list.cpp (original)
+++ sandbox-branches/bhy/py3k/libs/python/test/list.cpp 2009-07-22 01:38:59 EDT (Wed, 22 Jul 2009)
@@ -7,6 +7,8 @@
 #include <boost/python/def.hpp>
 #include <boost/python/class.hpp>
 #include <boost/python/list.hpp>
+#include <boost/python/tuple.hpp>
+#include <boost/python/dict.hpp>
 #include <boost/python/make_function.hpp>
 #include <boost/lexical_cast.hpp>
 #define BOOST_ENABLE_ASSERT_HANDLER
@@ -114,7 +116,11 @@
     print(x);
 
     print("reverse sorted:");
+#if PY_VERSION_HEX >= 0x03000000
+ x.sort(*tuple(), **dict(make_tuple(make_tuple("reverse", true))));
+#else
     x.sort(&notcmp);
+#endif
     print(x);
 
     list w;

Modified: sandbox-branches/bhy/py3k/libs/python/test/list.py
==============================================================================
--- sandbox-branches/bhy/py3k/libs/python/test/list.py (original)
+++ sandbox-branches/bhy/py3k/libs/python/test/list.py 2009-07-22 01:38:59 EDT (Wed, 22 Jul 2009)
@@ -73,7 +73,7 @@
 ...
 
>>> y = X(42)
->>> exercise(letters, y, printer)
+>>> exercise(letters, y, printer) #doctest: +NORMALIZE_WHITESPACE
 after append:
 ['h', 'e', 'l', 'l', 'o', '.', [1, 2], X(42), 5, X(3)]
 number of X(42) instances: 1


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk