Skip to content

Commit 09ca61c

Browse files
committed
Made server wide switch for unicode on/off (according to PDM).
1 parent 5a4b684 commit 09ca61c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+644
-805
lines changed

Zend/zend.c

Lines changed: 113 additions & 356 deletions
Large diffs are not rendered by default.

Zend/zend.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,6 @@ struct _zend_class_entry {
373373
char *doc_comment;
374374
zend_uint doc_comment_len;
375375

376-
zend_class_entry *u_twin;
377-
378376
struct _zend_module_entry *module;
379377
};
380378

@@ -541,7 +539,7 @@ ZEND_API void zend_error(int type, const char *format, ...);
541539
void zenderror(char *error);
542540

543541
/* The following #define is used for code duality in PHP for Engine 1 & 2 */
544-
#define ZEND_STANDARD_CLASS_DEF_PTR U_CLASS_ENTRY(zend_standard_class_def)
542+
#define ZEND_STANDARD_CLASS_DEF_PTR zend_standard_class_def
545543
extern ZEND_API zend_class_entry *zend_standard_class_def;
546544
extern ZEND_API zend_utility_values zend_uv;
547545
extern ZEND_API zval zval_used_for_init;

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ ZEND_API int _object_init_ex(zval *arg, zend_class_entry *class_type ZEND_FILE_L
11641164

11651165
ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC TSRMLS_DC)
11661166
{
1167-
return _object_init_ex(arg, U_CLASS_ENTRY(zend_standard_class_def) ZEND_FILE_LINE_RELAY_CC TSRMLS_CC);
1167+
return _object_init_ex(arg, zend_standard_class_def ZEND_FILE_LINE_RELAY_CC TSRMLS_CC);
11681168
}
11691169

11701170

Zend/zend_API.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ typedef struct _zend_function_entry {
114114

115115
#endif
116116

117-
#define U_CLASS_ENTRY(ce) ((UG(unicode)&&ce)?ce->u_twin:ce)
118-
119117
#define INIT_CLASS_ENTRY(class_container, class_name, functions) INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, NULL, NULL, NULL)
120118

121119
#define INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset) \
@@ -145,7 +143,6 @@ typedef struct _zend_function_entry {
145143
class_container.interfaces = NULL; \
146144
class_container.get_iterator = NULL; \
147145
class_container.iterator_funcs.funcs = NULL; \
148-
class_container.u_twin = NULL; \
149146
class_container.module = NULL; \
150147
}
151148

Zend/zend_compile.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ struct _zend_op_array {
179179
zend_arg_info *arg_info;
180180
zend_bool pass_rest_by_reference;
181181
unsigned char return_reference;
182-
union _zend_function *u_twin;
183182
/* END of common elements */
184183

185184
zend_uint *refcount;
@@ -234,7 +233,6 @@ typedef struct _zend_internal_function {
234233
zend_arg_info *arg_info;
235234
zend_bool pass_rest_by_reference;
236235
unsigned char return_reference;
237-
union _zend_function *u_twin;
238236
/* END of common elements */
239237

240238
void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
@@ -257,7 +255,6 @@ typedef union _zend_function {
257255
zend_arg_info *arg_info;
258256
zend_bool pass_rest_by_reference;
259257
unsigned char return_reference;
260-
union _zend_function *u_twin;
261258
} common;
262259

263260
zend_op_array op_array;

Zend/zend_exceptions.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ static zend_object_value zend_default_exception_new_ex(zend_class_entry *class_t
9393
trace->refcount = 0;
9494
zend_fetch_debug_backtrace(trace, skip_top_traces, 0 TSRMLS_CC);
9595

96-
zend_update_property_rt_string(U_CLASS_ENTRY(default_exception_ce), &obj, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC);
97-
zend_update_property_long(U_CLASS_ENTRY(default_exception_ce), &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC);
98-
zend_update_property(U_CLASS_ENTRY(default_exception_ce), &obj, "trace", sizeof("trace")-1, trace TSRMLS_CC);
96+
zend_update_property_rt_string(default_exception_ce, &obj, "file", sizeof("file")-1, zend_get_executed_filename(TSRMLS_C) TSRMLS_CC);
97+
zend_update_property_long(default_exception_ce, &obj, "line", sizeof("line")-1, zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC);
98+
zend_update_property(default_exception_ce, &obj, "trace", sizeof("trace")-1, trace TSRMLS_CC);
9999

100100
return obj.value.obj;
101101
}
@@ -139,22 +139,22 @@ ZEND_METHOD(exception, __construct)
139139

140140
if (message) {
141141
if (message_type == IS_UNICODE) {
142-
zend_update_property_unicodel(U_CLASS_ENTRY(default_exception_ce), object, "message", sizeof("message")-1, message, message_len TSRMLS_CC);
142+
zend_update_property_unicodel(default_exception_ce, object, "message", sizeof("message")-1, message, message_len TSRMLS_CC);
143143
} else if (UG(unicode)) {
144144
UErrorCode status = U_ZERO_ERROR;
145145
UChar *u_str;
146146
int32_t u_len;
147147

148148
zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, message, message_len, &status);
149-
zend_update_property_unicodel(U_CLASS_ENTRY(default_exception_ce), object, "message", sizeof("message")-1, u_str, u_len TSRMLS_CC);
149+
zend_update_property_unicodel(default_exception_ce, object, "message", sizeof("message")-1, u_str, u_len TSRMLS_CC);
150150
efree(u_str);
151151
} else {
152-
zend_update_property_stringl(U_CLASS_ENTRY(default_exception_ce), object, "message", sizeof("message")-1, message, message_len TSRMLS_CC);
152+
zend_update_property_stringl(default_exception_ce, object, "message", sizeof("message")-1, message, message_len TSRMLS_CC);
153153
}
154154
}
155155

156156
if (code) {
157-
zend_update_property_long(U_CLASS_ENTRY(default_exception_ce), object, "code", sizeof("code")-1, code TSRMLS_CC);
157+
zend_update_property_long(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC);
158158
}
159159
}
160160
/* }}} */
@@ -178,36 +178,36 @@ ZEND_METHOD(error_exception, __construct)
178178

179179
if (message) {
180180
if (message_type == IS_UNICODE) {
181-
zend_update_property_unicodel(U_CLASS_ENTRY(default_exception_ce), object, "message", sizeof("message")-1, message, message_len TSRMLS_CC);
181+
zend_update_property_unicodel(default_exception_ce, object, "message", sizeof("message")-1, message, message_len TSRMLS_CC);
182182
} else if (UG(unicode)) {
183183
UErrorCode status = U_ZERO_ERROR;
184184
UChar *u_str;
185185
int32_t u_len;
186186

187187
zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u_str, &u_len, message, message_len, &status);
188-
zend_update_property_unicodel(U_CLASS_ENTRY(default_exception_ce), object, "message", sizeof("message")-1, u_str, u_len TSRMLS_CC);
188+
zend_update_property_unicodel(default_exception_ce, object, "message", sizeof("message")-1, u_str, u_len TSRMLS_CC);
189189
efree(u_str);
190190
} else {
191-
zend_update_property_stringl(U_CLASS_ENTRY(default_exception_ce), object, "message", sizeof("message")-1, message, message_len TSRMLS_CC);
191+
zend_update_property_stringl(default_exception_ce, object, "message", sizeof("message")-1, message, message_len TSRMLS_CC);
192192
}
193193
}
194194

195195
if (code) {
196-
zend_update_property_long(U_CLASS_ENTRY(default_exception_ce), object, "code", sizeof("code")-1, code TSRMLS_CC);
196+
zend_update_property_long(default_exception_ce, object, "code", sizeof("code")-1, code TSRMLS_CC);
197197
}
198198

199-
zend_update_property_long(U_CLASS_ENTRY(default_exception_ce), object, "severity", sizeof("severity")-1, severity TSRMLS_CC);
199+
zend_update_property_long(default_exception_ce, object, "severity", sizeof("severity")-1, severity TSRMLS_CC);
200200

201201
if (argc >= 4) {
202202
if (file_type == IS_UNICODE) {
203-
zend_update_property_unicodel(U_CLASS_ENTRY(default_exception_ce), object, "file", sizeof("file")-1, filename, filename_len TSRMLS_CC);
203+
zend_update_property_unicodel(default_exception_ce, object, "file", sizeof("file")-1, filename, filename_len TSRMLS_CC);
204204
} else {
205-
zend_update_property_stringl(U_CLASS_ENTRY(default_exception_ce), object, "file", sizeof("file")-1, filename, filename_len TSRMLS_CC);
205+
zend_update_property_stringl(default_exception_ce, object, "file", sizeof("file")-1, filename, filename_len TSRMLS_CC);
206206
}
207207
if (argc < 5) {
208208
lineno = 0; /* invalidate lineno */
209209
}
210-
zend_update_property_long(U_CLASS_ENTRY(default_exception_ce), object, "line", sizeof("line")-1, lineno TSRMLS_CC);
210+
zend_update_property_long(default_exception_ce, object, "line", sizeof("line")-1, lineno TSRMLS_CC);
211211
}
212212
}
213213
/* }}} */
@@ -221,7 +221,7 @@ static void _default_exception_get_entry(zval *object, char *name, int name_len,
221221
{
222222
zval *value;
223223

224-
value = zend_read_property(U_CLASS_ENTRY(default_exception_ce), object, name, name_len, 0 TSRMLS_CC);
224+
value = zend_read_property(default_exception_ce, object, name, name_len, 0 TSRMLS_CC);
225225

226226
*return_value = *value;
227227
zval_copy_ctor(return_value);
@@ -524,7 +524,7 @@ ZEND_METHOD(exception, getTraceAsString)
524524
char *res = estrdup(""), **str = &res, *s_tmp;
525525
int res_len = 0, *len = &res_len, num = 0;
526526

527-
trace = zend_read_property(U_CLASS_ENTRY(default_exception_ce), getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC);
527+
trace = zend_read_property(default_exception_ce, getThis(), "trace", sizeof("trace")-1, 1 TSRMLS_CC);
528528
zend_hash_apply_with_arguments(Z_ARRVAL_P(trace), (apply_func_args_t)_build_trace_string, 3, str, len, &num);
529529

530530
s_tmp = emalloc(1 + MAX_LENGTH_OF_LONG + 7 + 1);
@@ -596,7 +596,7 @@ ZEND_METHOD(exception, __toString)
596596

597597
/* We store the result in the private property string so we can access
598598
* the result in uncaught exception handlers without memleaks. */
599-
zend_update_property_string(U_CLASS_ENTRY(default_exception_ce), getThis(), "string", sizeof("string")-1, str TSRMLS_CC);
599+
zend_update_property_string(default_exception_ce, getThis(), "string", sizeof("string")-1, str TSRMLS_CC);
600600

601601
if (trace) {
602602
zval_ptr_dtor(&trace);
@@ -678,12 +678,12 @@ void zend_register_default_exception(TSRMLS_D)
678678

679679
ZEND_API zend_class_entry *zend_exception_get_default(TSRMLS_D)
680680
{
681-
return U_CLASS_ENTRY(default_exception_ce);
681+
return default_exception_ce;
682682
}
683683

684684
ZEND_API zend_class_entry *zend_get_error_exception(TSRMLS_D)
685685
{
686-
return U_CLASS_ENTRY(error_exception_ce);
686+
return error_exception_ce;
687687
}
688688

689689

@@ -693,21 +693,21 @@ ZEND_API zval * zend_throw_exception(zend_class_entry *exception_ce, char *messa
693693

694694
MAKE_STD_ZVAL(ex);
695695
if (exception_ce) {
696-
if (!instanceof_function(exception_ce, U_CLASS_ENTRY(default_exception_ce) TSRMLS_CC)) {
696+
if (!instanceof_function(exception_ce, default_exception_ce TSRMLS_CC)) {
697697
zend_error(E_NOTICE, "Exceptions must be derived from the Exception base class");
698-
exception_ce = U_CLASS_ENTRY(default_exception_ce);
698+
exception_ce = default_exception_ce;
699699
}
700700
} else {
701-
exception_ce = U_CLASS_ENTRY(default_exception_ce);
701+
exception_ce = default_exception_ce;
702702
}
703703
object_init_ex(ex, exception_ce);
704704

705705

706706
if (message) {
707-
zend_update_property_rt_string(U_CLASS_ENTRY(default_exception_ce), ex, "message", sizeof("message")-1, message TSRMLS_CC);
707+
zend_update_property_rt_string(default_exception_ce, ex, "message", sizeof("message")-1, message TSRMLS_CC);
708708
}
709709
if (code) {
710-
zend_update_property_long(U_CLASS_ENTRY(default_exception_ce), ex, "code", sizeof("code")-1, code TSRMLS_CC);
710+
zend_update_property_long(default_exception_ce, ex, "code", sizeof("code")-1, code TSRMLS_CC);
711711
}
712712

713713
zend_throw_exception_internal(ex TSRMLS_CC);
@@ -733,7 +733,7 @@ ZEND_API zval * zend_throw_exception_ex(zend_class_entry *exception_ce, long cod
733733
ZEND_API zval * zend_throw_error_exception(zend_class_entry *exception_ce, char *message, long code, int severity TSRMLS_DC)
734734
{
735735
zval *ex = zend_throw_exception(exception_ce, message, code TSRMLS_CC);
736-
zend_update_property_long(U_CLASS_ENTRY(default_exception_ce), ex, "severity", sizeof("severity")-1, severity TSRMLS_CC);
736+
zend_update_property_long(default_exception_ce, ex, "severity", sizeof("severity")-1, severity TSRMLS_CC);
737737
return ex;
738738
}
739739

@@ -750,7 +750,7 @@ static void zend_error_va(int type, const char *file, uint lineno, const char *f
750750
ZEND_API void zend_exception_error(zval *exception TSRMLS_DC)
751751
{
752752
zend_class_entry *ce_exception = Z_OBJCE_P(exception);
753-
if (instanceof_function(ce_exception, U_CLASS_ENTRY(default_exception_ce) TSRMLS_CC)) {
753+
if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
754754
zval *str, *file, *line;
755755

756756
EG(exception) = NULL;
@@ -760,26 +760,26 @@ ZEND_API void zend_exception_error(zval *exception TSRMLS_DC)
760760
if (Z_TYPE_P(str) != IS_STRING) {
761761
zend_error(E_WARNING, "%v::__toString() must return a string", ce_exception->name);
762762
} else {
763-
zend_update_property_string(U_CLASS_ENTRY(default_exception_ce), exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name : Z_STRVAL_P(str) TSRMLS_CC);
763+
zend_update_property_string(default_exception_ce, exception, "string", sizeof("string")-1, EG(exception) ? ce_exception->name : Z_STRVAL_P(str) TSRMLS_CC);
764764
}
765765
}
766766
zval_ptr_dtor(&str);
767767

768768
if (EG(exception)) {
769769
/* do the best we can to inform about the inner exception */
770-
if (instanceof_function(ce_exception, U_CLASS_ENTRY(default_exception_ce) TSRMLS_CC)) {
771-
file = zend_read_property(U_CLASS_ENTRY(default_exception_ce), EG(exception), "file", sizeof("file")-1, 1 TSRMLS_CC);
772-
line = zend_read_property(U_CLASS_ENTRY(default_exception_ce), EG(exception), "line", sizeof("line")-1, 1 TSRMLS_CC);
770+
if (instanceof_function(ce_exception, default_exception_ce TSRMLS_CC)) {
771+
file = zend_read_property(default_exception_ce, EG(exception), "file", sizeof("file")-1, 1 TSRMLS_CC);
772+
line = zend_read_property(default_exception_ce, EG(exception), "line", sizeof("line")-1, 1 TSRMLS_CC);
773773
} else {
774774
file = NULL;
775775
line = NULL;
776776
}
777777
zend_error_va(E_WARNING, file ? Z_STRVAL_P(file) : NULL, line ? Z_LVAL_P(line) : 0, "Uncaught %v in exception handling during call to %v::__tostring()", Z_OBJCE_P(EG(exception))->name, ce_exception->name);
778778
}
779779

780-
str = zend_read_property(U_CLASS_ENTRY(default_exception_ce), exception, "string", sizeof("string")-1, 1 TSRMLS_CC);
781-
file = zend_read_property(U_CLASS_ENTRY(default_exception_ce), exception, "file", sizeof("file")-1, 1 TSRMLS_CC);
782-
line = zend_read_property(U_CLASS_ENTRY(default_exception_ce), exception, "line", sizeof("line")-1, 1 TSRMLS_CC);
780+
str = zend_read_property(default_exception_ce, exception, "string", sizeof("string")-1, 1 TSRMLS_CC);
781+
file = zend_read_property(default_exception_ce, exception, "file", sizeof("file")-1, 1 TSRMLS_CC);
782+
line = zend_read_property(default_exception_ce, exception, "line", sizeof("line")-1, 1 TSRMLS_CC);
783783

784784
if (Z_TYPE_P(file) == IS_UNICODE) {
785785
zval copy;
@@ -806,7 +806,7 @@ ZEND_API void zend_throw_exception_object(zval *exception TSRMLS_DC)
806806

807807
exception_ce = Z_OBJCE_P(exception);
808808

809-
if (!exception_ce || !instanceof_function(exception_ce, U_CLASS_ENTRY(default_exception_ce) TSRMLS_CC)) {
809+
if (!exception_ce || !instanceof_function(exception_ce, default_exception_ce TSRMLS_CC)) {
810810
zend_error(E_ERROR, "Exceptions must be valid objects derived from the Exception base class");
811811
}
812812
zend_throw_exception_internal(exception TSRMLS_CC);

Zend/zend_globals.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,6 @@ struct _zend_compiler_globals {
137137
char *script_encoding;
138138

139139
#ifdef ZTS
140-
HashTable *global_function_table;
141-
HashTable *global_class_table;
142-
HashTable *global_auto_globals_table;
143-
HashTable *global_u_function_table;
144-
HashTable *global_u_class_table;
145-
HashTable *global_u_auto_globals_table;
146-
147140
HashTable **static_members;
148141
int last_static_member;
149142
#endif
@@ -236,11 +229,6 @@ struct _zend_executor_globals {
236229

237230
zend_property_info std_property_info;
238231

239-
#ifdef ZTS
240-
HashTable *global_constants_table;
241-
HashTable *global_u_constants_table;
242-
#endif
243-
244232
void *reserved[ZEND_MAX_RESERVED_RESOURCES];
245233
};
246234

Zend/zend_hash.c

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,16 @@
4949

5050
#define UNICODE_KEY(ht, type, arKey, nKeyLength, tmp) \
5151
if (ht->unicode && type == IS_STRING) { \
52-
UErrorCode status = U_ZERO_ERROR; \
52+
UErrorCode status = U_ZERO_ERROR; \
5353
UChar *u = NULL; \
5454
int32_t u_len; \
5555
TSRMLS_FETCH(); \
5656
zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u, &u_len, (char*)arKey, nKeyLength-1, &status); \
57-
if (U_FAILURE(status)) { \
57+
if (U_FAILURE(status)) { \
5858
/* UTODO: */ \
59-
} \
60-
type = IS_UNICODE; \
61-
tmp = arKey = u; \
59+
} \
60+
type = IS_UNICODE; \
61+
tmp = arKey = u; \
6262
}
6363

6464

@@ -1781,6 +1781,57 @@ void zend_hash_display(HashTable *ht)
17811781
p = p->pListLast;
17821782
}
17831783
}
1784+
1785+
ZEND_API void zend_hash_to_unicode(HashTable *ht, apply_func_t apply_func TSRMLS_DC)
1786+
{
1787+
Bucket **p;
1788+
uint nIndex;
1789+
1790+
IS_CONSISTENT(ht);
1791+
if (ht->unicode) {
1792+
return;
1793+
}
1794+
1795+
ht->unicode = 1;
1796+
memset(ht->arBuckets, 0, ht->nTableSize * sizeof(Bucket *));
1797+
p = &ht->pListHead;
1798+
while ((*p) != NULL) {
1799+
if ((*p)->key.type == IS_STRING) {
1800+
UErrorCode status = U_ZERO_ERROR;
1801+
UChar *u = NULL;
1802+
int32_t u_len;
1803+
Bucket *q;
1804+
1805+
zend_convert_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &u, &u_len, (char*)(*p)->key.u.string, (*p)->nKeyLength-1, &status);
1806+
1807+
q = (Bucket *) pemalloc(sizeof(Bucket)-sizeof(q->key.u)+((u_len+1)*2), ht->persistent);
1808+
memcpy(q, *p, sizeof(Bucket)-sizeof(q->key.u));
1809+
memcpy(q->key.u.unicode, u, (u_len+1)*2);
1810+
q->key.type = IS_UNICODE;
1811+
q->nKeyLength = u_len+1;
1812+
q->h = zend_u_inline_hash_func(IS_UNICODE, (void*)q->key.u.unicode, q->nKeyLength);
1813+
if ((*p)->pData == &(*p)->pDataPtr) {
1814+
q->pData = &q->pDataPtr;
1815+
}
1816+
efree(u);
1817+
pefree(*p, ht->persistent);
1818+
*p = q;
1819+
if (q->pListNext) {
1820+
q->pListNext->pListLast = q;
1821+
} else {
1822+
ht->pListTail = q;
1823+
}
1824+
}
1825+
nIndex = (*p)->h & ht->nTableMask;
1826+
CONNECT_TO_BUCKET_DLLIST(*p, ht->arBuckets[nIndex]);
1827+
ht->arBuckets[nIndex] = *p;
1828+
if (apply_func) {
1829+
apply_func((*p)->pData TSRMLS_CC);
1830+
}
1831+
p = &(*p)->pListNext;
1832+
}
1833+
}
1834+
17841835
#endif
17851836

17861837
/*

Zend/zend_hash.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, apply_func_args_t ap
175175
*/
176176
ZEND_API void zend_hash_reverse_apply(HashTable *ht, apply_func_t apply_func TSRMLS_DC);
177177

178+
ZEND_API void zend_hash_to_unicode(HashTable *ht, apply_func_t apply_func TSRMLS_DC);
178179

179180
/* Deletes */
180181
ZEND_API int zend_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag);

0 commit comments

Comments
 (0)