Re-scope variables.

This commit is contained in:
Derick Rethans
2011-06-29 12:47:47 +01:00
parent 8bc1f0268b
commit e1663e8d0b
+26 -18
View File
@@ -366,6 +366,7 @@ PHP_FUNCTION(twig_template_get_attributes)
zval *object; zval *object;
zval *item; zval *item;
zval *arguments; zval *arguments;
zval *ret;
char *type = NULL; char *type = NULL;
int type_len = 0; int type_len = 0;
zend_bool isDefinedTest = 0; zend_bool isDefinedTest = 0;
@@ -437,6 +438,7 @@ PHP_FUNCTION(twig_template_get_attributes)
return false; return false;
} }
*/ */
if (!Z_TYPE_P(object) == IS_OBJECT) { if (!Z_TYPE_P(object) == IS_OBJECT) {
if (isDefinedTest) { if (isDefinedTest) {
RETURN_FALSE; RETURN_FALSE;
@@ -497,15 +499,16 @@ PHP_FUNCTION(twig_template_get_attributes)
} }
*/ */
if (strcmp("method", type) != 0) { if (strcmp("method", type) != 0) {
zval *tmp_self_cache, *tmp_class, *tmp_properties, *tmp_item, *tmp_object_item; zval *tmp_class, *tmp_properties, *tmp_item, *tmp_object_item = NULL;
tmp_self_cache = TWIG_GET_STATIC_PROPERTY(template, "cache");
tmp_class = TWIG_GET_ARRAY_ELEMENT(tmp_self_cache, class_name); tmp_class = TWIG_GET_ARRAY_ELEMENT(tmp_self_cache, class_name);
tmp_properties = TWIG_GET_ARRAY_ELEMENT(tmp_class, "properties"); tmp_properties = TWIG_GET_ARRAY_ELEMENT(tmp_class, "properties");
tmp_item = TWIG_GET_ARRAY_ELEMENT_ZVAL(tmp_properties, item); tmp_item = TWIG_GET_ARRAY_ELEMENT_ZVAL(tmp_properties, item);
convert_to_string(tmp_item);
if (tmp_item) {
convert_to_string(tmp_item);
tmp_object_item = TWIG_PROPERTY(object, Z_STRVAL_P(tmp_item)); tmp_object_item = TWIG_PROPERTY(object, Z_STRVAL_P(tmp_item));
}
if (tmp_item || tmp_object_item || TWIG_ARRAY_KEY_EXISTS(object, item) // FIXME: Array key? is that array access here? if (tmp_item || tmp_object_item || TWIG_ARRAY_KEY_EXISTS(object, item) // FIXME: Array key? is that array access here?
) { ) {
@@ -532,26 +535,26 @@ PHP_FUNCTION(twig_template_get_attributes)
} elseif (isset(self::$cache[$class]['methods']['__call'])) { } elseif (isset(self::$cache[$class]['methods']['__call'])) {
$method = $item; $method = $item;
*/ */
char *lsItem = TWIG_STRTOLOWER(item); {
char *lcItem = TWIG_STRTOLOWER_ZVAL(item);
char *method = NULL; char *method = NULL;
char *tmp_method_name_get = emalloc(4 + strlen(lsItem)); char *tmp_method_name_get = emalloc(4 + strlen(lcItem));
char *tmp_method_name_is = emalloc(3 + strlen(lsItem)); char *tmp_method_name_is = emalloc(3 + strlen(lcItem));
zval *tmp_class, *tmp_methods;
sprintf(tmp_method_name_get, "get%s", lsItem); sprintf(tmp_method_name_get, "get%s", lcItem);
sprintf(tmp_method_name_is, "is%s", lsItem); sprintf(tmp_method_name_is, "is%s", lcItem);
efree(lsItem);
zval *cache = TWIG_PROPERTY(template, "cache"); tmp_class = TWIG_GET_ARRAY_ELEMENT(tmp_self_cache, class_name);
zval *class = TWIG_PROPERTY(cache, "class"); tmp_methods = TWIG_GET_ARRAY_ELEMENT(tmp_class, "methods");
zval *methods = TWIG_PROPERTY(class, "methods");
if (TWIG_PROPERTY(methods, "lcItem")) { if (TWIG_PROPERTY(tmp_methods, lcItem)) {
method = Z_STRVAL_P(item); method = Z_STRVAL_P(item);
} else if (TWIG_PROPERTY(methods, tmp_method_name_get)) { } else if (TWIG_PROPERTY(tmp_methods, tmp_method_name_get)) {
method = tmp_method_name_get; method = tmp_method_name_get;
} else if (TWIG_PROPERTY(methods, tmp_method_name_is)) { } else if (TWIG_PROPERTY(tmp_methods, tmp_method_name_is)) {
method = tmp_method_name_is; method = tmp_method_name_is;
} else if (TWIG_PROPERTY(methods, "__call")) { } else if (TWIG_PROPERTY(tmp_methods, "__call")) {
method = Z_STRVAL_P(item); method = Z_STRVAL_P(item);
/* /*
} else { } else {
@@ -580,6 +583,7 @@ PHP_FUNCTION(twig_template_get_attributes)
if (isDefinedTest) { if (isDefinedTest) {
efree(tmp_method_name_get); efree(tmp_method_name_get);
efree(tmp_method_name_is); efree(tmp_method_name_is);
efree(lcItem);
RETURN_FALSE; RETURN_FALSE;
} }
/* /*
@@ -593,9 +597,11 @@ PHP_FUNCTION(twig_template_get_attributes)
/* /*
$ret = call_user_func_array(array($object, $method), $arguments); $ret = call_user_func_array(array($object, $method), $arguments);
*/ */
zval *ret = TWIG_CALL_USER_FUNC_ARRAY(object, method, arguments); ret = TWIG_CALL_USER_FUNC_ARRAY(object, method, arguments);
efree(tmp_method_name_get); efree(tmp_method_name_get);
efree(tmp_method_name_is); efree(tmp_method_name_is);
efree(lcItem);
}
/* /*
if ($object instanceof Twig_TemplateInterface) { if ($object instanceof Twig_TemplateInterface) {
return new Twig_Markup($ret); return new Twig_Markup($ret);
@@ -607,5 +613,7 @@ PHP_FUNCTION(twig_template_get_attributes)
/* /*
return $ret; return $ret;
*/ */
return_value = ret; // FIXME also wrong if (ret) {
RETVAL_ZVAL(ret, 0, 1);
}
} }