Browse files

* Fix support for "return-internal-reference"

  • Loading branch information...
1 parent 7573f45 commit 85a6a5f064f2f39df7634fb31da948d08f8484ba @moriyoshi committed Jul 3, 2009
Showing with 23 additions and 2 deletions.
  1. +17 −1 boost/php/converter.hpp
  2. +5 −0 tests/m008.cpp
  3. +1 −1 tests/m008.phpt
View
18 boost/php/converter.hpp
@@ -36,6 +36,8 @@
#include <boost/mpl/bool.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/not.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_pod.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/remove_reference.hpp>
@@ -141,7 +143,7 @@ struct to_value_ptr_converter;
template<typename Tnative_>
struct to_value_ptr_converter<Tnative_, true> {
- value_ptr operator()(const Tnative_& val TSRMLS_DC) const {
+ value_ptr operator()(Tnative_ const& val TSRMLS_DC) const {
return value_ptr(new value(val), false);
}
};
@@ -168,6 +170,13 @@ struct to_value_ptr_converter<value_ptr> {
};
template<>
+struct to_value_ptr_converter<value_ptr&> {
+ value_ptr operator()(value_ptr that TSRMLS_DC) const {
+ return value_ptr(that);
+ }
+};
+
+template<>
struct to_value_ptr_converter<value_ptr const&> {
value_ptr operator()(value_ptr const& that TSRMLS_DC) const {
return value_ptr(that);
@@ -188,6 +197,13 @@ inline value_ptr to_value_ptr(Tsrc_ const& val TSRMLS_DC)
return converter(val TSRMLS_CC);
}
+template<typename Tsrc_>
+inline value_ptr to_value_ptr(Tsrc_& val TSRMLS_DC, typename boost::disable_if<detail::is_first_class<Tsrc_> >::type* = 0)
+{
+ static to_value_ptr_converter<Tsrc_&> converter;
+ return converter(val TSRMLS_CC);
+}
+
template<typename T_>
inline T_ to_native(value_ptr const& val TSRMLS_DC)
{
View
5 tests/m008.cpp
@@ -17,6 +17,10 @@ class test {
return acc_;
}
+ test& self() {
+ return *this;
+ }
+
static void foo(test const& t) {
std::cout << t.acc_ << std::endl;
}
@@ -48,6 +52,7 @@ class m008_module
php::def_class<test>("test", boost::mpl::vector1<int>() TSRMLS_CC)
.defun("accumulate", &test::accumulate)
.defun("foo", &test::foo)
+ .defun("self", &test::self)
.defun("create", &test::create)
.fixup();
}
View
2 tests/m008.phpt
@@ -10,7 +10,7 @@ $test2 = new test(2);
for ($i = 0; $i < 10; ++$i) {
$test1->accumulate($i);
test::foo($test1);
- var_dump($test2->accumulate(10-$i));
+ var_dump($test2->self()->self()->accumulate(10-$i));
echo "--\n";
}
?>

0 comments on commit 85a6a5f

Please sign in to comment.