Author: dreiss
Date: Tue Mar 9 05:19:20 2010
New Revision: 920662
URL: http://svn.apache.org/viewvc?rev=920662&view=rev
Log:
THRIFT-659. php: Make php_thrift_protocol handle std::exception cleanly
Any std::exceptions thrown from within the extension will now be
converted into php exceptions.
Modified:
incubator/thrift/trunk/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
Modified:
incubator/thrift/trunk/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp?rev=920662&r1=920661&r2=920662&view=diff
==============================================================================
---
incubator/thrift/trunk/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
(original)
+++
incubator/thrift/trunk/lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp
Tue Mar 9 05:19:20 2010
@@ -399,6 +399,12 @@ void throw_tprotocolexception(char* what
throw PHPExceptionWrapper(ex);
}
+// Sets EG(exception), call this and then RETURN_NULL();
+void throw_zend_exception_from_std_exception(const std::exception& ex) {
+ zend_throw_exception(zend_exception_get_default(TSRMLS_CC),
const_cast<char*>(ex.what()), 0 TSRMLS_CC);
+}
+
+
void binary_deserialize(int8_t thrift_typeID, PHPInputTransport& transport,
zval* return_value, HashTable* fieldspec) {
zval** val_ptr;
Z_TYPE_P(return_value) = IS_NULL; // just in case
@@ -927,6 +933,9 @@ PHP_FUNCTION(thrift_protocol_write_binar
} catch (const PHPExceptionWrapper& ex) {
zend_throw_exception_object(ex TSRMLS_CC);
RETURN_NULL();
+ } catch (const std::exception& ex) {
+ throw_zend_exception_from_std_exception(ex);
+ RETURN_NULL();
}
}
@@ -1000,6 +1009,9 @@ PHP_FUNCTION(thrift_protocol_read_binary
} catch (const PHPExceptionWrapper& ex) {
zend_throw_exception_object(ex TSRMLS_CC);
RETURN_NULL();
+ } catch (const std::exception& ex) {
+ throw_zend_exception_from_std_exception(ex);
+ RETURN_NULL();
}
}