Skip to content

Commit c1b73ff

Browse files
committed
Merge branch 'PHP-7.0'
2 parents 1265c82 + 36b4311 commit c1b73ff

File tree

6 files changed

+68
-67
lines changed

6 files changed

+68
-67
lines changed

ext/pdo/pdo_dbh.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ static PHP_METHOD(PDO, inTransaction)
667667

668668
static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /* {{{ */
669669
{
670+
zend_long lval;
670671

671672
#define PDO_LONG_PARAM_CHECK \
672673
if (Z_TYPE_P(value) != IS_LONG && Z_TYPE_P(value) != IS_STRING && Z_TYPE_P(value) != IS_FALSE && Z_TYPE_P(value) != IS_TRUE) { \
@@ -678,12 +679,12 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
678679
switch (attr) {
679680
case PDO_ATTR_ERRMODE:
680681
PDO_LONG_PARAM_CHECK;
681-
convert_to_long(value);
682-
switch (Z_LVAL_P(value)) {
682+
lval = zval_get_long(value);
683+
switch (lval) {
683684
case PDO_ERRMODE_SILENT:
684685
case PDO_ERRMODE_WARNING:
685686
case PDO_ERRMODE_EXCEPTION:
686-
dbh->error_mode = Z_LVAL_P(value);
687+
dbh->error_mode = lval;
687688
return SUCCESS;
688689
default:
689690
pdo_raise_impl_error(dbh, NULL, "HY000", "invalid error mode");
@@ -694,12 +695,12 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
694695

695696
case PDO_ATTR_CASE:
696697
PDO_LONG_PARAM_CHECK;
697-
convert_to_long(value);
698-
switch (Z_LVAL_P(value)) {
698+
lval = zval_get_long(value);
699+
switch (lval) {
699700
case PDO_CASE_NATURAL:
700701
case PDO_CASE_UPPER:
701702
case PDO_CASE_LOWER:
702-
dbh->desired_case = Z_LVAL_P(value);
703+
dbh->desired_case = lval;
703704
return SUCCESS;
704705
default:
705706
pdo_raise_impl_error(dbh, NULL, "HY000", "invalid case folding mode");
@@ -710,8 +711,7 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
710711

711712
case PDO_ATTR_ORACLE_NULLS:
712713
PDO_LONG_PARAM_CHECK;
713-
convert_to_long(value);
714-
dbh->oracle_nulls = Z_LVAL_P(value);
714+
dbh->oracle_nulls = zval_get_long(value);
715715
return SUCCESS;
716716

717717
case PDO_ATTR_DEFAULT_FETCH_MODE:
@@ -726,18 +726,17 @@ static int pdo_dbh_attribute_set(pdo_dbh_t *dbh, zend_long attr, zval *value) /*
726726
} else {
727727
PDO_LONG_PARAM_CHECK;
728728
}
729-
convert_to_long(value);
730-
if (Z_LVAL_P(value) == PDO_FETCH_USE_DEFAULT) {
729+
lval = zval_get_long(value);
730+
if (lval == PDO_FETCH_USE_DEFAULT) {
731731
pdo_raise_impl_error(dbh, NULL, "HY000", "invalid fetch mode type");
732732
return FAILURE;
733733
}
734-
dbh->default_fetch_type = Z_LVAL_P(value);
734+
dbh->default_fetch_type = lval;
735735
return SUCCESS;
736736

737737
case PDO_ATTR_STRINGIFY_FETCHES:
738738
PDO_LONG_PARAM_CHECK;
739-
convert_to_long(value);
740-
dbh->stringify = Z_LVAL_P(value) ? 1 : 0;
739+
dbh->stringify = zval_get_long(value) ? 1 : 0;
741740
return SUCCESS;
742741

743742
case PDO_ATTR_STATEMENT_CLASS: {

ext/pdo_firebird/firebird_driver.c

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -474,56 +474,65 @@ static int firebird_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *v
474474

475475
switch (attr) {
476476
case PDO_ATTR_AUTOCOMMIT:
477-
478-
convert_to_boolean(val);
479-
480-
/* ignore if the new value equals the old one */
481-
if (dbh->auto_commit ^ (Z_TYPE_P(val) == IS_TRUE? 1 : 0)) {
482-
if (dbh->in_txn) {
483-
if (Z_TYPE_P(val) == IS_TRUE) {
484-
/* turning on auto_commit with an open transaction is illegal, because
485-
we won't know what to do with it */
486-
H->last_app_error = "Cannot enable auto-commit while a transaction is already open";
487-
return 0;
488-
} else {
489-
/* close the transaction */
490-
if (!firebird_handle_commit(dbh)) {
491-
break;
477+
{
478+
zend_bool bval = zval_get_long(val)? 1 : 0;
479+
480+
/* ignore if the new value equals the old one */
481+
if (dbh->auto_commit ^ bval) {
482+
if (dbh->in_txn) {
483+
if (bval) {
484+
/* turning on auto_commit with an open transaction is illegal, because
485+
we won't know what to do with it */
486+
H->last_app_error = "Cannot enable auto-commit while a transaction is already open";
487+
return 0;
488+
} else {
489+
/* close the transaction */
490+
if (!firebird_handle_commit(dbh)) {
491+
break;
492+
}
493+
dbh->in_txn = 0;
492494
}
493-
dbh->in_txn = 0;
494495
}
496+
dbh->auto_commit = bval;
495497
}
496-
dbh->auto_commit = Z_TYPE_P(val) == IS_TRUE? 1 : 0;
497498
}
498499
return 1;
499500

500501
case PDO_ATTR_FETCH_TABLE_NAMES:
501-
convert_to_boolean(val);
502-
H->fetch_table_names = Z_TYPE_P(val) == IS_TRUE? 1 : 0;
502+
H->fetch_table_names = zval_get_long(val)? 1 : 0;
503503
return 1;
504504

505505
case PDO_FB_ATTR_DATE_FORMAT:
506-
convert_to_string(val);
507-
if (H->date_format) {
508-
efree(H->date_format);
506+
{
507+
zend_string *str = zval_get_string(val);
508+
if (H->date_format) {
509+
efree(H->date_format);
510+
}
511+
spprintf(&H->date_format, 0, "%s", ZSTR_VAL(str));
512+
zend_string_release(str);
509513
}
510-
spprintf(&H->date_format, 0, "%s", Z_STRVAL_P(val));
511514
return 1;
512515

513516
case PDO_FB_ATTR_TIME_FORMAT:
514-
convert_to_string(val);
515-
if (H->time_format) {
516-
efree(H->time_format);
517+
{
518+
zend_string *str = zval_get_string(val);
519+
if (H->time_format) {
520+
efree(H->time_format);
521+
}
522+
spprintf(&H->time_format, 0, "%s", ZSTR_VAL(str));
523+
zend_string_release(str);
517524
}
518-
spprintf(&H->time_format, 0, "%s", Z_STRVAL_P(val));
519525
return 1;
520526

521527
case PDO_FB_ATTR_TIMESTAMP_FORMAT:
522-
convert_to_string(val);
523-
if (H->timestamp_format) {
524-
efree(H->timestamp_format);
528+
{
529+
zend_string *str = zval_get_string(val);
530+
if (H->timestamp_format) {
531+
efree(H->timestamp_format);
532+
}
533+
spprintf(&H->timestamp_format, 0, "%s", ZSTR_VAL(str));
534+
zend_string_release(str);
525535
}
526-
spprintf(&H->timestamp_format, 0, "%s", Z_STRVAL_P(val));
527536
return 1;
528537
}
529538
return 0;

ext/pdo_mysql/mysql_driver.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,43 +368,40 @@ static inline int mysql_handle_autocommit(pdo_dbh_t *dbh)
368368
/* {{{ pdo_mysql_set_attribute */
369369
static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val)
370370
{
371+
zend_long lval = zval_get_long(val);
372+
zend_bool bval = lval? 1 : 0;
371373
PDO_DBG_ENTER("pdo_mysql_set_attribute");
372374
PDO_DBG_INF_FMT("dbh=%p", dbh);
373375
PDO_DBG_INF_FMT("attr=%l", attr);
374376
switch (attr) {
375377
case PDO_ATTR_AUTOCOMMIT:
376-
convert_to_boolean(val);
377378
/* ignore if the new value equals the old one */
378-
if (dbh->auto_commit ^ (Z_TYPE_P(val) == IS_TRUE)) {
379-
dbh->auto_commit = (Z_TYPE_P(val) == IS_TRUE);
379+
if (dbh->auto_commit ^ bval) {
380+
dbh->auto_commit = bval;
380381
mysql_handle_autocommit(dbh);
381382
}
382383
PDO_DBG_RETURN(1);
383384

384385
case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY:
385-
convert_to_boolean(val);
386386
/* ignore if the new value equals the old one */
387-
((pdo_mysql_db_handle *)dbh->driver_data)->buffered = (Z_TYPE_P(val) == IS_TRUE);
387+
((pdo_mysql_db_handle *)dbh->driver_data)->buffered = bval;
388388
PDO_DBG_RETURN(1);
389389
case PDO_MYSQL_ATTR_DIRECT_QUERY:
390390
case PDO_ATTR_EMULATE_PREPARES:
391-
convert_to_boolean(val);
392391
/* ignore if the new value equals the old one */
393-
((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = (Z_TYPE_P(val) == IS_TRUE);
392+
((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = bval;
394393
PDO_DBG_RETURN(1);
395394
case PDO_ATTR_FETCH_TABLE_NAMES:
396-
convert_to_boolean(val);
397-
((pdo_mysql_db_handle *)dbh->driver_data)->fetch_table_names = (Z_TYPE_P(val) == IS_TRUE);
395+
((pdo_mysql_db_handle *)dbh->driver_data)->fetch_table_names = bval;
398396
PDO_DBG_RETURN(1);
399397
#ifndef PDO_USE_MYSQLND
400398
case PDO_MYSQL_ATTR_MAX_BUFFER_SIZE:
401-
convert_to_long(val);
402-
if (Z_LVAL_P(val) < 0) {
399+
if (lval < 0) {
403400
/* TODO: Johannes, can we throw a warning here? */
404401
((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = 1024*1024;
405402
PDO_DBG_INF_FMT("Adjusting invalid buffer size to =%l", ((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size);
406403
} else {
407-
((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = Z_LVAL_P(val);
404+
((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = lval;
408405
}
409406
PDO_DBG_RETURN(1);
410407
break;

ext/pdo_oci/oci_driver.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ static int oci_handle_rollback(pdo_dbh_t *dbh) /* {{{ */
440440

441441
static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /* {{{ */
442442
{
443+
zend_long lval = zval_get_long(val);
443444
pdo_oci_db_handle *H = (pdo_oci_db_handle *)dbh->driver_data;
444445

445446
if (attr == PDO_ATTR_AUTOCOMMIT) {
@@ -454,13 +455,10 @@ static int oci_handle_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) /
454455
dbh->in_txn = 0;
455456
}
456457

457-
convert_to_long(val);
458-
459-
dbh->auto_commit = (unsigned int) (Z_LVAL_P(val)) ? 1 : 0;
458+
dbh->auto_commit = (unsigned int)lval? 1 : 0;
460459
return 1;
461460
} else if (attr == PDO_ATTR_PREFETCH) {
462-
convert_to_long(val);
463-
H->prefetch = pdo_oci_sanitize_prefetch(Z_LVAL_P(val));
461+
H->prefetch = pdo_oci_sanitize_prefetch(lval);
464462
return 1;
465463
} else {
466464
return 0;

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,16 +1152,15 @@ static const zend_function_entry *pdo_pgsql_get_driver_methods(pdo_dbh_t *dbh, i
11521152

11531153
static int pdo_pgsql_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
11541154
{
1155+
zend_bool bval = zval_get_long(val)? 1 : 0;
11551156
pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)dbh->driver_data;
11561157

11571158
switch (attr) {
11581159
case PDO_ATTR_EMULATE_PREPARES:
1159-
convert_to_long(val);
1160-
H->emulate_prepares = 0 != Z_LVAL_P(val);
1160+
H->emulate_prepares = bval;
11611161
return 1;
11621162
case PDO_PGSQL_ATTR_DISABLE_PREPARES:
1163-
convert_to_long(val);
1164-
H->disable_prepares = 0 != Z_LVAL_P(val);
1163+
H->disable_prepares = bval;
11651164
return 1;
11661165
default:
11671166
return 0;

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ static int pdo_sqlite_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
301301

302302
switch (attr) {
303303
case PDO_ATTR_TIMEOUT:
304-
convert_to_long(val);
305-
sqlite3_busy_timeout(H->db, Z_LVAL_P(val) * 1000);
304+
sqlite3_busy_timeout(H->db, zval_get_long(val) * 1000);
306305
return 1;
307306
}
308307
return 0;

0 commit comments

Comments
 (0)