Refactor mbstring (incompleted)

This commit is contained in:
Xinchen Hui 2014-03-24 12:37:05 +08:00
parent 9011a70c7f
commit 506f6a4282
18 changed files with 436 additions and 413 deletions

View File

@ -691,6 +691,12 @@ END_EXTERN_C()
efree(ref); \
} while (0)
#define ZVAL_DEREF(z) do { \
if (Z_ISREF_P((z))) { \
(z) = Z_REFVAL_P((z)); \
} \
} while (0)
// TODO: invalud ???
#define INIT_PZVAL_COPY(z, v) \
do { \

File diff suppressed because it is too large Load Diff

View File

@ -980,10 +980,13 @@ static void zend_scan_escape_string(zval *zendlval, char *str, int len, char quo
*t = 0;
if (SCNG(output_filter)) {
size_t sz = 0;
unsigned char *str;
//??? use zend_string saving memalloc
s = Z_STRVAL_P(zendlval);
SCNG(output_filter)((unsigned char **)&Z_STRVAL_P(zendlval), &sz, (unsigned char *)s, (size_t)Z_STRLEN_P(zendlval) TSRMLS_CC);
Z_STRLEN_P(zendlval) = sz;
efree(s);
SCNG(output_filter)(&str, &sz, (unsigned char *)s, (size_t)Z_STRLEN_P(zendlval) TSRMLS_CC);
zval_ptr_dtor(zendlval);
ZVAL_STRINGL(zendlval, str, sz);
efree(str);
}
}

View File

@ -114,7 +114,7 @@ ZEND_API int zend_multibyte_set_functions(const zend_multibyte_functions *functi
* populated, we need to reinitialize script_encoding here.
*/
{
const char *value = zend_ini_string("zend.script_encoding", sizeof("zend.script_encoding"), 0);
const char *value = zend_ini_string("zend.script_encoding", sizeof("zend.script_encoding") - 1, 0);
zend_multibyte_set_script_encoding_by_string(value, strlen(value) TSRMLS_CC);
}
return SUCCESS;

View File

@ -2047,6 +2047,7 @@ PHP_FUNCTION(mb_parse_str)
if (track_vars_array != NULL) {
/* Clear out the array */
ZVAL_DEREF(track_vars_array);
zval_dtor(track_vars_array);
array_init(track_vars_array);
}
@ -3173,7 +3174,9 @@ PHP_FUNCTION(mb_strtoupper)
if (newstr) {
//???
RETURN_STRINGL(newstr, ret_len);
RETVAL_STRINGL(newstr, ret_len);
efree(newstr);
return;
}
RETURN_FALSE;
}
@ -3198,7 +3201,9 @@ PHP_FUNCTION(mb_strtolower)
if (newstr) {
//???
RETURN_STRINGL(newstr, ret_len);
RETVAL_STRINGL(newstr, ret_len);
efree(newstr);
return;
}
RETURN_FALSE;
}
@ -3378,6 +3383,7 @@ PHP_FUNCTION(mb_encode_mimeheader)
if (ret != NULL) {
//?????
RETVAL_STRINGL((char *)ret->val, ret->len); /* the string is already strdup()'ed */
efree(ret->val);
} else {
RETVAL_FALSE;
}
@ -3403,6 +3409,7 @@ PHP_FUNCTION(mb_decode_mimeheader)
if (ret != NULL) {
//????
RETVAL_STRINGL((char *)ret->val, ret->len); /* the string is already strdup()'ed */
efree(ret->val);
} else {
RETVAL_FALSE;
}
@ -4365,7 +4372,7 @@ PHP_FUNCTION(mb_get_info)
if (MBSTRG(current_http_output_encoding)) {
add_assoc_string(return_value, "http_output", (char *)MBSTRG(current_http_output_encoding)->name, 1);
}
if ((name = (char *)zend_ini_string("mbstring.http_output_conv_mimetypes", sizeof("mbstring.http_output_conv_mimetypes"), 0)) != NULL) {
if ((name = (char *)zend_ini_string("mbstring.http_output_conv_mimetypes", sizeof("mbstring.http_output_conv_mimetypes") - 1, 0)) != NULL) {
add_assoc_string(return_value, "http_output_conv_mimetypes", name, 1);
}
add_assoc_long(return_value, "func_overload", MBSTRG(func_overload));
@ -4440,7 +4447,7 @@ PHP_FUNCTION(mb_get_info)
RETVAL_STRING((char *)MBSTRG(current_http_output_encoding)->name);
}
} else if (!strcasecmp("http_output_conv_mimetypes", typ)) {
if ((name = (char *)zend_ini_string("mbstring.http_output_conv_mimetypes", sizeof("mbstring.http_output_conv_mimetypes"), 0)) != NULL) {
if ((name = (char *)zend_ini_string("mbstring.http_output_conv_mimetypes", sizeof("mbstring.http_output_conv_mimetypes") - 1, 0)) != NULL) {
RETVAL_STRING(name);
}
} else if (!strcasecmp("func_overload", typ)) {

View File

@ -740,9 +740,11 @@ static void _php_mb_regex_ereg_exec(INTERNAL_FUNCTION_PARAMETERS, int icase)
match_len = 1;
str = string;
if (array != NULL) {
match_len = regs->end[0] - regs->beg[0];
ZVAL_DEREF(array);
zval_dtor(array);
array_init(array);
match_len = regs->end[0] - regs->beg[0];
for (i = 0; i < regs->num_regs; i++) {
beg = regs->beg[i];
end = regs->end[i];
@ -1011,9 +1013,11 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
if (err <= -2) {
smart_str_free(&out_buf);
RETVAL_FALSE;
} else {
smart_str_appendc(&out_buf, '\0');
} else if (out_buf.s) {
smart_str_0(&out_buf);
RETVAL_STR(out_buf.s);
} else {
RETVAL_EMPTY_STRING();
}
}
/* }}} */

View File

@ -70,54 +70,54 @@ unset($a);
unset($b);
unset($c);
?>
--EXPECT--
string(10) "あいうえお" refcount(2)
string(10) "、「、、、ヲ、ィ、ェ" refcount(2)
string(10) "、「、、、ヲ、ィ、ェ" refcount(1)
string(10) "、「、、、ヲ、ィ、ェ" refcount(1)
array(1) refcount(2){
--EXPECTF--
string(10) "あいうえお" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
array(1) refcount(%d){
[0]=>
string(10) "あいうえお" refcount(2)
string(10) "あいうえお" refcount(%d)
}
array(1) refcount(2){
array(1) refcount(%d){
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(1)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
}
array(1) refcount(2){
array(1) refcount(%d){
[0]=>
&string(10) "あいうえお" refcount(2)
&string(10) "あいうえお" refcount(%d)
}
array(1) refcount(2){
array(1) refcount(%d){
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(1)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
}
array(1) refcount(1){
array(1) refcount(%d){
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(2)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
}
array(1) refcount(1){
array(1) refcount(%d){
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(2)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
}
array(1) refcount(1){
array(1) refcount(%d){
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(2)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
}
array(1) refcount(1){
array(1) refcount(%d){
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(2)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
}
array(1) refcount(3){
array(1) refcount(%d){
[0]=>
array(1) refcount(1){
array(1) refcount(%d){
[0]=>
string(10) "あいうえお" refcount(1)
string(10) "あいうえお" refcount(%d)
}
}
array(1) refcount(2){
array(1) refcount(%d){
[0]=>
array(1) refcount(1){
array(1) refcount(%d){
[0]=>
string(10) "、「、、、ヲ、ィ、ェ" refcount(1)
string(10) "、「、、、ヲ、ィ、ェ" refcount(%d)
}
}

View File

@ -49,12 +49,12 @@ $enc = mb_http_output();
print "$enc\n";
$r = mb_http_output($t_ary);
($r === FALSE) ? print "OK_BAD_ARY_SET\n" : print "NG_BAD_ARY_SET\n";
($r === NULL) ? print "OK_BAD_ARY_SET\n" : print "NG_BAD_ARY_SET\n";
$enc = mb_http_output();
print "$enc\n";
$r = mb_http_output($t_obj);
($r === FALSE) ? print "OK_BAD_OBJ_SET\n" : print "NG_BAD_OBJ_SET\n";
($r === NULL) ? print "OK_BAD_OBJ_SET\n" : print "NG_BAD_OBJ_SET\n";
$enc = mb_http_output();
print "$enc\n";

View File

@ -103,13 +103,13 @@ $r = mb_strpos($euc_jp, b"\n");
echo "== INVALID PARAMETER TEST ==\n";
$r = mb_strpos($euc_jp,'','EUC-JP');
($r === FALSE) ? print("OK_NULL\n") : print("NG_NULL\n");
($r === NULL) ? print("OK_NULL\n") : print("NG_NULL\n");
$r = mb_strpos($euc_jp, $t_ary, 'EUC-JP');
($r === FALSE) ? print("OK_ARRAY\n") : print("NG_ARRAY\n");
($r === NULL) ? print("OK_ARRAY\n") : print("NG_ARRAY\n");
$r = mb_strpos($euc_jp, $t_obj, 'EUC-JP');
($r === FALSE) ? print("OK_OBJECT\n") : print("NG_OBJECT\n");
($r === NULL) ? print("OK_OBJECT\n") : print("NG_OBJECT\n");
$r = mb_strpos($euc_jp, $t_obj, 'BAD_ENCODING');
($r === FALSE) ? print("OK_BAD_ENCODING\n") : print("NG_BAD_ENCODING\n");
($r === NULL) ? print("OK_BAD_ENCODING\n") : print("NG_BAD_ENCODING\n");
?>

View File

@ -41,10 +41,10 @@ echo "Done";
-- Testing mb_strpos() function with more than expected no. of arguments --
Warning: mb_strpos() expects at most 4 parameters, 5 given in %s on line %d
bool(false)
NULL
-- Testing mb_strpos() function with less than expected no. of arguments --
Warning: mb_strpos() expects at least 2 parameters, 1 given in %s on line %d
bool(false)
NULL
Done

View File

@ -178,5 +178,5 @@ bool(false)
-- Iteration 24 --
Warning: mb_strpos() expects parameter 1 to be string, resource given in %s on line %d
bool(false)
NULL
Done

View File

@ -194,5 +194,5 @@ bool(false)
-- Iteration 24 --
Warning: mb_strpos() expects parameter 2 to be string, resource given in %s on line %d
bool(false)
NULL
Done

View File

@ -162,32 +162,32 @@ int(8)
-- Iteration 16 --
Warning: mb_strpos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
NULL
-- Iteration 17 --
Warning: mb_strpos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
NULL
-- Iteration 18 --
Warning: mb_strpos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
NULL
-- Iteration 19 --
Warning: mb_strpos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
NULL
-- Iteration 20 --
Warning: mb_strpos() expects parameter 3 to be long, string given in %s on line %d
bool(false)
NULL
-- Iteration 21 --
Warning: mb_strpos() expects parameter 3 to be long, object given in %s on line %d
bool(false)
NULL
-- Iteration 22 --
int(8)
@ -198,5 +198,5 @@ int(8)
-- Iteration 24 --
Warning: mb_strpos() expects parameter 3 to be long, resource given in %s on line %d
bool(false)
NULL
Done

View File

@ -218,5 +218,5 @@ bool(false)
-- Iteration 24 --
Warning: mb_strpos() expects parameter 4 to be string, resource given in %s on line %d
bool(false)
Done
NULL
Done

View File

@ -41,10 +41,10 @@ echo "Done";
-- Testing mb_strrpos() function with more than expected no. of arguments --
Warning: mb_strrpos() expects at most 4 parameters, 5 given in %s on line %d
bool(false)
NULL
-- Testing mb_strrpos() function with less than expected no. of arguments --
Warning: mb_strrpos() expects at least 2 parameters, 1 given in %s on line %d
bool(false)
NULL
Done

View File

@ -177,5 +177,5 @@ bool(false)
-- Iteration 24 --
Warning: mb_strrpos() expects parameter 1 to be string, resource given in %s on line %d
bool(false)
Done
NULL
Done

View File

@ -179,5 +179,5 @@ bool(false)
-- Iteration 24 --
Warning: mb_strrpos() expects parameter 2 to be string, resource given in %s on line %d
bool(false)
NULL
Done

View File

@ -218,5 +218,5 @@ bool(false)
-- Iteration 24 --
Warning: mb_strrpos() expects parameter 4 to be string, resource given in %s on line %d
bool(false)
Done
NULL
Done