cvs: ZendEngine2 / zend.c zend.h

[email protected] ("Dmitry Stogov") Wed, 18 Feb 2009 10:55:23 -0000
Newsgroups php.zend-engine.cvs
Message-ID <cvsdmitry1234954523@cvsserver>
dmitry		Wed Feb 18 10:55:23 2009 UTC

  Modified files:              
    /ZendEngine2	zend.c zend.h 
  Log:
  Fixed zend_print_zval_r_ex() to use the write callback function
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend.c?r1=1.428&r2=1.429&diff_format=u
Index: ZendEngine2/zend.c
diff -u ZendEngine2/zend.c:1.428 ZendEngine2/zend.c:1.429
--- ZendEngine2/zend.c:1.428	Fri Jan  2 13:14:16 2009
+++ ZendEngine2/zend.c	Wed Feb 18 10:55:23 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend.c,v 1.428 2009/01/02 13:14:16 helly Exp $ */
+/* $Id: zend.c,v 1.429 2009/02/18 10:55:23 dmitry Exp $ */
 
 #include "zend.h"
 #include "zend_extensions.h"
@@ -225,7 +225,7 @@
 #define ZEND_CORE_VERSION_INFO	"Zend Engine v" ZEND_VERSION ", Copyright (c) 1998-2009 Zend Technologies\n"
 #define PRINT_ZVAL_INDENT 4
 
-static void print_hash(HashTable *ht, int indent, zend_bool is_object TSRMLS_DC) /* {{{ */
+static void print_hash(zend_write_func_t write_func, HashTable *ht, int indent, zend_bool is_object TSRMLS_DC) /* {{{ */
 {
 	zval **tmp;
 	zstr string_key;
@@ -236,18 +236,18 @@
 	zend_uchar ztype;
 
 	for (i = 0; i < indent; i++) {
-		ZEND_PUTS(" ");
+		ZEND_PUTS_EX(" ");
 	}
-	ZEND_PUTS("(\n");
+	ZEND_PUTS_EX("(\n");
 	indent += PRINT_ZVAL_INDENT;
 	zend_hash_internal_pointer_reset_ex(ht, &iterator);
 	while (zend_hash_get_current_data_ex(ht, (void **) &tmp, &iterator) == SUCCESS) {
 		zend_uchar key_type;
 
 		for (i = 0; i < indent; i++) {
-			ZEND_PUTS(" ");
+			ZEND_PUTS_EX(" ");
 		}
-		ZEND_PUTS("[");
+		ZEND_PUTS_EX("[");
 		switch ((key_type = zend_hash_get_current_key_ex(ht, &string_key, &str_len, &num_key, 0, &iterator))) {
 			case HASH_KEY_IS_STRING:
 				ztype = IS_STRING;
@@ -260,33 +260,83 @@
 
 					int mangled = zend_u_unmangle_property_name(ztype, string_key, str_len - 1, &class_name, &prop_name);
 
+					if (ztype == IS_UNICODE) {
+						UConverter *conv = ZEND_U_CONVERTER(UG(output_encoding_conv));
+						UErrorCode status = U_ZERO_ERROR;
+						char *s = NULL;
+						int s_len;
+
+						zend_unicode_to_string_ex(conv, &s, &s_len, prop_name.u, u_strlen(prop_name.u), &status);
+						if (U_FAILURE(status)) {
+							zend_error(E_WARNING, "Could not convert Unicode to printable form");
+							return;
+						}
+						ZEND_WRITE_EX(s, s_len);
+						efree(s);
+					} else {
+						ZEND_PUTS_EX(prop_name.s);
+					}
 					if (class_name.v && mangled == SUCCESS) {
 						if (class_name.s[0]=='*') {
-							zend_printf("%R:protected", ztype, prop_name);
+							ZEND_PUTS_EX(":protected");
 						} else {
-							zend_printf("%R:%v:private", ztype, prop_name, class_name);
+							ZEND_PUTS_EX(":");
+							if (UG(unicode)) {
+								UConverter *conv = ZEND_U_CONVERTER(UG(output_encoding_conv));
+								UErrorCode status = U_ZERO_ERROR;
+								char *s = NULL;
+								int s_len;
+
+								zend_unicode_to_string_ex(conv, &s, &s_len, class_name.u, u_strlen(class_name.u), &status);
+								if (U_FAILURE(status)) {
+									zend_error(E_WARNING, "Could not convert Unicode to printable form");
+									return;
+								}
+								ZEND_WRITE_EX(s, s_len);
+								efree(s);
+							} else {
+								ZEND_PUTS_EX(class_name.s);
+							}
+							ZEND_PUTS_EX(":private");
 						}
-					} else {
-						zend_printf("%R", ztype, prop_name);
 					}
 				} else {
-					zend_printf("%R", ztype, string_key);
+					if (ztype == IS_UNICODE) {
+						UConverter *conv = ZEND_U_CONVERTER(UG(output_encoding_conv));
+						UErrorCode status = U_ZERO_ERROR;
+						char *s = NULL;
+						int s_len;
+
+						zend_unicode_to_string_ex(conv, &s, &s_len, string_key.u, str_len-1, &status);
+						if (U_FAILURE(status)) {
+							zend_error(E_WARNING, "Could not convert Unicode to printable form");
+							return;
+						}
+						ZEND_WRITE_EX(s, s_len);
+						efree(s);
+					} else {
+						ZEND_WRITE_EX(string_key.s, str_len-1);
+					}
 				}
 				break;
 			case HASH_KEY_IS_LONG:
-				zend_printf("%ld", num_key);
+				{
+					char key[25];
+					snprintf(key, sizeof(key), "%ld", num_key);
+					ZEND_PUTS_EX(key);
+				}
 				break;
 		}
-		ZEND_PUTS("] => ");
-		zend_print_zval_r(*tmp, indent+PRINT_ZVAL_INDENT TSRMLS_CC);
-		ZEND_PUTS("\n");
+		ZEND_PUTS_EX("] => ");
+		zend_print_zval_r_ex(write_func, *tmp, indent+PRINT_ZVAL_INDENT TSRMLS_CC);
+		ZEND_PUTS_EX("\n");
 		zend_hash_move_forward_ex(ht, &iterator);
 	}
 	indent -= PRINT_ZVAL_INDENT;
 	for (i = 0; i < indent; i++) {
-		ZEND_PUTS(" ");
+		ZEND_PUTS_EX(" ");
 	}
-	ZEND_PUTS(")\n");
+	ZEND_PUTS_EX(")\n");
 }
 /* }}} */
 
@@ -581,13 +631,13 @@
 {
 	switch (Z_TYPE_P(expr)) {
 		case IS_ARRAY:
-			ZEND_PUTS("Array\n");
+			ZEND_PUTS_EX("Array\n");
 			if (++Z_ARRVAL_P(expr)->nApplyCount>1) {
-				ZEND_PUTS(" *RECURSION*");
+				ZEND_PUTS_EX(" *RECURSION*");
 				Z_ARRVAL_P(expr)->nApplyCount--;
 				return;
 			}
-			print_hash(Z_ARRVAL_P(expr), indent, 0 TSRMLS_CC);
+			print_hash(write_func, Z_ARRVAL_P(expr), indent, 0 TSRMLS_CC);
 			Z_ARRVAL_P(expr)->nApplyCount--;
 			break;
 		case IS_OBJECT:
@@ -601,10 +651,26 @@
 					Z_OBJ_HANDLER_P(expr, get_class_name)(expr, &class_name, &clen, 0 TSRMLS_CC);
 				}
 				if (class_name.v) {
-					zend_printf("%v Object\n", class_name.v);
+					if (UG(unicode)) {
+						UConverter *conv = ZEND_U_CONVERTER(UG(output_encoding_conv));
+						UErrorCode status = U_ZERO_ERROR;
+						char *s = NULL;
+						int s_len;
+
+						zend_unicode_to_string_ex(conv, &s, &s_len, class_name.u, clen, &status);
+						if (U_FAILURE(status)) {
+							zend_error(E_WARNING, "Could not convert Unicode to printable form");
+							return;
+						}
+						ZEND_WRITE_EX(s, s_len);
+						efree(s);
+					} else {
+						ZEND_PUTS_EX(class_name.s);
+					}
 				} else {
-					zend_printf("%s Object\n", "Unknown Class");
+					ZEND_PUTS_EX("Unknown Class");
 				}
+				ZEND_PUTS_EX(" Object\n");
 				if (class_name.v) {
 					efree(class_name.v);
 				}
@@ -612,11 +678,11 @@
 					break;
 				}
 				if (++properties->nApplyCount>1) {
-					ZEND_PUTS(" *RECURSION*");
+					ZEND_PUTS_EX(" *RECURSION*");
 					properties->nApplyCount--;
 					return;
 				}
-				print_hash(properties, indent, 1 TSRMLS_CC);
+				print_hash(write_func, properties, indent, 1 TSRMLS_CC);
 				properties->nApplyCount--;
 				if (is_temp) {
 					zend_hash_destroy(properties);
@@ -625,7 +691,7 @@
 				break;
 			}
 		default:
-			zend_print_variable(expr);
+			zend_print_zval_ex(write_func, expr, indent);
 			break;
 	}
 }
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend.h?r1=1.364&r2=1.365&diff_format=u
Index: ZendEngine2/zend.h
diff -u ZendEngine2/zend.h:1.364 ZendEngine2/zend.h:1.365
--- ZendEngine2/zend.h:1.364	Wed Dec 31 11:12:28 2008
+++ ZendEngine2/zend.h	Wed Feb 18 10:55:23 2009
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend.h,v 1.364 2008/12/31 11:12:28 sebastian Exp $ */
+/* $Id: zend.h,v 1.365 2009/02/18 10:55:23 dmitry Exp $ */
 
 #ifndef ZEND_H
 #define ZEND_H
@@ -653,7 +653,9 @@
 
 /* output support */
 #define ZEND_WRITE(str, str_len)		zend_write((str), (str_len))
+#define ZEND_WRITE_EX(str, str_len)		write_func((str), (str_len))
 #define ZEND_PUTS(str)					zend_write((str), strlen((str)))
+#define ZEND_PUTS_EX(str)				write_func((str), strlen((str)))
 #define ZEND_PUTC(c)					zend_write(&(c), 1), (c)
 
 BEGIN_EXTERN_C()