Skip to content

Commit c974313

Browse files
committed
Switch from using PHP_MAJOR_VERSION to separate define for
unicode. Unicode is no more, but these are "bookmarks" where to change mysqlnd, if Unicode becomes trendy again.
1 parent d27983e commit c974313

12 files changed

+46
-40
lines changed

ext/mysqlnd/mysqlnd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ mysqlnd_connect_run_authentication(
481481
if (options->charset_name && (charset = mysqlnd_find_charset_name(options->charset_name))) {
482482
auth_packet->charset_no = charset->nr;
483483
} else {
484-
#if PHP_MAJOR_VERSION >= 6
484+
#if MYSQLND_UNICODE
485485
auth_packet->charset_no = 200;/* utf8 - swedish collation, check mysqlnd_charset.c */
486486
#else
487487
auth_packet->charset_no = greet_packet->charset_no;
@@ -799,7 +799,7 @@ MYSQLND_METHOD(mysqlnd_conn, connect)(MYSQLND * conn,
799799

800800
mysqlnd_local_infile_default(conn);
801801

802-
#if PHP_MAJOR_VERSION >= 6
802+
#if MYSQLND_UNICODE
803803
{
804804
unsigned int as_unicode = 1;
805805
conn->m->set_client_option(conn, MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE, (char *)&as_unicode TSRMLS_CC);
@@ -2052,7 +2052,7 @@ MYSQLND_METHOD(mysqlnd_conn, set_client_option)(MYSQLND * const conn,
20522052
case MYSQLND_OPT_NET_READ_BUFFER_SIZE:
20532053
ret = conn->net->m.set_client_option(conn->net, option, value TSRMLS_CC);
20542054
break;
2055-
#if PHP_MAJOR_VERSION >= 6
2055+
#if MYSQLND_UNICODE
20562056
case MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE:
20572057
conn->options.numeric_and_datetime_as_unicode = *(unsigned int*) value;
20582058
break;

ext/mysqlnd/mysqlnd_debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ PHPAPI struct st_mysqlnd_allocator_methods mysqlnd_allocator =
12491249

12501250
/* Follows code borrowed from zend_builtin_functions.c because the functions there are static */
12511251

1252-
#if PHP_MAJOR_VERSION >= 6
1252+
#if MYSQLND_UNICODE
12531253
/* {{{ gettraceasstring() macros */
12541254
#define TRACE_APPEND_CHR(chr) \
12551255
*str = (char*)erealloc(*str, *len + 1 + 1); \

ext/mysqlnd/mysqlnd_enum_n_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ typedef enum mysqlnd_option
152152
MYSQL_REPORT_DATA_TRUNCATION,
153153
MYSQL_OPT_RECONNECT,
154154
MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
155-
#if PHP_MAJOR_VERSION >= 6
155+
#if MYSQLND_UNICODE
156156
MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE = 200,
157157
#endif
158158
#ifdef MYSQLND_STRING_TO_INT_CONVERSION

ext/mysqlnd/mysqlnd_priv.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
#define Z_DELREF_PP(ppz) Z_DELREF_P(*(ppz))
3434
#endif
3535

36+
#if PHP_MAJOR_VERSION >= 6
37+
#define MYSQLND_UNICODE 1
38+
#else
39+
#define MYSQLND_UNICODE 0
40+
#endif
41+
3642
#ifdef ZTS
3743
#include "TSRM.h"
3844
#endif
@@ -45,18 +51,18 @@
4551
#define MYSQLND_CLASS_METHODS_START(class) struct st_##class##_methods MYSQLND_CLASS_METHOD_TABLE_NAME(class) = {
4652
#define MYSQLND_CLASS_METHODS_END }
4753

48-
#if PHP_MAJOR_VERSION < 6
54+
#if MYSQLND_UNICODE
4955
#define mysqlnd_array_init(arg, field_count) \
5056
{ \
5157
ALLOC_HASHTABLE_REL(Z_ARRVAL_P(arg));\
52-
zend_hash_init(Z_ARRVAL_P(arg), (field_count), NULL, ZVAL_PTR_DTOR, 0); \
58+
zend_u_hash_init(Z_ARRVAL_P(arg), (field_count), NULL, ZVAL_PTR_DTOR, 0, 0);\
5359
Z_TYPE_P(arg) = IS_ARRAY;\
5460
}
5561
#else
5662
#define mysqlnd_array_init(arg, field_count) \
5763
{ \
5864
ALLOC_HASHTABLE_REL(Z_ARRVAL_P(arg));\
59-
zend_u_hash_init(Z_ARRVAL_P(arg), (field_count), NULL, ZVAL_PTR_DTOR, 0, 0);\
65+
zend_hash_init(Z_ARRVAL_P(arg), (field_count), NULL, ZVAL_PTR_DTOR, 0); \
6066
Z_TYPE_P(arg) = IS_ARRAY;\
6167
}
6268
#endif

ext/mysqlnd/mysqlnd_ps.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ mysqlnd_stmt_fetch_row_unbuffered(MYSQLND_RES *result, void *param, unsigned int
869869
if (IS_NULL != (Z_TYPE_P(stmt->result_bind[i].zv) = Z_TYPE_P(data)) ) {
870870
if (
871871
(Z_TYPE_P(data) == IS_STRING
872-
#if PHP_MAJOR_VERSION >= 6
872+
#if MYSQLND_UNICODE
873873
|| Z_TYPE_P(data) == IS_UNICODE
874874
#endif
875875
)
@@ -1059,7 +1059,7 @@ mysqlnd_fetch_stmt_row_cursor(MYSQLND_RES *result, void *param, unsigned int fla
10591059
Z_TYPE_P(data), Z_REFCOUNT_P(stmt->result_bind[i].zv));
10601060
if (IS_NULL != (Z_TYPE_P(stmt->result_bind[i].zv) = Z_TYPE_P(data))) {
10611061
if ((Z_TYPE_P(data) == IS_STRING
1062-
#if PHP_MAJOR_VERSION >= 6
1062+
#if MYSQLND_UNICODE
10631063
|| Z_TYPE_P(data) == IS_UNICODE
10641064
#endif
10651065
)

ext/mysqlnd/mysqlnd_ps_codec.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void ps_fetch_from_1_to_8_bytes(zval *zv, const MYSQLND_FIELD * const field,
117117
}
118118

119119
if (tmp_len) {
120-
#if PHP_MAJOR_VERSION >= 6
120+
#if MYSQLND_UNICODE
121121
if (as_unicode) {
122122
DBG_INF("stringify");
123123
ZVAL_UTF8_STRINGL(zv, tmp, tmp_len, ZSTR_DUPLICATE);
@@ -265,12 +265,12 @@ void ps_fetch_time(zval *zv, const MYSQLND_FIELD * const field,
265265
length = spprintf(&to, 0, "%s%02u:%02u:%02u", (t.neg ? "-" : ""), t.hour, t.minute, t.second);
266266

267267
DBG_INF_FMT("%s", to);
268-
#if PHP_MAJOR_VERSION >= 6
268+
#if MYSQLND_UNICODE
269269
if (!as_unicode) {
270270
#endif
271271
ZVAL_STRINGL(zv, to, length, 1);
272272
efree(to); /* allocated by spprintf */
273-
#if PHP_MAJOR_VERSION >= 6
273+
#if MYSQLND_UNICODE
274274
} else {
275275
ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);
276276
}
@@ -316,12 +316,12 @@ void ps_fetch_date(zval *zv, const MYSQLND_FIELD * const field,
316316
length = spprintf(&to, 0, "%04u-%02u-%02u", t.year, t.month, t.day);
317317

318318
DBG_INF_FMT("%s", to);
319-
#if PHP_MAJOR_VERSION >= 6
319+
#if MYSQLND_UNICODE
320320
if (!as_unicode) {
321321
#endif
322322
ZVAL_STRINGL(zv, to, length, 1);
323323
efree(to); /* allocated by spprintf */
324-
#if PHP_MAJOR_VERSION >= 6
324+
#if MYSQLND_UNICODE
325325
} else {
326326
ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);
327327
}
@@ -375,12 +375,12 @@ void ps_fetch_datetime(zval *zv, const MYSQLND_FIELD * const field,
375375
t.year, t.month, t.day, t.hour, t.minute, t.second);
376376

377377
DBG_INF_FMT("%s", to);
378-
#if PHP_MAJOR_VERSION >= 6
378+
#if MYSQLND_UNICODE
379379
if (!as_unicode) {
380380
#endif
381381
ZVAL_STRINGL(zv, to, length, 1);
382382
efree(to); /* allocated by spprintf */
383-
#if PHP_MAJOR_VERSION >= 6
383+
#if MYSQLND_UNICODE
384384
} else {
385385
ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);
386386
}
@@ -403,17 +403,17 @@ void ps_fetch_string(zval *zv, const MYSQLND_FIELD * const field,
403403
unsigned long length = php_mysqlnd_net_field_length(row);
404404
DBG_ENTER("ps_fetch_string");
405405
DBG_INF_FMT("len = %lu", length);
406-
#if PHP_MAJOR_VERSION < 6
407-
DBG_INF("copying from the row buffer");
408-
ZVAL_STRINGL(zv, (char *)*row, length, 1);
409-
#else
406+
#if MYSQLND_UNICODE
410407
if (field->charsetnr == MYSQLND_BINARY_CHARSET_NR) {
411408
DBG_INF("Binary charset");
412409
ZVAL_STRINGL(zv, (char *)*row, length, 1);
413410
} else {
414411
DBG_INF_FMT("copying from the row buffer");
415412
ZVAL_UTF8_STRINGL(zv, (char*)*row, length, ZSTR_DUPLICATE);
416413
}
414+
#else
415+
DBG_INF("copying from the row buffer");
416+
ZVAL_STRINGL(zv, (char *)*row, length, 1);
417417
#endif
418418

419419
(*row) += length;
@@ -704,10 +704,10 @@ mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar **buf, zend_uchar
704704
break;
705705
case MYSQL_TYPE_VAR_STRING:
706706
data_size += 8; /* max 8 bytes for size */
707-
#if PHP_MAJOR_VERSION < 6
708-
if (Z_TYPE_P(the_var) != IS_STRING)
709-
#elif PHP_MAJOR_VERSION >= 6
707+
#if MYSQLND_UNICODE
710708
if (Z_TYPE_P(the_var) != IS_STRING || Z_TYPE_P(the_var) == IS_UNICODE)
709+
#else
710+
if (Z_TYPE_P(the_var) != IS_STRING)
711711
#endif
712712
{
713713
if (!copies || !copies[i]) {
@@ -717,7 +717,7 @@ mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar **buf, zend_uchar
717717
}
718718
}
719719
the_var = copies[i];
720-
#if PHP_MAJOR_VERSION >= 6
720+
#if MYSQLND_UNICODE
721721
if (Z_TYPE_P(the_var) == IS_UNICODE) {
722722
zval_unicode_to_string_ex(the_var, UG(utf8_conv) TSRMLS_CC);
723723
}

ext/mysqlnd/mysqlnd_result.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ mysqlnd_fetch_row_unbuffered(MYSQLND_RES * result, void *param, unsigned int fla
814814
*/
815815
Z_ADDREF_P(data);
816816
if (zend_hash_key->is_numeric == FALSE) {
817-
#if PHP_MAJOR_VERSION >= 6
817+
#if MYSQLND_UNICODE
818818
zend_u_hash_quick_update(Z_ARRVAL_P(row), IS_UNICODE,
819819
zend_hash_key->ustr,
820820
zend_hash_key->ulen + 1,
@@ -1069,7 +1069,7 @@ mysqlnd_fetch_row_buffered(MYSQLND_RES * result, void *param, unsigned int flags
10691069
*/
10701070
Z_ADDREF_P(data);
10711071
if (zend_hash_key->is_numeric == FALSE) {
1072-
#if PHP_MAJOR_VERSION >= 6
1072+
#if MYSQLND_UNICODE
10731073
zend_u_hash_quick_update(Z_ARRVAL_P(row), IS_UNICODE,
10741074
zend_hash_key->ustr,
10751075
zend_hash_key->ulen + 1,

ext/mysqlnd/mysqlnd_result_meta.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ mysqlnd_is_key_numeric(char *key, size_t length, long *idx)
9292
/* }}} */
9393

9494

95-
#if PHP_MAJOR_VERSION >= 6
95+
#if MYSQLND_UNICODE
9696
/* {{{ mysqlnd_unicode_is_key_numeric */
9797
static zend_bool
9898
mysqlnd_unicode_is_key_numeric(UChar *key, size_t length, long *idx)
@@ -142,7 +142,7 @@ MYSQLND_METHOD(mysqlnd_res_meta, read_metadata)(MYSQLND_RES_METADATA * const met
142142
{
143143
unsigned int i = 0;
144144
MYSQLND_PACKET_RES_FIELD * field_packet;
145-
#if PHP_MAJOR_VERSION >= 6
145+
#if MYSQLND_UNICODE
146146
UChar *ustr;
147147
int ulen;
148148
#endif
@@ -227,7 +227,7 @@ MYSQLND_METHOD(mysqlnd_res_meta, read_metadata)(MYSQLND_RES_METADATA * const met
227227

228228
}
229229

230-
#if PHP_MAJOR_VERSION >= 6
230+
#if MYSQLND_UNICODE
231231
zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen,
232232
meta->fields[i].name,
233233
meta->fields[i].name_length TSRMLS_CC);
@@ -284,7 +284,7 @@ MYSQLND_METHOD(mysqlnd_res_meta, free)(MYSQLND_RES_METADATA * meta TSRMLS_DC)
284284

285285
if (meta->zend_hash_keys) {
286286
DBG_INF("Freeing zend_hash_keys");
287-
#if PHP_MAJOR_VERSION >= 6
287+
#if MYSQLND_UNICODE
288288
if (UG(unicode)) {
289289
for (i = 0; i < meta->field_count; i++) {
290290
if (meta->zend_hash_keys[i].ustr.v) {
@@ -380,7 +380,7 @@ MYSQLND_METHOD(mysqlnd_res_meta, clone_metadata)(const MYSQLND_RES_METADATA * co
380380
/* copy the trailing \0 too */
381381
memcpy(new_fields[i].def, orig_fields[i].def, orig_fields[i].def_length + 1);
382382
}
383-
#if PHP_MAJOR_VERSION >= 6
383+
#if MYSQLND_UNICODE
384384
if (new_meta->zend_hash_keys[i].ustr.u) {
385385
new_meta->zend_hash_keys[i].ustr.u =
386386
eustrndup(new_meta->zend_hash_keys[i].ustr.u, new_meta->zend_hash_keys[i].ulen);

ext/mysqlnd/mysqlnd_statistics.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,14 @@ mysqlnd_fill_stats_hash(const MYSQLND_STATS * const stats, const MYSQLND_STRING
203203

204204
mysqlnd_array_init(return_value, stats->count);
205205
for (i = 0; i < stats->count; i++) {
206-
#if PHP_MAJOR_VERSION >= 6
206+
#if MYSQLND_UNICODE
207207
UChar *ustr, *tstr;
208208
int ulen, tlen;
209209
#endif
210210
char tmp[25];
211211

212212
sprintf((char *)&tmp, MYSQLND_LLU_SPEC, stats->values[i]);
213-
#if PHP_MAJOR_VERSION >= 6
213+
#if MYSQLND_UNICODE
214214
zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, names[i].s, names[i].l + 1 TSRMLS_CC);
215215
zend_string_to_unicode(UG(utf8_conv), &tstr, &tlen, tmp, strlen(tmp) + 1 TSRMLS_CC);
216216
add_u_assoc_unicode_ex(return_value, IS_UNICODE, ZSTR(ustr), ulen, tstr, 1);

ext/mysqlnd/mysqlnd_structs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ struct mysqlnd_field_hash_key
788788
{
789789
zend_bool is_numeric;
790790
unsigned long key;
791-
#if PHP_MAJOR_VERSION >= 6
791+
#if MYSQLND_UNICODE
792792
zstr ustr;
793793
unsigned int ulen;
794794
#endif

0 commit comments

Comments
 (0)