iliaa Sat Jan 18 15:09:32 2003 EDT
Modified files:
/php4/ext/mbstring php_mbregex.c mbstring.c
Log:
Removed pointless memory allocation checks.
Index: php4/ext/mbstring/php_mbregex.c
diff -u php4/ext/mbstring/php_mbregex.c:1.26 php4/ext/mbstring/php_mbregex.c:1.27
--- php4/ext/mbstring/php_mbregex.c:1.26 Tue Dec 31 11:06:53 2002
+++ php4/ext/mbstring/php_mbregex.c Sat Jan 18 15:09:29 2003
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_mbregex.c,v 1.26 2002/12/31 16:06:53 sebastian Exp $ */
+/* $Id: php_mbregex.c,v 1.27 2003/01/18 20:09:29 iliaa Exp $ */
#ifdef HAVE_CONFIG_H
@@ -238,20 +238,15 @@
rc->options != options || rc->mbctype != mbctype) {
memset(pre, 0, sizeof(*pre));
pre->fastmap = (char*)emalloc((1 << MBRE_BYTEWIDTH)*sizeof(char));
- if (pre->fastmap) {
- pre->options = options;
- pre->mbctype = mbctype;
- err_str = mbre_compile_pattern(pattern, patlen, pre);
- if (!err_str) {
- zend_hash_update(&MBSTRG(ht_rc), (char *) pattern,
patlen+1, (void *) pre, sizeof(*pre), NULL);
- } else {
- efree(pre->fastmap);
- pre->fastmap = (char*)0;
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "mbregex
compile err: %s", err_str);
- res = 1;
- }
+ pre->options = options;
+ pre->mbctype = mbctype;
+ err_str = mbre_compile_pattern(pattern, patlen, pre);
+ if (!err_str) {
+ zend_hash_update(&MBSTRG(ht_rc), (char *) pattern, patlen+1,
+(void *) pre, sizeof(*pre), NULL);
} else {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to
allocate memory in mbregex_compile_pattern");
+ efree(pre->fastmap);
+ pre->fastmap = (char*)0;
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "mbregex compile
+err: %s", err_str);
res = 1;
}
} else {
@@ -698,10 +693,6 @@
if (count == 0) count = 1;
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
-
/* create regex pattern buffer */
err = php_mbregex_compile_pattern(
&re,
@@ -712,6 +703,8 @@
RETURN_FALSE;
}
+ array_init(return_value);
+
pos = 0;
err = 0;
/* churn through str, generating array entries as we go */
@@ -895,29 +888,23 @@
}
switch (mode) {
case 1:
- if (array_init(return_value) != FAILURE) {
- beg = MBSTRG(search_regs)->beg[0];
- end = MBSTRG(search_regs)->end[0];
- add_next_index_long(return_value, beg);
- add_next_index_long(return_value, end - beg);
- } else {
- RETVAL_FALSE;
- }
+ array_init(return_value);
+ beg = MBSTRG(search_regs)->beg[0];
+ end = MBSTRG(search_regs)->end[0];
+ add_next_index_long(return_value, beg);
+ add_next_index_long(return_value, end - beg);
break;
case 2:
- if (array_init(return_value) != FAILURE) {
- n = MBSTRG(search_regs)->num_regs;
- for (i = 0; i < n; i++) {
- beg = MBSTRG(search_regs)->beg[i];
- end = MBSTRG(search_regs)->end[i];
- if (beg >= 0 && beg <= end && end <= len) {
- add_index_stringl(return_value, i,
(char *)&str[beg], end - beg, 1);
- } else {
- add_index_bool(return_value, i, 0);
- }
+ array_init(return_value);
+ n = MBSTRG(search_regs)->num_regs;
+ for (i = 0; i < n; i++) {
+ beg = MBSTRG(search_regs)->beg[i];
+ end = MBSTRG(search_regs)->end[i];
+ if (beg >= 0 && beg <= end && end <= len) {
+ add_index_stringl(return_value, i, (char
+*)&str[beg], end - beg, 1);
+ } else {
+ add_index_bool(return_value, i, 0);
}
- } else {
- RETVAL_FALSE;
}
break;
default:
Index: php4/ext/mbstring/mbstring.c
diff -u php4/ext/mbstring/mbstring.c:1.153 php4/ext/mbstring/mbstring.c:1.154
--- php4/ext/mbstring/mbstring.c:1.153 Tue Dec 31 11:06:52 2002
+++ php4/ext/mbstring/mbstring.c Sat Jan 18 15:09:29 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: mbstring.c,v 1.153 2002/12/31 16:06:52 sebastian Exp $ */
+/* $Id: mbstring.c,v 1.154 2003/01/18 20:09:29 iliaa Exp $ */
/*
* PHP4 Multibyte String module "mbstring"
@@ -820,13 +820,11 @@
n = php_mb_default_identify_list_size;
}
entry = (int *)emalloc(n*sizeof(int));
- if (entry != NULL) {
- MBSTRG(current_detect_order_list) = entry;
- MBSTRG(current_detect_order_list_size) = n;
- while (n > 0) {
- *entry++ = *list++;
- n--;
- }
+ MBSTRG(current_detect_order_list) = entry;
+ MBSTRG(current_detect_order_list_size) = n;
+ while (n > 0) {
+ *entry++ = *list++;
+ n--;
}
/* override original function. */
@@ -1031,9 +1029,7 @@
break;
case 'I':
case 'i':
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
+ array_init(return_value);
entry = MBSTRG(http_input_list);
n = MBSTRG(http_input_list_size);
while (n > 0) {
@@ -1133,9 +1129,7 @@
char *name;
if (ZEND_NUM_ARGS() == 0) {
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
+ array_init(return_value);
entry = MBSTRG(current_detect_order_list);
n = MBSTRG(current_detect_order_list_size);
while (n > 0) {
@@ -2463,9 +2457,6 @@
WRONG_PARAM_COUNT;
}
args = (pval ***)ecalloc(argc, sizeof(pval **));
- if (args == NULL) {
- RETURN_FALSE;
- }
if (zend_get_parameters_array_ex(argc, args) == FAILURE) {
efree((void *)args);
WRONG_PARAM_COUNT;
@@ -2508,96 +2499,9 @@
from_encoding = mbfl_no_encoding_invalid;
stack_max = PHP_MBSTR_STACK_BLOCK_SIZE;
stack = (pval ***)emalloc(stack_max*sizeof(pval **));
- if (stack != NULL) {
- stack_level = 0;
- identd = mbfl_encoding_detector_new(elist, elistsz TSRMLS_CC);
- if (identd != NULL) {
- n = 2;
- while (n < argc || stack_level > 0) {
- if (stack_level <= 0) {
- var = args[n++];
- if (Z_TYPE_PP(var) == IS_ARRAY ||
Z_TYPE_PP(var) == IS_OBJECT) {
- target_hash = HASH_OF(*var);
- if (target_hash != NULL) {
-
zend_hash_internal_pointer_reset(target_hash);
- }
- }
- } else {
- stack_level--;
- var = stack[stack_level];
- }
- if (Z_TYPE_PP(var) == IS_ARRAY ||
Z_TYPE_PP(var) == IS_OBJECT) {
- target_hash = HASH_OF(*var);
- if (target_hash != NULL) {
- while
(zend_hash_get_current_data(target_hash, (void **) &hash_entry) != FAILURE) {
-
zend_hash_move_forward(target_hash);
- if
(Z_TYPE_PP(hash_entry) == IS_ARRAY || Z_TYPE_PP(hash_entry) == IS_OBJECT) {
- if
(stack_level >= stack_max) {
-
stack_max += PHP_MBSTR_STACK_BLOCK_SIZE;
- ptmp =
erealloc(stack, sizeof(pval **)*stack_max);
- if
(ptmp == NULL) {
-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "stack err at %s:(%d)", __FILE__,
__LINE__);
-
continue;
- }
- stack
= (pval ***)ptmp;
- }
-
stack[stack_level] = var;
- stack_level++;
- var =
hash_entry;
- target_hash =
HASH_OF(*var);
- if
(target_hash != NULL) {
-
zend_hash_internal_pointer_reset(target_hash);
-
continue;
- }
- } else if
(Z_TYPE_PP(hash_entry) == IS_STRING) {
- string.val =
(unsigned char *)Z_STRVAL_PP(hash_entry);
- string.len =
Z_STRLEN_PP(hash_entry);
- if
(mbfl_encoding_detector_feed(identd, &string TSRMLS_CC)) {
- goto
detect_end; /* complete detecting */
- }
- }
- }
- }
- } else if (Z_TYPE_PP(var) == IS_STRING) {
- string.val = (unsigned char
*)Z_STRVAL_PP(var);
- string.len = Z_STRLEN_PP(var);
- if
(mbfl_encoding_detector_feed(identd, &string TSRMLS_CC)) {
- goto detect_end;
/* complete detecting */
- }
- }
- }
-detect_end:
- from_encoding = mbfl_encoding_detector_judge(identd
TSRMLS_CC);
- mbfl_encoding_detector_delete(identd TSRMLS_CC);
- }
- efree(stack);
- }
- if (from_encoding == mbfl_no_encoding_invalid) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to detect
encoding");
- from_encoding = mbfl_no_encoding_pass;
- }
- }
- if (elist != NULL) {
- efree((void *)elist);
- }
- /* create converter */
- convd = NULL;
- if (from_encoding != mbfl_no_encoding_pass) {
- convd = mbfl_buffer_converter_new(from_encoding, to_encoding, 0
TSRMLS_CC);
- if (convd == NULL) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create
converter");
- RETURN_FALSE;
- }
- mbfl_buffer_converter_illegal_mode(convd,
MBSTRG(current_filter_illegal_mode) TSRMLS_CC);
- mbfl_buffer_converter_illegal_substchar(convd,
MBSTRG(current_filter_illegal_substchar) TSRMLS_CC);
- }
-
- /* convert */
- if (convd != NULL) {
- stack_max = PHP_MBSTR_STACK_BLOCK_SIZE;
- stack = (pval ***)emalloc(stack_max*sizeof(pval **));
- if (stack != NULL) {
- stack_level = 0;
+ stack_level = 0;
+ identd = mbfl_encoding_detector_new(elist, elistsz TSRMLS_CC);
+ if (identd != NULL) {
n = 2;
while (n < argc || stack_level > 0) {
if (stack_level <= 0) {
@@ -2621,10 +2525,6 @@
if (stack_level >=
stack_max) {
stack_max +=
PHP_MBSTR_STACK_BLOCK_SIZE;
ptmp =
erealloc(stack, sizeof(pval **)*stack_max);
- if (ptmp ==
NULL) {
-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "stack err at %s:(%d)", __FILE__,
__LINE__);
-
continue;
- }
stack = (pval
***)ptmp;
}
stack[stack_level] =
var;
@@ -2638,11 +2538,8 @@
} else if
(Z_TYPE_PP(hash_entry) == IS_STRING) {
string.val = (unsigned
char *)Z_STRVAL_PP(hash_entry);
string.len =
Z_STRLEN_PP(hash_entry);
- ret =
mbfl_buffer_converter_feed_result(convd, &string, &result TSRMLS_CC);
- if (ret != NULL) {
-
STR_FREE(Z_STRVAL_PP(hash_entry));
-
Z_STRVAL_PP(hash_entry) = (char *)ret->val;
-
Z_STRLEN_PP(hash_entry) = ret->len;
+ if
+(mbfl_encoding_detector_feed(identd, &string TSRMLS_CC)) {
+ goto
+detect_end; /* complete detecting */
}
}
}
@@ -2650,16 +2547,100 @@
} else if (Z_TYPE_PP(var) == IS_STRING) {
string.val = (unsigned char *)Z_STRVAL_PP(var);
string.len = Z_STRLEN_PP(var);
- ret = mbfl_buffer_converter_feed_result(convd,
&string, &result TSRMLS_CC);
- if (ret != NULL) {
- STR_FREE(Z_STRVAL_PP(var));
- Z_STRVAL_PP(var) = (char *)ret->val;
- Z_STRLEN_PP(var) = ret->len;
+ if (mbfl_encoding_detector_feed(identd,
+&string TSRMLS_CC)) {
+ goto detect_end; /*
+complete detecting */
}
}
}
- efree(stack);
+detect_end:
+ from_encoding = mbfl_encoding_detector_judge(identd TSRMLS_CC);
+ mbfl_encoding_detector_delete(identd TSRMLS_CC);
}
+ efree(stack);
+
+ if (from_encoding == mbfl_no_encoding_invalid) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to detect
+encoding");
+ from_encoding = mbfl_no_encoding_pass;
+ }
+ }
+ if (elist != NULL) {
+ efree((void *)elist);
+ }
+ /* create converter */
+ convd = NULL;
+ if (from_encoding != mbfl_no_encoding_pass) {
+ convd = mbfl_buffer_converter_new(from_encoding, to_encoding, 0
+TSRMLS_CC);
+ if (convd == NULL) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to create
+converter");
+ RETURN_FALSE;
+ }
+ mbfl_buffer_converter_illegal_mode(convd,
+MBSTRG(current_filter_illegal_mode) TSRMLS_CC);
+ mbfl_buffer_converter_illegal_substchar(convd,
+MBSTRG(current_filter_illegal_substchar) TSRMLS_CC);
+ }
+
+ /* convert */
+ if (convd != NULL) {
+ stack_max = PHP_MBSTR_STACK_BLOCK_SIZE;
+ stack = (pval ***)emalloc(stack_max*sizeof(pval **));
+ stack_level = 0;
+ n = 2;
+ while (n < argc || stack_level > 0) {
+ if (stack_level <= 0) {
+ var = args[n++];
+ if (Z_TYPE_PP(var) == IS_ARRAY || Z_TYPE_PP(var) ==
+IS_OBJECT) {
+ target_hash = HASH_OF(*var);
+ if (target_hash != NULL) {
+
+zend_hash_internal_pointer_reset(target_hash);
+ }
+ }
+ } else {
+ stack_level--;
+ var = stack[stack_level];
+ }
+ if (Z_TYPE_PP(var) == IS_ARRAY || Z_TYPE_PP(var) == IS_OBJECT)
+{
+ target_hash = HASH_OF(*var);
+ if (target_hash != NULL) {
+ while (zend_hash_get_current_data(target_hash,
+(void **) &hash_entry) != FAILURE) {
+ zend_hash_move_forward(target_hash);
+ if (Z_TYPE_PP(hash_entry) == IS_ARRAY
+|| Z_TYPE_PP(hash_entry) == IS_OBJECT) {
+ if (stack_level >= stack_max) {
+ stack_max +=
+PHP_MBSTR_STACK_BLOCK_SIZE;
+ ptmp = erealloc(stack,
+sizeof(pval **)*stack_max);
+ stack = (pval ***)ptmp;
+ }
+ stack[stack_level] = var;
+ stack_level++;
+ var = hash_entry;
+ target_hash = HASH_OF(*var);
+ if (target_hash != NULL) {
+
+zend_hash_internal_pointer_reset(target_hash);
+ continue;
+ }
+ } else if (Z_TYPE_PP(hash_entry) ==
+IS_STRING) {
+ string.val = (unsigned char
+*)Z_STRVAL_PP(hash_entry);
+ string.len =
+Z_STRLEN_PP(hash_entry);
+ ret =
+mbfl_buffer_converter_feed_result(convd, &string, &result TSRMLS_CC);
+ if (ret != NULL) {
+
+STR_FREE(Z_STRVAL_PP(hash_entry));
+
+Z_STRVAL_PP(hash_entry) = (char *)ret->val;
+
+Z_STRLEN_PP(hash_entry) = ret->len;
+ }
+ }
+ }
+ }
+ } else if (Z_TYPE_PP(var) == IS_STRING) {
+ string.val = (unsigned char *)Z_STRVAL_PP(var);
+ string.len = Z_STRLEN_PP(var);
+ ret = mbfl_buffer_converter_feed_result(convd,
+&string, &result TSRMLS_CC);
+ if (ret != NULL) {
+ STR_FREE(Z_STRVAL_PP(var));
+ Z_STRVAL_PP(var) = (char *)ret->val;
+ Z_STRLEN_PP(var) = ret->len;
+ }
+ }
+ }
+ efree(stack);
+
mbfl_buffer_converter_delete(convd TSRMLS_CC);
}
@@ -2719,19 +2700,17 @@
i = zend_hash_num_elements(target_hash);
if (i > 0) {
convmap = (int *)emalloc(i*sizeof(int));
- if (convmap != NULL) {
- mapelm = convmap;
- mapsize = 0;
- while (i > 0) {
- if (zend_hash_get_current_data(target_hash,
(void **) &hash_entry) == FAILURE) {
- break;
- }
- convert_to_long_ex(hash_entry);
- *mapelm++ = Z_LVAL_PP(hash_entry);
- mapsize++;
- i--;
- zend_hash_move_forward(target_hash);
+ mapelm = convmap;
+ mapsize = 0;
+ while (i > 0) {
+ if (zend_hash_get_current_data(target_hash, (void **)
+&hash_entry) == FAILURE) {
+ break;
}
+ convert_to_long_ex(hash_entry);
+ *mapelm++ = Z_LVAL_PP(hash_entry);
+ mapsize++;
+ i--;
+ zend_hash_move_forward(target_hash);
}
}
}
@@ -2937,9 +2916,7 @@
convert_to_string_ex(type);
if (argc == 0 || !strcasecmp("all", Z_STRVAL_PP(type))) {
- if (array_init(return_value) == FAILURE) {
- RETURN_FALSE;
- }
+ array_init(return_value);
if ((name = (char
*)mbfl_no_encoding2name(MBSTRG(current_internal_encoding))) != NULL) {
add_assoc_string(return_value, "internal_encoding", name, 1);
}
@@ -3083,15 +3060,9 @@
list_size += strlen(name) + 1;
if (!list) {
list = (char*)emalloc(list_size);
- if (!list) {
- return -1;
- }
*list = (char)NULL;
} else {
list = (char*)erealloc(list, list_size);
- if (!list) {
- return -1;
- }
strcat(list, ",");
}
strcat(list, name);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php