com php-src: Separate php_mb_reset() from php_mbl en(): ext/standard/file.c ext/standard/php_string .h ext/standard/string.c
| From: | Nikita Popov | Date: | Wed, 03 Sep 2014 18:37:04 +0000 |
| Subject: | com php-src: Separate php_mb_reset() from php_mbl en(): ext/standard/file.c ext/standard/php_string .h ext/standard/string.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-81413@lists.php.net to get a copy of this message | ||
Commit: 2b133e9149eca862c7d8c37f19d95e940970afec
Author: Nikita Popov <nikic@php.net> Wed, 3 Sep 2014 20:37:04 +0200
Parents: dd38c9e10132d5cb3b5df508985de627361e81f6
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2b133e9149eca862c7d8c37f19d95e940970afec
Log:
Separate php_mb_reset() from php_mblen()
Instead of fighting against warnings ...
Changed paths:
M ext/standard/file.c
M ext/standard/php_string.h
M ext/standard/string..c
Diff:
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 21f9a75..20a956d 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -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);
diff --git a/ext/standard/php_string.h b/ext/standard/php_string.h
index e0ffff5..bb173ee 100644
--- a/ext/standard/php_string.h
+++ b/ext/standard/php_string.h
@@ -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);
diff --git a/ext/standard/string.c b/ext/standard/string.c
index a85a73f..0c41249 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -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;