cvs: ZendEngine2 / zend_API.c zend_API.h zend_operators.h zend_unicode.h

From: Date: Thu, 18 Aug 2005 22:33:25 +0000
Subject: cvs: ZendEngine2 / zend_API.c zend_API.h zend_operators.h zend_unicode.h
Groups: php.zend-engine.cvs 
Request: Send a blank email to php-zend-engine-cvs+get-4049@lists.php.net to get a copy of this message
andrei Thu Aug 18 18:33:25 2005 EDT Modified files: /ZendEngine2 zend_API.c zend_API.h zend_operators.h zend_unicode.h Log: - Implement zend_codepoint_to_uchar(). - Rename and fix zend_get_unified_string_type() so that it does not allow mixing of binary and Unicode types. http://cvs.php.net/diff.php/ZendEngine2/zend_API.c?r1=1.307&r2=1.308&ty=u Index: ZendEngine2/zend_API.c diff -u ZendEngine2/zend_API.c:1.307 ZendEngine2/zend_API.c:1.308 --- ZendEngine2/zend_API.c:1.307 Thu Aug 18 11:42:45 2005 +++ ZendEngine2/zend_API.c Thu Aug 18 18:33:22 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.c,v 1.307 2005/08/18 15:42:45 dmitry Exp $ */ +/* $Id: zend_API.c,v 1.308 2005/08/18 22:33:22 andrei Exp $ */ #include "zend.h" #include "zend_execute.h" @@ -2928,30 +2928,40 @@ } /* - * Return the most precise string type out of the list. - * If none of the types are string types, IS_STRING is returned. - * Binary > Unicode > string. + * Return the string type that all the passed in types should be converted to. + * If none of the types are string types, IS_UNICODE or IS_STRING is returned, + * depending on the Unicode semantics switch. + * Binary and Unicode types cannot be mixed, so we return -1 (or 255 since it's + * uchar) */ -ZEND_API zend_uchar zend_get_best_string_type(int num_args, ...) +ZEND_API zend_uchar zend_get_unified_string_type(int num_args TSRMLS_DC, ...) { va_list ap; - int best_type = IS_STRING; + int best_type = UG(unicode) ? IS_UNICODE : IS_STRING; + zend_bool seen_unicode = 0; int type; - if (num_args <= 0) return -1; + if (num_args <= 0) return (zend_uchar)-1; va_start(ap, num_args); while (num_args--) { type = va_arg(ap, int); if (type == IS_BINARY) { best_type = IS_BINARY; - break; - } else if (type == IS_UNICODE && best_type == IS_STRING) { - best_type = IS_UNICODE; + } else if (type == IS_UNICODE) { + seen_unicode = 1; + if (best_type == IS_STRING) { + best_type = IS_UNICODE; + } } } va_end(ap); + /* We do not allow mixing binary and Unicode types */ + if (best_type == IS_BINARY && seen_unicode) { + return (zend_uchar)-1; + } + return best_type; } http://cvs.php.net/diff.php/ZendEngine2/zend_API.h?r1=1.213&r2=1.214&ty=u Index: ZendEngine2/zend_API.h diff -u ZendEngine2/zend_API.h:1.213 ZendEngine2/zend_API.h:1.214 --- ZendEngine2/zend_API.h:1.213 Thu Aug 18 11:42:46 2005 +++ ZendEngine2/zend_API.h Thu Aug 18 18:33:22 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_API.h,v 1.213 2005/08/18 15:42:46 dmitry Exp $ */ +/* $Id: zend_API.h,v 1.214 2005/08/18 22:33:22 andrei Exp $ */ #ifndef ZEND_API_H #define ZEND_API_H @@ -235,7 +235,7 @@ ZEND_API zend_class_entry *zend_get_class_entry(zval *zobject TSRMLS_DC); ZEND_API int zend_get_object_classname(zval *object, char **class_name, zend_uint *class_name_len TSRMLS_DC); -ZEND_API zend_uchar zend_get_best_string_type(int num_args, ...); +ZEND_API zend_uchar zend_get_unified_string_type(int num_args TSRMLS_DC, ...); #define getThis() (this_ptr) http://cvs.php.net/diff.php/ZendEngine2/zend_operators.h?r1=1.96&r2=1.97&ty=u Index: ZendEngine2/zend_operators.h diff -u ZendEngine2/zend_operators.h:1.96 ZendEngine2/zend_operators.h:1.97 --- ZendEngine2/zend_operators.h:1.96 Wed Aug 17 16:02:45 2005 +++ ZendEngine2/zend_operators.h Thu Aug 18 18:33:23 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: zend_operators.h,v 1.96 2005/08/17 20:02:45 helly Exp $ */ +/* $Id: zend_operators.h,v 1.97 2005/08/18 22:33:23 andrei Exp $ */ #ifndef ZEND_OPERATORS_H #define ZEND_OPERATORS_H @@ -68,7 +68,7 @@ ZEND_API double zend_u_strtod(const UChar *nptr, UChar **endptr); END_EXTERN_C() -static inline zend_bool is_numeric_string(char *str, int length, long *lval, double *dval, zend_bool allow_errors) +static inline zend_uchar is_numeric_string(char *str, int length, long *lval, double *dval, zend_bool allow_errors) { long local_lval; double local_dval; @@ -131,7 +131,7 @@ return 0; } -static inline zend_bool is_numeric_unicode(UChar *str, int32_t length, long *lval, double *dval, zend_bool allow_errors) +static inline zend_uchar is_numeric_unicode(UChar *str, int32_t length, long *lval, double *dval, zend_bool allow_errors) { int32_t local_lval; double local_dval; @@ -320,7 +320,7 @@ convert_to_double(pzv); \ break; \ case IS_BOOL: \ - convert_to_bool(pzv); \ + convert_to_boolean(pzv); \ break; \ case IS_ARRAY: \ convert_to_array(pzv); \ http://cvs.php.net/diff.php/ZendEngine2/zend_unicode.h?r1=1.1&r2=1.2&ty=u Index: ZendEngine2/zend_unicode.h diff -u ZendEngine2/zend_unicode.h:1.1 ZendEngine2/zend_unicode.h:1.2 --- ZendEngine2/zend_unicode.h:1.1 Thu Aug 11 19:35:00 2005 +++ ZendEngine2/zend_unicode.h Thu Aug 18 18:33:23 2005 @@ -71,6 +71,24 @@ return c; } +/* + * Convert a single codepoint to UChar sequence (1 or 2). + * The UChar buffer is assumed to be large enough. + */ +static inline int zend_codepoint_to_uchar(UChar32 codepoint, UChar *buf) +{ + if (U_IS_BMP(codepoint)) { + *buf++ = (UChar) codepoint; + return 1; + } else if (codepoint <= UCHAR_MAX_VALUE) { + *buf++ = (UChar) U16_LEAD(codepoint); + *buf++ = (UChar) U16_TRAIL(codepoint); + return 2; + } else { + return 0; + } +} + #define ZEND_U_CONVERTER(c) ((c)?(c):UG(fallback_encoding_conv)) #define USTR_FREE(ustr) do { if (ustr) { efree(ustr); } } while (0);

« previous php.zend-engine.cvs (#4049) next »