Ticket #1316: call.patch
File call.patch, 3.5 KB (added by , 15 years ago) |
---|
-
boost/python/object_core.hpp
42 42 43 43 namespace boost { namespace python { 44 44 45 namespace detail { 46 47 class kwds_proxy; 48 class args_proxy; 49 50 } 51 45 52 namespace converter 46 53 { 47 54 template <class T> struct arg_to_python; … … 99 106 # define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PYTHON_MAX_ARITY, <boost/python/object_call.hpp>)) 100 107 # include BOOST_PP_ITERATE() 101 108 109 detail::args_proxy operator* () const; 110 111 object operator()(detail::args_proxy const &args) const; 112 object operator()(detail::args_proxy const &args, 113 detail::kwds_proxy const &kwds) const; 114 115 102 116 // truth value testing 103 117 // 104 118 operator bool_type() const; … … 410 424 // implementation 411 425 // 412 426 427 namespace detail { 428 class call_proxy 429 { 430 public: 431 call_proxy(object target) : m_target(target) {} 432 operator object() const { return m_target;} 433 434 private: 435 object m_target; 436 }; 437 438 class kwds_proxy : public call_proxy 439 { 440 public: 441 kwds_proxy(object o = object()) : call_proxy(o) {} 442 }; 443 class args_proxy : public call_proxy 444 { 445 public: 446 args_proxy(object o) : call_proxy(o) {} 447 kwds_proxy operator* () const { return kwds_proxy(*this);} 448 }; 449 } 450 451 template <typename U> 452 detail::args_proxy api::object_operators<U>::operator* () const 453 { 454 object_cref2 x = *static_cast<U const*>(this); 455 return detail::args_proxy(x); 456 } 457 458 template <typename U> 459 object api::object_operators<U>::operator()(detail::args_proxy const &args) const 460 { 461 U const& self = *static_cast<U const*>(this); 462 PyObject *result = PyObject_Call(get_managed_object(self, tag), 463 args.operator object().ptr(), 464 0); 465 return object(detail::new_reference(result)); 466 467 } 468 469 template <typename U> 470 object api::object_operators<U>::operator()(detail::args_proxy const &args, 471 detail::kwds_proxy const &kwds) const 472 { 473 U const& self = *static_cast<U const*>(this); 474 PyObject *result = PyObject_Call(get_managed_object(self, tag), 475 args.operator object().ptr(), 476 kwds.operator object().ptr()); 477 return object(detail::new_reference(result)); 478 479 } 480 413 481 inline object::object() 414 482 : object_base(python::incref(Py_None)) 415 483 {} -
libs/python/test/object.cpp
123 123 return !y[key]; 124 124 } 125 125 126 object test_call(object c, object args, object kwds) 127 { 128 return c(*args, **kwds); 129 } 130 126 131 bool check_string_slice() 127 132 { 128 133 object s("hello, world"); … … 324 329 def("test_item", test_item); 325 330 def("test_not_item", test_not_item); 326 331 332 def("test_call", test_call); 333 327 334 def("check_binary_operators", check_binary_operators); 328 335 def("check_inplace", check_inplace); 329 336 def("check_string_slice", check_string_slice); -
libs/python/test/object.py
15 15 'hello, world!' 16 16 >>> number() 17 17 42 18 >>> def print_args(*args, **kwds): 19 ... print args, kwds 20 >>> test_call(print_args, (0, 1, 2, 3), {'a':'A'}) 21 (0, 1, 2, 3) {'a': 'A'} 18 22 19 23 >>> test('hi') 20 24 1