]> granicus.if.org Git - php/commitdiff
Separate php_mb_reset() from php_mblen()
authorNikita Popov <nikic@php.net>
Wed, 3 Sep 2014 18:37:04 +0000 (20:37 +0200)
committerNikita Popov <nikic@php.net>
Wed, 3 Sep 2014 18:37:04 +0000 (20:37 +0200)
Instead of fighting against warnings ...

ext/standard/file.c
ext/standard/php_string.h
ext/standard/string.c

index 21f9a752e338c8a50c8a2e0019f3a97f23a92993..20a956df9d1fb8da160aea66055be3101cdea0f9 100644 (file)
@@ -1809,12 +1809,12 @@ static const char *php_fgetcsv_lookup_trailing_spaces(const char *ptr, size_t le
        unsigned char last_chars[2] = { 0, 0 };
 
        while (len > 0) {
-               inc_len = (*ptr == '\0' ? 1: php_mblen(ptr, len));
+               inc_len = (*ptr == '\0' ? 1 : php_mblen(ptr, len));
                switch (inc_len) {
                        case -2:
                        case -1:
                                inc_len = 1;
-                               php_ignore_value(php_mblen(NULL, 0));
+                               php_mb_reset();
                                break;
                        case 0:
                                goto quit_loop;
@@ -2070,7 +2070,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
        zend_bool first_field = 1;
 
        /* initialize internal state */
-       php_ignore_value(php_mblen(NULL, 0));
+       php_mb_reset();
 
        /* Now into new section that parses buf for delimiter/enclosure fields */
 
@@ -2096,7 +2096,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
 
                tptr = temp;
 
-               inc_len = (bptr < limit ? (*bptr == '\0' ? 1: php_mblen(bptr, limit - bptr)): 0);
+               inc_len = (bptr < limit ? (*bptr == '\0' ? 1 : php_mblen(bptr, limit - bptr)): 0);
                if (inc_len == 1) {
                        char *tmp = bptr;
                        while ((*tmp != delimiter) && isspace((int)*(unsigned char *)tmp)) {
@@ -2185,7 +2185,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
 
                                        case -2:
                                        case -1:
-                                               php_ignore_value(php_mblen(NULL, 0));
+                                               php_mb_reset();
                                                /* break is omitted intentionally */
                                        case 1:
                                                /* we need to determine if the enclosure is
@@ -2240,7 +2240,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
                                                }
                                                break;
                                }
-                               inc_len = (bptr < limit ? (*bptr == '\0' ? 1: php_mblen(bptr, limit - bptr)): 0);
+                               inc_len = (bptr < limit ? (*bptr == '\0' ? 1 : php_mblen(bptr, limit - bptr)): 0);
                        }
 
                quit_loop_2:
@@ -2253,7 +2253,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
                                        case -2:
                                        case -1:
                                                inc_len = 1;
-                                               php_ignore_value(php_mblen(NULL, 0));
+                                               php_mb_reset();
                                                /* break is omitted intentionally */
                                        case 1:
                                                if (*bptr == delimiter) {
@@ -2264,7 +2264,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
                                                break;
                                }
                                bptr += inc_len;
-                               inc_len = (bptr < limit ? (*bptr == '\0' ? 1: php_mblen(bptr, limit - bptr)): 0);
+                               inc_len = (bptr < limit ? (*bptr == '\0' ? 1 : php_mblen(bptr, limit - bptr)): 0);
                        }
 
                quit_loop_3:
@@ -2284,7 +2284,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
                                        case -2:
                                        case -1:
                                                inc_len = 1;
-                                               php_ignore_value(php_mblen(NULL, 0));
+                                               php_mb_reset();
                                                /* break is omitted intentionally */
                                        case 1:
                                                if (*bptr == delimiter) {
@@ -2295,7 +2295,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
                                                break;
                                }
                                bptr += inc_len;
-                               inc_len = (bptr < limit ? (*bptr == '\0' ? 1: php_mblen(bptr, limit - bptr)): 0);
+                               inc_len = (bptr < limit ? (*bptr == '\0' ? 1 : php_mblen(bptr, limit - bptr)): 0);
                        }
                quit_loop_4:
                        memcpy(tptr, hunk_begin, bptr - hunk_begin);
index e0ffff5e23fbbd87e23d09fc0fccd9299c6591af..bb173ee85a5be36b7fe9b51cf6bc042a2f7d3fae 100644 (file)
@@ -154,12 +154,13 @@ PHPAPI char *php_strerror(int errnum);
 
 #ifndef HAVE_MBLEN
 # define php_mblen(ptr, len) 1
+# define php_mb_reset()
+#elif defined(_REENTRANT) && defined(HAVE_MBRLEN) && defined(HAVE_MBSTATE_T)
+# define php_mblen(ptr, len) ((int) mbrlen(ptr, len, &BG(mblen_state)))
+# define php_mb_reset() memset(&BG(mblen_state), 0, sizeof(BG(mblen_state)))
 #else
-# if defined(_REENTRANT) && defined(HAVE_MBRLEN) && defined(HAVE_MBSTATE_T)
-#  define php_mblen(ptr, len) ((ptr) == NULL ? memset(&BG(mblen_state), 0, sizeof(BG(mblen_state))): (int)mbrlen(ptr, len, &BG(mblen_state)))
-# else
-#  define php_mblen(ptr, len) mblen(ptr, len)
-# endif
+# define php_mblen(ptr, len) mblen(ptr, len)
+# define php_mb_reset() mblen(NULL, 0)
 #endif
 
 void register_string_constants(INIT_FUNC_ARGS);
index a85a73fe6a8df44363c58671b0e656dbe0d6f4f6..0c41249473e514798b05c3e4bde44b2f13dfaba2 100644 (file)
@@ -1410,13 +1410,13 @@ PHPAPI zend_string *php_basename(const char *s, size_t len, char *suffix, size_t
        cnt = len;
        state = 0;
        while (cnt > 0) {
-               inc_len = (*c == '\0' ? 1: php_mblen(c, cnt));
+               inc_len = (*c == '\0' ? 1 : php_mblen(c, cnt));
 
                switch (inc_len) {
                        case -2:
                        case -1:
                                inc_len = 1;
-                               php_ignore_value(php_mblen(NULL, 0));
+                               php_mb_reset();
                                break;
                        case 0:
                                goto quit_loop;