ssb             Wed Mar 14 16:53:07 2001 EDT

  Modified files:              
    /pear/PEAR  pear.c 
  Log:
  * implemented setErrorHandling
  
  
Index: pear/PEAR/pear.c
diff -u pear/PEAR/pear.c:1.2 pear/PEAR/pear.c:1.3
--- pear/PEAR/pear.c:1.2        Tue Mar 13 17:04:45 2001
+++ pear/PEAR/pear.c    Wed Mar 14 16:53:06 2001
@@ -22,6 +22,7 @@
 #include "php_pear.h"
 #include "config.h"
 #include "build-defs.h"
+#include "ext/standard/info.h"
 
 ZEND_DECLARE_MODULE_GLOBALS(pear)
 
@@ -35,8 +36,8 @@
     PHP_FALIAS(pear,              pear_constructor, NULL)
     PHP_FALIAS(_pear,             pear_destructor, NULL)
     PHP_FALIAS(iserror,           pear_isError, first_arg_force_ref)
-#if 0
     PHP_FALIAS(seterrorhandling,  pear_setErrorHandling, NULL)
+#if 0
     PHP_FALIAS(raiseerror,        pear_raiseError, NULL)
 #endif
     {NULL, NULL, NULL}
@@ -136,13 +137,14 @@
 _destructor_objects_dtor(void *data)
 {
     zval *object = (zval *)data;
-    ZVAL_DELREF(object);
+    /*ZVAL_DELREF(object);*/
+    zval_dtor(object);
 }
 
 /* Remove if there's nothing to do at request start */
 PHP_RINIT_FUNCTION(pear)
 {
-    zend_llist_init(&PEARG(destructor_objects), sizeof(zval), NULL, 0);
+    zend_llist_init(&PEARG(destructor_objects), sizeof(zval), 
+_destructor_objects_dtor, 0);
        return SUCCESS;
 }
 
@@ -183,6 +185,9 @@
     zval_dtor(funcname);
     zval_dtor(retval);
     zval_dtor(arg);
+    efree(funcname);
+    efree(retval);
+    efree(arg);
 }
 
 /* Remove if there's nothing to do at request end */
@@ -197,7 +202,7 @@
 PHP_MINFO_FUNCTION(pear)
 {
        php_info_print_table_start();
-       php_info_print_table_header(2, "PEAR", " $Revision: 1.2 $");
+       php_info_print_table_header(2, "PEAR", " $Revision: 1.3 $");
        php_info_print_table_end();
 
        /* DISPLAY_INI_ENTRIES(); */
@@ -222,7 +227,7 @@
     dtorfunc[len - 1] = '\0';
     if (zend_hash_exists(&this->value.obj.ce->function_table, dtorfunc, len)) {
         zend_llist_add_element(&PEARG(destructor_objects), this);
-        ZVAL_ADDREF(this);
+        /*ZVAL_ADDREF(this);*/
         /*php_printf("registered object on destructor list\n");*/
     }
     efree(dtorfunc);
@@ -254,6 +259,76 @@
         ce = ce->parent;
     } while (ce != NULL);
     RETURN_FALSE;
+}
+
+
+PHP_FUNCTION(pear_setErrorHandling)
+{
+    zval **mode = NULL, **options = NULL, *this = getThis(), *tmp;
+    HashTable *symtab;
+    char *modename, *optionsname, *callbackname;
+    int argc;
+
+    argc = ZEND_NUM_ARGS();
+    
+    if (argc < 1 || argc > 2 ||
+        zend_get_parameters_ex(argc, &mode, &options) == FAILURE) {
+        ZEND_WRONG_PARAM_COUNT();
+    }
+    
+    convert_to_long_ex(mode);
+
+    if (this == NULL) {
+        modename = "_PEAR_default_error_mode";
+        optionsname = "_PEAR_default_error_options";
+        callbackname = "_PEAR_default_error_callback";
+        symtab = &EG(symbol_table);
+    } else {
+        modename = "_default_error_mode";
+        optionsname = "_default_error_options";
+        callbackname = "_default_error_callback";
+        symtab = this->value.obj.properties;
+    }
+
+    MAKE_STD_ZVAL(tmp);
+
+    switch ((*mode)->value.lval) {
+        case PEAR_ERROR_RETURN:
+        case PEAR_ERROR_PRINT:
+        case PEAR_ERROR_TRIGGER:
+        case PEAR_ERROR_DIE:
+            ZVAL_LONG(tmp, (*mode)->value.lval);
+            ZEND_SET_SYMBOL(symtab, modename, tmp);
+            if (options != NULL) {
+                ZEND_SET_SYMBOL(symtab, optionsname, *options);
+            }
+            break;
+
+        case PEAR_ERROR_CALLBACK:
+            ZVAL_LONG(tmp, (*mode)->value.lval);
+            ZEND_SET_SYMBOL(symtab, modename, tmp);
+            if (options != NULL) {
+                zval **el0, **el1;
+                if (((*options)->type != IS_STRING && (*options)->type != IS_ARRAY) ||
+                    ((*options)->type == IS_ARRAY && 
+                     (zend_hash_num_elements((*options)->value.ht) != 2 ||
+                      zend_hash_index_find((*options)->value.ht, 0, (void **)&el0) == 
+FAILURE ||
+                      zend_hash_index_find((*options)->value.ht, 1, (void **)&el1) == 
+FAILURE ||
+                      (*el0)->type != IS_OBJECT || (*el1)->type != IS_STRING))) {
+                    php_error(E_USER_WARNING,
+                              "PEAR::setErrorHandler: invalid error callback");
+                }
+                memcpy(tmp, *options, sizeof(zval));
+                ZEND_SET_SYMBOL(symtab, optionsname, tmp);
+            }
+            break;
+
+        default:
+            php_error(E_USER_WARNING,
+                      "PEAR::setErrorHandler: invalid error mode");
+            break;
+    }
+
 }
 
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to