From 97bedcc064b93d9026edfb08b6bc511b6a0fb9ab Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Tue, 20 Sep 2005 18:46:15 +0000 Subject: [PATCH] - Provide helper function to avoid TSRM issues with exception base and root --- ext/pdo/pdo.c | 20 +++++++++++++++----- ext/pdo/pdo_dbh.c | 4 ++-- ext/pdo/php_pdo_int.h | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ext/pdo/pdo.c b/ext/pdo/pdo.c index f43bcf6f90..c965c87141 100755 --- a/ext/pdo/pdo.c +++ b/ext/pdo/pdo.c @@ -67,6 +67,20 @@ PDO_API char *php_pdo_str_tolower_dup(const char *src, int len) return dest; } +PDO_API zend_class_entry *php_pdo_get_exception_base(int root TSRMLS_DC) +{ +#if can_handle_soft_dependency_on_SPL && defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1)) + if (!root) { + return spl_ce_RuntimeException; + } +#endif +#if (PHP_MAJOR_VERSION < 6) + return zend_exception_get_default(); +#else + return zend_exception_get_default(TSRMLS_C); +#endif +} + zend_class_entry *pdo_dbh_ce, *pdo_dbstmt_ce, *pdo_row_ce; /* proto array pdo_drivers() @@ -303,11 +317,7 @@ PHP_MINIT_FUNCTION(pdo) "PDO persistent database", module_number); INIT_CLASS_ENTRY(ce, "PDOException", NULL); -#if can_handle_soft_dependency_on_SPL && defined(HAVE_SPL) && ((PHP_MAJOR_VERSION > 5) || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1)) - pdo_exception_ce = zend_register_internal_class_ex(&ce, spl_ce_RuntimeException, NULL TSRMLS_CC); -#else - pdo_exception_ce = zend_register_internal_class_ex(&ce, zend_exception_get_default(TSRMLS_C), NULL TSRMLS_CC); -#endif + pdo_exception_ce = zend_register_internal_class_ex(&ce, php_pdo_get_exception_base(0 TSRMLS_CC), NULL TSRMLS_CC); zend_declare_property_null(pdo_exception_ce, "errorInfo", sizeof("errorInfo")-1, ZEND_ACC_PUBLIC TSRMLS_CC); pdo_dbh_init(TSRMLS_C); diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 83e0b5949a..bccddb5920 100755 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -84,7 +84,7 @@ void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *sqlstate } } else { zval *ex; - zend_class_entry *def_ex = zend_exception_get_default(TSRMLS_C), *pdo_ex = php_pdo_get_exception(TSRMLS_C); + zend_class_entry *def_ex = php_pdo_get_exception_base(1 TSRMLS_CC), *pdo_ex = php_pdo_get_exception(TSRMLS_C); MAKE_STD_ZVAL(ex); object_init_ex(ex, pdo_ex); @@ -165,7 +165,7 @@ void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC) } } else if (EG(exception) == NULL) { zval *ex; - zend_class_entry *def_ex = zend_exception_get_default(TSRMLS_C), *pdo_ex = php_pdo_get_exception(TSRMLS_C); + zend_class_entry *def_ex = php_pdo_get_exception_base(1 TSRMLS_CC), *pdo_ex = php_pdo_get_exception(TSRMLS_C); MAKE_STD_ZVAL(ex); object_init_ex(ex, pdo_ex); diff --git a/ext/pdo/php_pdo_int.h b/ext/pdo/php_pdo_int.h index f47d1cb769..073dddf7e6 100755 --- a/ext/pdo/php_pdo_int.h +++ b/ext/pdo/php_pdo_int.h @@ -25,6 +25,7 @@ /* Stuff private to the PDO extension and not for consumption by PDO drivers * */ extern zend_class_entry *pdo_exception_ce; +PDO_API zend_class_entry *php_pdo_get_exception_base(int root TSRMLS_DC); int php_pdo_list_entry(void); void pdo_dbh_init(TSRMLS_D); -- 2.50.1