Commit:    289bb339c9e722ff3017ec58fdef7300f39b8e6d
Author:    Remi Collet <r...@php.net>         Sun, 25 Nov 2012 08:14:23 +0100
Parents:   8d2c44b59dfc6c5c608121546edac5840def3f9a
Branches:  PHP-5.4

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=289bb339c9e722ff3017ec58fdef7300f39b8e6d

Log:
Fixed bug #63588 Duplicate implementation of php_next_utf8_char

Json use an utf8 parser from a third party library, switch to
our implementation of php_next_utf8_char.
This also helps on solving #63520. All the unit tests succeed.
Our implementation also seems a little faster.

json.dsp need to be regenerated.

Bugs:
https://bugs.php.net/63588
https://bugs.php.net/63520

Changed paths:
  M  NEWS
  M  ext/json/config.m4
  M  ext/json/config.w32
  M  ext/json/json.c
  D  ext/json/utf8_to_utf16.c
  D  ext/json/utf8_to_utf16.h


Diff:
diff --git a/NEWS b/NEWS
index 4dde872..d55c467 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,10 @@ PHP                                                            
            NEWS
 - Imap:
   . Fixed Bug #63126 DISABLE_AUTHENTICATOR ignores array (Remi)
 
+- Json:
+  . Fixed bug #63588 use php_next_utf8_char and remove duplicate
+    implementation. (Remi)
+
 - mysqli:
   . Fixed bug #63361 missing header. (Remi)
 
diff --git a/ext/json/config.m4 b/ext/json/config.m4
index b62e938..26c43a0 100644
--- a/ext/json/config.m4
+++ b/ext/json/config.m4
@@ -9,7 +9,7 @@ if test "$PHP_JSON" != "no"; then
   AC_DEFINE([HAVE_JSON],1 ,[whether to enable JavaScript Object Serialization 
support])
   AC_HEADER_STDC
 
-  PHP_NEW_EXTENSION(json, json.c utf8_to_utf16.c utf8_decode.c JSON_parser.c, 
$ext_shared)
+  PHP_NEW_EXTENSION(json, json.c utf8_decode.c JSON_parser.c, $ext_shared)
   PHP_INSTALL_HEADERS([ext/json], [php_json.h])
   PHP_SUBST(JSON_SHARED_LIBADD)
 fi
diff --git a/ext/json/config.w32 b/ext/json/config.w32
index 06a48e0..cedbf42 100644
--- a/ext/json/config.w32
+++ b/ext/json/config.w32
@@ -5,7 +5,7 @@ ARG_ENABLE("json", "JavaScript Object Serialization support", 
"yes");
 
 if (PHP_JSON != "no") {
        EXTENSION('json', 'json.c', PHP_JSON_SHARED, "");
-       ADD_SOURCES(configure_module_dirname, "JSON_parser.c utf8_decode.c 
utf8_to_utf16.c", "json");
+       ADD_SOURCES(configure_module_dirname, "JSON_parser.c utf8_decode.c", 
"json");
        PHP_INSTALL_HEADERS("ext/json/", "php_json.h");
 }
 
diff --git a/ext/json/json.c b/ext/json/json.c
index 786b21a..270c7cb 100644
--- a/ext/json/json.c
+++ b/ext/json/json.c
@@ -25,8 +25,8 @@
 #include "php.h"
 #include "php_ini.h"
 #include "ext/standard/info.h"
+#include "ext/standard/html.h"
 #include "ext/standard/php_smart_str.h"
-#include "utf8_to_utf16.h"
 #include "JSON_parser.h"
 #include "php_json.h"
 #include <zend_exceptions.h>
@@ -344,6 +344,32 @@ static void json_encode_array(smart_str *buf, zval **val, 
int options TSRMLS_DC)
 }
 /* }}} */
 
+static int json_utf8_to_utf16(unsigned short *utf16, char utf8[], int len) /* 
{{{ */
+{
+       size_t pos = 0, us;
+       int j, status;
+
+       for (j=0 ; pos < len ; j++) {
+               us = php_next_utf8_char((const unsigned char *)utf8, len, &pos, 
&status);
+               if (status != SUCCESS) {
+                       return -1;
+               }
+               if (utf16) {
+                       /* From http://en.wikipedia.org/wiki/UTF16 */
+                       if (us >= 0x10000) {
+                               us -= 0x10000;
+                               utf16[j++] = (unsigned short)((us >> 10) | 
0xd800);
+                               utf16[j] = (unsigned short)((us & 0x3ff) | 
0xdc00);
+                       } else {
+                               utf16[j] = (unsigned short)us;
+                       }
+               }
+       }
+       return j;
+}
+/* }}} */
+
+
 #define REVERSE16(us) (((us & 0xf) << 12) | (((us >> 4) & 0xf) << 8) | (((us 
>> 8) & 0xf) << 4) | ((us >> 12) & 0xf))
 
 static void json_escape_string(smart_str *buf, char *s, int len, int options 
TSRMLS_DC) /* {{{ */
@@ -383,7 +409,7 @@ static void json_escape_string(smart_str *buf, char *s, int 
len, int options TSR
        }
 
        utf16 = (options & PHP_JSON_UNESCAPED_UNICODE) ? NULL : (unsigned short 
*) safe_emalloc(len, sizeof(unsigned short), 0);
-       ulen = utf8_to_utf16(utf16, s, len);
+       ulen = json_utf8_to_utf16(utf16, s, len);
        if (ulen <= 0) {
                if (utf16) {
                        efree(utf16);
@@ -628,7 +654,7 @@ PHP_JSON_API void php_json_decode_ex(zval *return_value, 
char *str, int str_len,
 
        utf16 = (unsigned short *) safe_emalloc((str_len+1), sizeof(unsigned 
short), 1);
 
-       utf16_len = utf8_to_utf16(utf16, str, str_len);
+       utf16_len = json_utf8_to_utf16(utf16, str, str_len);
        if (utf16_len <= 0) {
                if (utf16) {
                        efree(utf16);
diff --git a/ext/json/utf8_to_utf16.c b/ext/json/utf8_to_utf16.c
deleted file mode 100644
index 508bc93..0000000
--- a/ext/json/utf8_to_utf16.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* utf8_to_utf16.c */
-
-/* 2005-12-25 */
-
-/*
-Copyright (c) 2005 JSON.org
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
-
-#include "utf8_to_utf16.h"
-#include "utf8_decode.h"
-
-int 
-utf8_to_utf16(unsigned short *w, char p[], int length) 
-{
-    int c;
-    int the_index = 0;
-    json_utf8_decode utf8;
-    
-    utf8_decode_init(&utf8, p, length);
-    for (;;) {
-        c = utf8_decode_next(&utf8);
-        if (c < 0) {
-            return (c == UTF8_END) ? the_index : UTF8_ERROR;
-        }
-        if (c < 0x10000) {
-            if (w) {
-                w[the_index] = (unsigned short)c;
-            }
-            the_index += 1;
-        } else {
-            c -= 0x10000;
-            if (w) {
-                w[the_index] = (unsigned short)(0xD800 | (c >> 10));
-                w[the_index + 1] = (unsigned short)(0xDC00 | (c & 0x3FF));
-            }
-            the_index += 2;
-        }
-    }
-}
diff --git a/ext/json/utf8_to_utf16.h b/ext/json/utf8_to_utf16.h
deleted file mode 100644
index 5c9685a..0000000
--- a/ext/json/utf8_to_utf16.h
+++ /dev/null
@@ -1,3 +0,0 @@
-/* utf8_to_utf16.h */
-
-extern int utf8_to_utf16(unsigned short *w, char p[], int length);


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

Reply via email to