Sara,
Are you sure this complexity is necessary? Why not just pass the binary
string to INI subsystem and let user make sure it's in UTF-8? We don't
do this for any other function, really..
-Andrei
On Dec 19, 2006, at 2:01 PM, Andrei Zmievski wrote:
andrei Tue Dec 19 22:01:50 2006 UTC
Modified files:
/php-src/ext/standard basic_functions.c
Log:
Unicode support in set_include_path().
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/basic_functions.c?
r1=1.840&r2=1.841&diff_format=u
Index: php-src/ext/standard/basic_functions.c
diff -u php-src/ext/standard/basic_functions.c:1.840
php-src/ext/standard/basic_functions.c:1.841
--- php-src/ext/standard/basic_functions.c:1.840 Tue Dec 19 21:38:59
2006
+++ php-src/ext/standard/basic_functions.c Tue Dec 19 22:01:50 2006
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------
+
*/
-/* $Id: basic_functions.c,v 1.840 2006/12/19 21:38:59 andrei Exp $ */
+/* $Id: basic_functions.c,v 1.841 2006/12/19 22:01:50 andrei Exp $ */
#include "php.h"
#include "php_streams.h"
@@ -5750,31 +5750,67 @@
}
/* }}} */
-/* {{{ proto string set_include_path(string new_include_path)
+/* {{{ proto string set_include_path(string new_include_path) U
Sets the include_path configuration option */
PHP_FUNCTION(set_include_path)
{
- zval **new_value;
+ zstr new_value;
+ int new_value_len;
+ zend_uchar type;
char *old_value;
+ zend_bool free_new_value = 0;
+ char *temp;
+ int temp_len;
- if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_value) ==
FAILURE) {
- WRONG_PARAM_COUNT;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "t",
&new_value, &new_value_len, &type) == FAILURE) {
+ return;
}
- convert_to_string_ex(new_value);
+
old_value = zend_ini_string("include_path", sizeof("include_path"),
0);
/* copy to return here, because alter might free it! */
if (old_value) {
- RETVAL_STRING(old_value, 1);
+ RETVAL_UTF8_STRING(old_value, ZSTR_DUPLICATE);
} else {
RETVAL_FALSE;
}
+
+ /*
+ * We always want to convert IS_UNICODE to UTF-8 and pass to INI
subsystem.
+ * For binary strings, however, we want to convert only if
UG(unicode) is
+ * on, in which case we check whether filesystem encoding is already
UTF-8,
+ * and if it's not, we convert from that to UTF-8.
+ */
+ if (type == IS_UNICODE) {
+ zend_unicode_to_string(UG(utf8_conv), &temp, &temp_len,
new_value.u, new_value_len TSRMLS_CC);
+ new_value.s = temp;
+ new_value_len = temp_len;
+ free_new_value = 1;
+ } else if (UG(unicode)) {
+ const char *conv_name;
+ UErrorCode status = U_ZERO_ERROR;
+
+ conv_name =
ucnv_getName(ZEND_U_CONVERTER(UG(filesystem_encoding_conv)), &status);
+ conv_name = ucnv_getStandardName(conv_name, "MIME", &status);
+ if (strcmp(conv_name, "UTF-8") != 0) {
+ status = U_ZERO_ERROR;
+ zend_convert_encodings(UG(utf8_conv),
ZEND_U_CONVERTER(UG(filesystem_encoding_conv)),
+ &temp,
&temp_len, new_value.s, new_value_len, &status);
+ new_value.s = temp;
+ new_value_len = temp_len;
+ free_new_value = 1;
+ }
+ }
+
if (zend_alter_ini_entry("include_path", sizeof("include_path"),
- Z_STRVAL_PP(new_value),
Z_STRLEN_PP(new_value),
- PHP_INI_USER, PHP_INI_STAGE_RUNTIME) ==
FAILURE) {
+ new_value.s, new_value_len, PHP_INI_USER,
PHP_INI_STAGE_RUNTIME) == FAILURE) {
zval_dtor(return_value);
RETURN_FALSE;
}
+
+ if (free_new_value) {
+ efree(new_value.s);
+ }
}
/* }}} */
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php