helly           Thu Feb  7 18:40:29 2008 UTC

  Modified files:              
    /php-src    README.UNICODE-UPGRADES 
    /php-src/main       snprintf.c spprintf.c 
  Log:
  - Add %Z to *printf
  
http://cvs.php.net/viewvc.cgi/php-src/README.UNICODE-UPGRADES?r1=1.18&r2=1.19&diff_format=u
Index: php-src/README.UNICODE-UPGRADES
diff -u php-src/README.UNICODE-UPGRADES:1.18 
php-src/README.UNICODE-UPGRADES:1.19
--- php-src/README.UNICODE-UPGRADES:1.18        Thu Feb  7 18:33:20 2008
+++ php-src/README.UNICODE-UPGRADES     Thu Feb  7 18:40:28 2008
@@ -540,6 +540,19 @@
     zend_error(E_WARNING, "%v::__toString() did not return anything",
             Z_OBJCE_P(object)->name);
 
+  %Z
+    This format prints a zval's value. You can specify the minimum length
+    of the string representation using "%*Z" as well as the absolute length
+    using "%.*Z". The following example is taken from the engine and
+    therefor uses zend_spprintf rather than spprintf. Further more clen is
+    an integer that is smaller than Z_UNILEN_P(callable).
+
+    zend_spprintf(error, 0, "class '%.*Z' not found", clen, callable);
+
+    The function allows to output any kind of zaval values, as long as a
+    string (or unicode) conversion is available. Note that printing non
+    string zvals outside of request time is not possible.
+
 Since [v]spprintf() can only output native strings there are also the new
 functions [v]uspprintf() and [v]zspprintf() that create unicode strings and
 return the number of characters printed. That is they return the length rather
http://cvs.php.net/viewvc.cgi/php-src/main/snprintf.c?r1=1.62&r2=1.63&diff_format=u
Index: php-src/main/snprintf.c
diff -u php-src/main/snprintf.c:1.62 php-src/main/snprintf.c:1.63
--- php-src/main/snprintf.c:1.62        Thu Feb  7 12:45:42 2008
+++ php-src/main/snprintf.c     Thu Feb  7 18:40:29 2008
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: snprintf.c,v 1.62 2008/02/07 12:45:42 helly Exp $ */
+/* $Id: snprintf.c,v 1.63 2008/02/07 18:40:29 helly Exp $ */
 
 
 #include "php.h"
@@ -573,17 +573,18 @@
  */
 static int format_converter(register buffy * odp, const char *fmt, va_list ap) 
/* {{{ */
 {
-       register char *sp;
-       register char *bep;
-       register int cc = 0;
-       register int i;
+       char *sp;
+       char *bep;
+       int cc = 0;
+       int i;
 
-       register char *s = NULL;
-       register UChar *u = NULL;
+       char *s = NULL;
+       UChar *u = NULL;
        char *q;
-       int s_len, s_unicode, u_len;
+       int s_len, s_unicode, u_len, free_zcopy;
+       zval *zvp, zcopy;
 
-       register int min_width = 0;
+       int min_width = 0;
        int precision = 0;
        enum {
                LEFT, RIGHT
@@ -631,6 +632,7 @@
                        pad_char = ' ';
                        prefix_char = NUL;
                        s_to_free = NULL;
+                       free_zcopy = 0;
                        s_unicode = 0;
 
                        fmt++;
@@ -778,6 +780,18 @@
                         *   It is reset to ' ' by non-numeric formats
                         */
                        switch (*fmt) {
+                               case 'Z':
+                                       zvp = (zval*) va_arg(ap, zval*);
+                                       zend_make_string_zval(zvp, &zcopy, 
&free_zcopy);
+                                       if (free_zcopy) {
+                                               zvp = &zcopy;
+                                       }
+                                       s_len = Z_UNILEN_P(zvp);
+                                       s = Z_STRVAL_P(zvp);
+                                       if (adjust_precision && precision < 
s_len) {
+                                               s_len = precision;
+                                       }
+                                       break;
                                case 'u':
                                        switch(modifier) {
                                                default:
@@ -1203,7 +1217,12 @@
                                s++;
                        }
 
-                       if (s_to_free) efree(s_to_free);
+                       if (s_to_free) {
+                               efree(s_to_free);
+                       }
+                       if (free_zcopy) {
+                               zval_dtor(&zcopy);
+                       }
 
                        if (adjust_width && adjust == LEFT && min_width > s_len)
                                PAD(min_width, s_len, pad_char);
http://cvs.php.net/viewvc.cgi/php-src/main/spprintf.c?r1=1.52&r2=1.53&diff_format=u
Index: php-src/main/spprintf.c
diff -u php-src/main/spprintf.c:1.52 php-src/main/spprintf.c:1.53
--- php-src/main/spprintf.c:1.52        Thu Feb  7 12:45:42 2008
+++ php-src/main/spprintf.c     Thu Feb  7 18:40:29 2008
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: spprintf.c,v 1.52 2008/02/07 12:45:42 helly Exp $ */
+/* $Id: spprintf.c,v 1.53 2008/02/07 18:40:29 helly Exp $ */
 
 /* This is the spprintf implementation.
  * It has emerged from apache snprintf. See original header:
@@ -214,12 +214,12 @@
  */
 static void xbuf_format_converter(int unicode, smart_str *xbuf, const char 
*fmt, va_list ap) /* {{{ */
 {
-       register char *s = NULL;
-       register UChar *u = NULL;
+       char *s = NULL;
+       UChar *u = NULL;
        char *q;
-       int s_len, s_unicode, u_len;
-
-       register int min_width = 0;
+       int s_len, s_unicode, u_len, free_zcopy;
+       zval *zvp, zcopy;
+       int min_width = 0;
        int precision = 0;
        enum {
                LEFT, RIGHT
@@ -232,7 +232,7 @@
        u_wide_int ui_num;
 
        char num_buf[NUM_BUF_SIZE];
-       char char_buf[2];                       /* for printing %% and 
%<unknown> */
+       char char_buf[2]; /* for printing %% and %<unknown> */
        zend_bool free_s; /* free string if allocated here */
 
 #ifdef HAVE_LOCALE_H
@@ -264,6 +264,7 @@
                        pad_char = ' ';
                        prefix_char = NUL;
                        free_s = 0;
+                       free_zcopy = 0;
                        s_unicode = 0;
 
                        fmt++;
@@ -411,6 +412,23 @@
                         *   It is reset to ' ' by non-numeric formats
                         */
                        switch (*fmt) {
+                               case 'Z':
+                                       zvp = (zval*) va_arg(ap, zval*);
+                                       if (unicode) {
+                                               zend_make_unicode_zval(zvp, 
&zcopy, &free_zcopy);
+                                               s_unicode = 1;
+                                       } else {
+                                               zend_make_string_zval(zvp, 
&zcopy, &free_zcopy);
+                                       }
+                                       if (free_zcopy) {
+                                               zvp = &zcopy;
+                                       }
+                                       s_len = Z_UNILEN_P(zvp);
+                                       s = Z_STRVAL_P(zvp);
+                                       if (adjust_precision && precision < 
s_len) {
+                                               s_len = precision;
+                                       }
+                                       break;
                                case 'u':
                                        switch(modifier) {
                                                default:
@@ -838,7 +856,12 @@
                         * Print the string s.
                         */
                        INS_STRING(unicode, s_unicode, xbuf, s, s_len);
-                       if (free_s) efree(s);
+                       if (free_s) {
+                               efree(s);
+                       }
+                       if (free_zcopy) {
+                               zval_dtor(&zcopy);
+                       }
 
                        if (adjust_width && adjust == LEFT && min_width > 
s_len) {
                                PAD(unicode, xbuf, min_width - s_len, pad_char);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to