]> granicus.if.org Git - php/commitdiff
- Provide helper function to avoid TSRM issues with exception base and root
authorMarcus Boerger <helly@php.net>
Tue, 20 Sep 2005 18:46:15 +0000 (18:46 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 20 Sep 2005 18:46:15 +0000 (18:46 +0000)
ext/pdo/pdo.c
ext/pdo/pdo_dbh.c
ext/pdo/php_pdo_int.h

index f43bcf6f90032f13e53ba37a4e9ef37219f63d8b..c965c87141c7982b91352f5ce52960dd2144b50c 100755 (executable)
@@ -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);
index 83e0b5949a9c092485fabb9da72df01a9f51927d..bccddb5920d23d34fce5290df979396f5ca4521c 100755 (executable)
@@ -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);
index f47d1cb7698c64376bfd2e443048c8cec598c54d..073dddf7e68b9cfa9b13a1876e0d590fb0a4adb9 100755 (executable)
@@ -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);