cvs: php4 /ext/mbstring mbstring.c mbstring.h

From: Date: Fri, 12 Apr 2002 16:17:16 +0000
Subject: cvs: php4 /ext/mbstring mbstring.c mbstring.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-11086@lists.php.net to get a copy of this message
helly Fri Apr 12 12:17:16 2002 EDT Modified files: /php4/ext/mbstring mbstring.c mbstring.h Log: -new function php_mb_check_encoding_list -mark module globals as const (thread safety) Index: php4/ext/mbstring/mbstring.c diff -u php4/ext/mbstring/mbstring.c:1.60 php4/ext/mbstring/mbstring.c:1.61 --- php4/ext/mbstring/mbstring.c:1.60 Fri Apr 12 10:24:54 2002 +++ php4/ext/mbstring/mbstring.c Fri Apr 12 12:17:15 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mbstring.c,v 1.60 2002/04/12 14:24:54 helly Exp $ */ +/* $Id: mbstring.c,v 1.61 2002/04/12 16:17:15 helly Exp $ */ /* * PHP4 Multibyte String module "mbstring" (currently only for Japanese) @@ -71,7 +71,7 @@ #include "mbregex.h" #endif -static enum mbfl_no_encoding php_mbstr_default_identify_list[] = { +static const enum mbfl_no_encoding php_mbstr_default_identify_list[] = { mbfl_no_encoding_ascii, mbfl_no_encoding_jis, mbfl_no_encoding_utf8, @@ -79,7 +79,7 @@ mbfl_no_encoding_sjis }; -static int php_mbstr_default_identify_list_size = sizeof(php_mbstr_default_identify_list)/sizeof(enum mbfl_no_encoding); +static const int php_mbstr_default_identify_list_size = sizeof(php_mbstr_default_identify_list)/sizeof(enum mbfl_no_encoding); static unsigned char third_and_rest_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE_REST }; static unsigned char second_args_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE }; @@ -233,6 +233,10 @@ list = NULL; if (value == NULL || value_length <= 0) { + if (return_list) + *return_list = NULL; + if (return_size) + *return_size = 0; return 0; } else { /* copy the value string for work */ @@ -277,7 +281,7 @@ if (!bauto) { bauto = 1; l = php_mbstr_default_identify_list_size; - src = php_mbstr_default_identify_list; + src = (int*)php_mbstr_default_identify_list; while (l > 0) { *entry++ = *src++; l--; @@ -292,24 +296,38 @@ } p1 = p2 + 1; } while (n < size && p2 != NULL); - if (n > 0){ - *return_list = list; - *return_size = n; + if (n > 0) { + if (return_list) + *return_list = list; + else + pefree(list, persistent); } else { - efree(list); - *return_list = NULL; + pefree(list, persistent); + if (return_list) + *return_list = NULL; + ret = 0; } + if (return_size) + *return_size = n; + } else { + if (return_list) + *return_list = NULL; + if (return_size) + *return_size = 0; + ret = 0; } efree(tmpstr); } - if (list == NULL) { - return 0; - } - return ret; } +/* {{{ php_mb_check_encoding_list */ +PHPAPI int php_mb_check_encoding_list(const char *encoding_list TSRMLS_DC) { + return php_mbstring_parse_encoding_list(encoding_list, strlen(encoding_list), NULL, NULL, 0); +} +/* }}} */ + /* Return 0 if input contains any illegal encoding, otherwise 1. * Even if any illegal encoding is detected the result may contain a list * of parsed encodings. @@ -343,7 +361,7 @@ if (!bauto) { bauto = 1; l = php_mbstr_default_identify_list_size; - src = php_mbstr_default_identify_list; + src = (int*)php_mbstr_default_identify_list; while (l > 0) { *entry++ = *src++; l--; @@ -360,19 +378,27 @@ i--; } if (n > 0) { - *return_list = list; - *return_size = n; + if (return_list) + *return_list = list; + else + pefree(list, persistent); } else { - efree(list); - *return_list = NULL; + pefree(list, persistent); + if (return_list) + *return_list = NULL; + ret = 0; } + if (return_size) + *return_size = n; + } else { + if (return_list) + *return_list = NULL; + if (return_size) + *return_size = 0; + ret = 0; } } - if (list == NULL) { - return 0; - } - return ret; } @@ -594,7 +620,7 @@ n = MBSTRG(detect_order_list_size); } if (n <= 0) { - list = php_mbstr_default_identify_list; + list = (int*)php_mbstr_default_identify_list; n = php_mbstr_default_identify_list_size; } entry = (int *)emalloc(n*sizeof(int)); Index: php4/ext/mbstring/mbstring.h diff -u php4/ext/mbstring/mbstring.h:1.17 php4/ext/mbstring/mbstring.h:1.18 --- php4/ext/mbstring/mbstring.h:1.17 Wed Apr 10 08:47:41 2002 +++ php4/ext/mbstring/mbstring.h Fri Apr 12 12:17:16 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mbstring.h,v 1.17 2002/04/10 12:47:41 hirokawa Exp $ */ +/* $Id: mbstring.h,v 1.18 2002/04/12 16:17:16 helly Exp $ */ /* * PHP4 Multibyte String module "mbstring" (currently only for Japanese) @@ -58,6 +58,7 @@ #define PHP_MBSTRING_API 20020405 PHPAPI char * php_mb_convert_encoding(char *input, size_t length, char *_to_encoding, char *_from_encodings, size_t *output_len TSRMLS_DC); +PHPAPI int php_mb_check_encoding_list(const char *encoding_list TSRMLS_DC); #if HAVE_MBREGEX #include "mbregex.h"

« previous php.cvs (#11086) next »