My code is just as bad, but I remember that it used to work:

PHP_FUNCTION(jtemplate_set_root)
{
        zval **z_root_dir;
        char *root_dir = NULL;
        int argc = ZEND_NUM_ARGS();
        zval func;
        zval *retval = NULL;
        zval *args[1];
        
        if (argc < 0 || argc > 1 ||
                zend_get_parameters_ex(argc, &z_root_dir) == FAILURE) {
                WRONG_PARAM_COUNT;
        }
        if (argc > 0) {
                convert_to_string_ex(z_root_dir);
                root_dir = estrndup(Z_STRVAL_PP(z_root_dir), 
Z_STRLEN_PP(z_root_dir));
        } else {
                root_dir = estrndup(".", sizeof(".") - 1);
        }

        INIT_ZVAL(func);
        ZVAL_STRING(&func, "is_dir", 1);
        MAKE_STD_ZVAL(args[0]);
        ZVAL_STRING(args[0], root_dir, 1);
        MAKE_STD_ZVAL(retval);
        /* check to see if the directory really exists and that is a real 
directory */
        if (call_user_function(EG(function_table), NULL, &func, retval, 1, 
args TSRMLS_CC) == FAILURE) {
                zend_error(E_ERROR, "%s(): could not call is_dir().", 
get_active_function_name(TSRMLS_C));
        }
        if (Z_TYPE_P(retval) == IS_BOOL && Z_LVAL_P(retval) == 0) {
                ZVAL_STRING(&func, "halt", 1);
                ZVAL_STRING(args[0], "no such directory", 1);
                call_user_function(NULL, &getThis(), &func, retval, 1, 
args TSRMLS_CC);
                zval_dtor(&func);
        }
        efree(root_dir);
        zval_dtor(retval);
        zval_ptr_dtor(&args[0]);

        add_property_stringl(getThis(), "root", Z_STRVAL_PP(z_root_dir), 
Z_STRLEN_PP(z_root_dir), 1);

        ZEND_PUTS(get_active_function_name(TSRMLS_C));
        RETURN_TRUE;
}

Yes, this _is_ nasty ;)

Cheers,
Joao


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to