cvs: ZendEngine2 / zend.h zend_compile.c

From: Date: Tue, 15 Nov 2005 16:50:09 +0000
Subject: cvs: ZendEngine2 / zend.h zend_compile.c
Groups: php.zend-engine.cvs 
Request: Send a blank email to [email protected] to get a copy of this message
dmitry		Tue Nov 15 11:50:09 2005 EDT

  Modified files:              
    /ZendEngine2	zend.h zend_compile.c 
  Log:
  Allow "null" default value for arguments with array type hint
  Unicode support
  
  
http://cvs.php.net/diff.php/ZendEngine2/zend.h?r1=1.302&r2=1.303&ty=u
Index: ZendEngine2/zend.h
diff -u ZendEngine2/zend.h:1.302 ZendEngine2/zend.h:1.303
--- ZendEngine2/zend.h:1.302	Tue Nov 15 10:20:17 2005
+++ ZendEngine2/zend.h	Tue Nov 15 11:50:07 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend.h,v 1.302 2005/11/15 15:20:17 dmitry Exp $ */
+/* $Id: zend.h,v 1.303 2005/11/15 16:50:07 dmitry Exp $ */
 
 #ifndef ZEND_H
 #define ZEND_H
@@ -684,6 +684,7 @@
 	  (!memcmp((ustr),(str),(slen))): \
 	  (!zend_cmp_unicode_and_literal(((UChar*)(ustr)), ulen, str, slen)))
 
+
 #endif /* ZEND_H */
 
 /*
http://cvs.php.net/diff.php/ZendEngine2/zend_compile.c?r1=1.670&r2=1.671&ty=u
Index: ZendEngine2/zend_compile.c
diff -u ZendEngine2/zend_compile.c:1.670 ZendEngine2/zend_compile.c:1.671
--- ZendEngine2/zend_compile.c:1.670	Mon Oct 17 04:01:06 2005
+++ ZendEngine2/zend_compile.c	Tue Nov 15 11:50:07 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_compile.c,v 1.670 2005/10/17 08:01:06 dmitry Exp $ */
+/* $Id: zend_compile.c,v 1.671 2005/11/15 16:50:07 dmitry Exp $ */
 
 #include <zend_language_parser.h>
 #include "zend.h"
@@ -1301,6 +1301,19 @@
 }
 
 
+static inline int ZEND_U_CASE_EQUAL(zend_uchar type, void *ustr, int ulen, char *str, int slen)
+{
+	void* lcname;
+	unsigned int lcname_len;
+	int ret;
+
+	lcname = zend_u_str_case_fold(type, ustr, ulen, 0, &lcname_len);
+	ret = ZEND_U_EQUAL(type, lcname, lcname_len, str, slen);
+	efree(lcname);
+	return ret;
+}
+
+
 void zend_do_receive_arg(zend_uchar op, znode *var, znode *offset, znode *initialization, znode
*class_type, znode *varname, zend_uchar pass_by_reference TSRMLS_DC)
 {
 	zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
@@ -1329,13 +1342,15 @@
 	cur_arg_info->pass_by_reference = pass_by_reference;
 
 	if (class_type->op_type != IS_UNUSED) {
+		cur_arg_info->allow_null = 0;
 		if (class_type->u.constant.type == IS_STRING || class_type->u.constant.type == IS_UNICODE)
{
 			cur_arg_info->class_name = Z_UNIVAL(class_type->u.constant);
 			cur_arg_info->class_name_len = Z_UNILEN(class_type->u.constant);
-
-			/* FIXME: make this work for unicode=on too */
 			if (op == ZEND_RECV_INIT) {
-				if (Z_TYPE(initialization->u.constant) == IS_NULL || (Z_TYPE(initialization->u.constant)
== IS_CONSTANT && !strcasecmp(Z_STRVAL(initialization->u.constant), "NULL"))) {
+				if (Z_TYPE(initialization->u.constant) == IS_NULL ||
+				    (Z_TYPE(initialization->u.constant) == IS_CONSTANT &&
+				    Z_UNILEN(initialization->u.constant) == sizeof("null") - 1 &&
+				    ZEND_U_CASE_EQUAL(UG(unicode)?IS_UNICODE:IS_STRING,
Z_UNIVAL(initialization->u.constant), Z_UNILEN(initialization->u.constant), "null",
sizeof("null")-1))) {
 					cur_arg_info->allow_null = 1;
 				} else {
 					zend_error(E_COMPILE_ERROR, "Default value for parameters with a class type hint can only
be NULL");
@@ -1345,6 +1360,16 @@
 			cur_arg_info->array_type_hint = 1;
 			cur_arg_info->class_name = NULL;
 			cur_arg_info->class_name_len = 0;
+			if (op == ZEND_RECV_INIT) {
+				if (Z_TYPE(initialization->u.constant) == IS_NULL ||
+				    (Z_TYPE(initialization->u.constant) == IS_CONSTANT &&
+				    Z_UNILEN(initialization->u.constant) == sizeof("null") - 1 &&
+				    ZEND_U_CASE_EQUAL(UG(unicode)?IS_UNICODE:IS_STRING,
Z_UNIVAL(initialization->u.constant), Z_UNILEN(initialization->u.constant), "null",
sizeof("null")-1))) {
+					cur_arg_info->allow_null = 1;
+				} else if (Z_TYPE(initialization->u.constant) != IS_ARRAY &&
Z_TYPE(initialization->u.constant) != IS_CONSTANT_ARRAY) {
+					zend_error(E_COMPILE_ERROR, "Default value for parameters with array type hint can only
be an array or NULL");
+				}
+			}
 		}
 	} else {
 		cur_arg_info->class_name = NULL;


Thread (2 messages)

« previous php.zend-engine.cvs (#4337) next »