@@ -2353,39 +2353,15 @@ static inline bool php_mb_is_no_encoding_utf8(enum mbfl_no_encoding no_enc)
2353
2353
2354
2354
MBSTRING_API char * php_mb_convert_encoding_ex (const char * input , size_t length , const mbfl_encoding * to_encoding , const mbfl_encoding * from_encoding , size_t * output_len )
2355
2355
{
2356
- mbfl_string string , result , * ret ;
2357
- mbfl_buffer_converter * convd ;
2358
- char * output = NULL ;
2359
-
2360
- if (output_len ) {
2361
- * output_len = 0 ;
2362
- }
2356
+ unsigned int num_errors = 0 ;
2357
+ zend_string * result = mb_fast_convert ((unsigned char * )input , length , from_encoding , to_encoding , MBSTRG (current_filter_illegal_substchar ), MBSTRG (current_filter_illegal_mode ), & num_errors );
2363
2358
2364
- /* initialize string */
2365
- string .encoding = from_encoding ;
2366
- string .val = (unsigned char * )input ;
2367
- string .len = length ;
2368
-
2369
- /* initialize converter */
2370
- convd = mbfl_buffer_converter_new (from_encoding , to_encoding , string .len );
2371
- /* If this assertion fails this means some memory allocation failure which is a bug */
2372
- ZEND_ASSERT (convd != NULL );
2359
+ MBSTRG (illegalchars ) += num_errors ;
2360
+ * output_len = ZSTR_LEN (result );
2373
2361
2374
- mbfl_buffer_converter_illegal_mode (convd , MBSTRG (current_filter_illegal_mode ));
2375
- mbfl_buffer_converter_illegal_substchar (convd , MBSTRG (current_filter_illegal_substchar ));
2376
-
2377
- /* do it */
2378
- mbfl_string_init (& result );
2379
- ret = mbfl_buffer_converter_feed_result (convd , & string , & result );
2380
- if (ret ) {
2381
- if (output_len ) {
2382
- * output_len = ret -> len ;
2383
- }
2384
- output = (char * )ret -> val ;
2385
- }
2386
-
2387
- MBSTRG (illegalchars ) += mbfl_buffer_illegalchars (convd );
2388
- mbfl_buffer_converter_delete (convd );
2362
+ char * output = emalloc (ZSTR_LEN (result ) + 1 );
2363
+ memcpy (output , ZSTR_VAL (result ), ZSTR_LEN (result ) + 1 );
2364
+ efree (result );
2389
2365
return output ;
2390
2366
}
2391
2367
/* }}} */
@@ -2573,7 +2549,7 @@ PHP_FUNCTION(mb_convert_encoding)
2573
2549
const mbfl_encoding * from_encoding = from_encodings [0 ];
2574
2550
if (from_encoding -> to_wchar && to_encoding -> from_wchar ) {
2575
2551
unsigned int num_errors = 0 ;
2576
- RETVAL_STR (mb_fast_convert (input_str , from_encoding , to_encoding , MBSTRG (current_filter_illegal_substchar ), MBSTRG (current_filter_illegal_mode ), & num_errors ));
2552
+ RETVAL_STR (mb_fast_convert (( unsigned char * ) ZSTR_VAL ( input_str ), ZSTR_LEN ( input_str ) , from_encoding , to_encoding , MBSTRG (current_filter_illegal_substchar ), MBSTRG (current_filter_illegal_mode ), & num_errors ));
2577
2553
MBSTRG (illegalchars ) += num_errors ;
2578
2554
goto out ;
2579
2555
}
0 commit comments