Skip to content

Commit 91954c2

Browse files
committed
Make usable for PECL OCI8 release for PHP 7.x
1 parent 57eb25b commit 91954c2

File tree

5 files changed

+125
-2
lines changed

5 files changed

+125
-2
lines changed

ext/oci8/oci8.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,13 @@ void php_oci_column_hash_dtor(zval *data)
14541454
if (column->descid) {
14551455
if (GC_REFCOUNT(column->descid) == 1)
14561456
zend_list_close(column->descid);
1457-
else
1457+
else {
1458+
#if PHP_VERSION_ID < 70300
14581459
GC_REFCOUNT(column->descid)--;
1460+
#else
1461+
GC_DELREF(column->descid);
1462+
#endif
1463+
}
14591464
}
14601465

14611466
if (column->data) {
@@ -1536,7 +1541,7 @@ sb4 php_oci_error(OCIError *err_p, sword errstatus)
15361541
case OCI_ERROR:
15371542
errcode = php_oci_fetch_errmsg(err_p, errbuf, sizeof(errbuf));
15381543
if (errcode) {
1539-
php_error_docref(NULL, E_WARNING, "%s", errbuf, sizeof(errbuf));
1544+
php_error_docref(NULL, E_WARNING, "%s", errbuf);
15401545
} else {
15411546
php_error_docref(NULL, E_WARNING, "failed to fetch error message");
15421547
}
@@ -1877,7 +1882,11 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
18771882
(memcmp(ZSTR_VAL(tmp->hash_key), ZSTR_VAL(hashed_details.s),
18781883
ZSTR_LEN(tmp->hash_key)) == 0)) {
18791884
connection = tmp;
1885+
#if PHP_VERSION_ID < 70300
18801886
++GC_REFCOUNT(connection->id);
1887+
#else
1888+
GC_ADDREF(connection->id);
1889+
#endif
18811890
}
18821891
} else {
18831892
PHP_OCI_REGISTER_RESOURCE(connection, le_pconnection);
@@ -1887,7 +1896,11 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
18871896
* decremented in the persistent helper
18881897
*/
18891898
if (OCI_G(old_oci_close_semantics)) {
1899+
#if PHP_VERSION_ID < 70300
18901900
++GC_REFCOUNT(connection->id);
1901+
#else
1902+
GC_ADDREF(connection->id);
1903+
#endif
18911904
}
18921905
}
18931906
smart_str_free(&hashed_details);
@@ -1898,7 +1911,11 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
18981911
} else {
18991912
/* we do not ping non-persistent connections */
19001913
smart_str_free(&hashed_details);
1914+
#if PHP_VERSION_ID < 70300
19011915
++GC_REFCOUNT(connection->id);
1916+
#else
1917+
GC_ADDREF(connection->id);
1918+
#endif
19021919
return connection;
19031920
}
19041921
} /* is_open is true? */
@@ -2040,8 +2057,10 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
20402057

20412058
/* add to the appropriate hash */
20422059
if (connection->is_persistent) {
2060+
#if PHP_VERSION_ID < 70300
20432061
new_le.ptr = connection;
20442062
new_le.type = le_pconnection;
2063+
#endif
20452064
connection->used_this_request = 1;
20462065
PHP_OCI_REGISTER_RESOURCE(connection, le_pconnection);
20472066

@@ -2050,9 +2069,17 @@ php_oci_connection *php_oci_do_connect_ex(char *username, int username_len, char
20502069
* refcount is decremented in the persistent helper
20512070
*/
20522071
if (OCI_G(old_oci_close_semantics)) {
2072+
#if PHP_VERSION_ID < 70300
20532073
++GC_REFCOUNT(connection->id);
2074+
#else
2075+
GC_ADDREF(connection->id);
2076+
#endif
20542077
}
2078+
#if PHP_VERSION_ID < 70300
20552079
zend_hash_update_mem(&EG(persistent_list), connection->hash_key, (void *)&new_le, sizeof(zend_resource));
2080+
#else
2081+
zend_register_persistent_resource_ex(connection->hash_key, connection, le_pconnection);
2082+
#endif
20562083
OCI_G(num_persistent)++;
20572084
OCI_G(num_links)++;
20582085
} else if (!exclusive) {
@@ -2447,7 +2474,11 @@ int php_oci_column_to_zval(php_oci_out_column *column, zval *value, int mode)
24472474

24482475
if (column->is_cursor) { /* REFCURSOR -> simply return the statement id */
24492476
ZVAL_RES(value, column->stmtid);
2477+
#if PHP_VERSION_ID < 70300
24502478
++GC_REFCOUNT(column->stmtid);
2479+
#else
2480+
GC_ADDREF(column->stmtid);
2481+
#endif
24512482
} else if (column->is_descr) {
24522483

24532484
if (column->data_type != SQLT_RDD) {
@@ -2491,7 +2522,11 @@ int php_oci_column_to_zval(php_oci_out_column *column, zval *value, int mode)
24912522
/* return the locator */
24922523
object_init_ex(value, oci_lob_class_entry_ptr);
24932524
add_property_resource(value, "descriptor", column->descid);
2525+
#if PHP_VERSION_ID < 70300
24942526
++GC_REFCOUNT(column->descid);
2527+
#else
2528+
GC_ADDREF(column->descid);
2529+
#endif
24952530
}
24962531
} else {
24972532
switch (column->retcode) {
@@ -2873,7 +2908,9 @@ static php_oci_spool *php_oci_get_spool(char *username, int username_len, char *
28732908
{
28742909
smart_str spool_hashed_details = {0};
28752910
php_oci_spool *session_pool = NULL;
2911+
#if PHP_VERSION_ID < 70300
28762912
zend_resource spool_le = {{0}};
2913+
#endif
28772914
zend_resource *spool_out_le = NULL;
28782915
zend_bool iserror = 0;
28792916
zval *spool_out_zv = NULL;
@@ -2920,10 +2957,14 @@ static php_oci_spool *php_oci_get_spool(char *username, int username_len, char *
29202957
iserror = 1;
29212958
goto exit_get_spool;
29222959
}
2960+
#if PHP_VERSION_ID < 70300
29232961
spool_le.ptr = session_pool;
29242962
spool_le.type = le_psessionpool;
29252963
PHP_OCI_REGISTER_RESOURCE(session_pool, le_psessionpool);
29262964
zend_hash_update_mem(&EG(persistent_list), session_pool->spool_hash_key, (void *)&spool_le, sizeof(zend_resource));
2965+
#else
2966+
zend_register_persistent_resource_ex(session_pool->spool_hash_key, session_pool, le_psessionpool);
2967+
#endif
29272968
} else if (spool_out_le->type == le_psessionpool &&
29282969
ZSTR_LEN(((php_oci_spool *)(spool_out_le->ptr))->spool_hash_key) == ZSTR_LEN(spool_hashed_details.s) &&
29292970
memcmp(ZSTR_VAL(((php_oci_spool *)(spool_out_le->ptr))->spool_hash_key), ZSTR_VAL(spool_hashed_details.s), ZSTR_LEN(spool_hashed_details.s)) == 0) {

ext/oci8/oci8_collection.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ php_oci_collection *php_oci_collection_create(php_oci_connection *connection, ch
5252

5353
collection->connection = connection;
5454
collection->collection = NULL;
55+
#if PHP_VERSION_ID < 70300
5556
++GC_REFCOUNT(collection->connection->id);
57+
#else
58+
GC_ADDREF(collection->connection->id);
59+
#endif
5660

5761
/* get type handle by name */
5862
PHP_OCI_CALL_RETURN(errstatus, OCITypeByName,

ext/oci8/oci8_interface.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,28 @@ PHP_FUNCTION(oci_register_taf_callback)
6060
if (!zend_is_callable(callback, 0, 0)) {
6161
callback_name = zend_get_callable_name(callback);
6262
php_error_docref(NULL, E_WARNING, "function '%s' is not callable", ZSTR_VAL(callback_name));
63+
#if PHP_VERSION_ID < 70300
6364
zend_string_release(callback_name);
65+
#else
66+
zend_string_release_ex(callback_name, 0);
67+
#endif
6468
RETURN_FALSE;
6569
}
6670
#else
6771
if (!zend_is_callable(callback, 0, &callback_name)) {
6872
php_error_docref(NULL, E_WARNING, "function '%s' is not callable", ZSTR_VAL(callback_name));
73+
#if PHP_VERSION_ID < 70300
6974
zend_string_release(callback_name);
75+
#else
76+
zend_string_release_ex(callback_name, 0);
77+
#endif
7078
RETURN_FALSE;
7179
}
80+
#if PHP_VERSION_ID < 70300
7281
zend_string_release(callback_name);
82+
#else
83+
zend_string_release_ex(callback_name, 0);
84+
#endif
7385
#endif
7486
}
7587

@@ -141,10 +153,18 @@ PHP_FUNCTION(oci_define_by_name)
141153
/* if (zend_hash_add(statement->defines, name, name_len, define, sizeof(php_oci_define), (void **)&tmp_define) == SUCCESS) { */
142154
zvtmp = zend_string_init(name, name_len, 0);
143155
if ((define = zend_hash_add_new_ptr(statement->defines, zvtmp, define)) != NULL) {
156+
#if PHP_VERSION_ID < 70300
144157
zend_string_release(zvtmp);
158+
#else
159+
zend_string_release_ex(zvtmp, 0);
160+
#endif
145161
} else {
146162
efree(define);
163+
#if PHP_VERSION_ID < 70300
147164
zend_string_release(zvtmp);
165+
#else
166+
zend_string_release_ex(zvtmp, 0);
167+
#endif
148168
RETURN_FALSE;
149169
}
150170

@@ -1472,7 +1492,11 @@ PHP_FUNCTION(oci_fetch_all)
14721492
zend_string *zvtmp;
14731493
zvtmp = zend_string_init(columns[ i ]->name, columns[ i ]->name_len, 0);
14741494
zend_symtable_update(Z_ARRVAL(row), zvtmp, &element);
1495+
#if PHP_VERSION_ID < 70300
14751496
zend_string_release(zvtmp);
1497+
#else
1498+
zend_string_release_ex(zvtmp, 0);
1499+
#endif
14761500
}
14771501
}
14781502

@@ -1507,7 +1531,11 @@ PHP_FUNCTION(oci_fetch_all)
15071531
array_init(&tmp);
15081532
zvtmp = zend_string_init(columns[ i ]->name, columns[ i ]->name_len, 0);
15091533
outarrs[ i ] = zend_symtable_update(Z_ARRVAL_P(array), zvtmp, &tmp);
1534+
#if PHP_VERSION_ID < 70300
15101535
zend_string_release(zvtmp);
1536+
#else
1537+
zend_string_release_ex(zvtmp, 0);
1538+
#endif
15111539
}
15121540
}
15131541

ext/oci8/oci8_lob.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ php_oci_descriptor *php_oci_lob_create (php_oci_connection *connection, zend_lon
6767
descriptor = ecalloc(1, sizeof(php_oci_descriptor));
6868
descriptor->type = (ub4) type;
6969
descriptor->connection = connection;
70+
#if PHP_VERSION_ID < 70300
7071
++GC_REFCOUNT(descriptor->connection->id);
72+
#else
73+
GC_ADDREF(descriptor->connection->id);
74+
#endif
7175

7276
PHP_OCI_CALL_RETURN(errstatus, OCIDescriptorAlloc, (connection->env, (dvoid*)&(descriptor->descriptor), descriptor->type, (size_t) 0, (dvoid **) 0));
7377

ext/oci8/oci8_statement.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ php_oci_statement *php_oci_statement_create(php_oci_connection *connection, char
111111
statement->impres_child_stmt = NULL;
112112
statement->impres_count = 0;
113113
statement->impres_flag = PHP_OCI_IMPRES_UNKNOWN; /* may or may not have Implicit Result Set children */
114+
#if PHP_VERSION_ID < 70300
114115
++GC_REFCOUNT(statement->connection->id);
116+
#else
117+
GC_ADDREF(statement->connection->id);
118+
#endif
115119

116120
if (OCI_G(default_prefetch) >= 0) {
117121
php_oci_statement_set_prefetch(statement, (ub4)OCI_G(default_prefetch));
@@ -171,8 +175,13 @@ php_oci_statement *php_oci_get_implicit_resultset(php_oci_statement *statement)
171175
statement2->has_descr = 0;
172176
statement2->stmttype = 0;
173177

178+
#if PHP_VERSION_ID < 70300
174179
GC_REFCOUNT(statement->id)++;
175180
GC_REFCOUNT(statement2->connection->id)++;
181+
#else
182+
GC_ADDREF(statement->id);
183+
GC_ADDREF(statement2->connection->id);
184+
#endif
176185

177186
php_oci_statement_set_prefetch(statement2, statement->prefetch_count);
178187

@@ -433,7 +442,11 @@ sb4 php_oci_define_callback(dvoid *ctx, OCIDefine *define, ub4 iter, dvoid **buf
433442
return OCI_ERROR;
434443
}
435444
nested_stmt->parent_stmtid = outcol->statement->id;
445+
#if PHP_VERSION_ID < 70300
436446
++GC_REFCOUNT(outcol->statement->id);
447+
#else
448+
GC_ADDREF(outcol->statement->id);
449+
#endif
437450
outcol->nested_statement = nested_stmt;
438451
outcol->stmtid = nested_stmt->id;
439452

@@ -595,11 +608,15 @@ int php_oci_statement_execute(php_oci_statement *statement, ub4 mode)
595608
for (counter = 1; counter <= colcount; counter++) {
596609
outcol = (php_oci_out_column *) ecalloc(1, sizeof(php_oci_out_column));
597610

611+
#if PHP_VERSION_ID < 70300
598612
if ((outcol = zend_hash_index_update_ptr(statement->columns, counter, outcol)) == NULL) {
599613
FREE_HASHTABLE(statement->columns);
600614
/* out of memory */
601615
return 1;
602616
}
617+
#else
618+
outcol = zend_hash_index_update_ptr(statement->columns, counter, outcol);
619+
#endif
603620

604621
/* get column */
605622
PHP_OCI_CALL_RETURN(errstatus, OCIParamGet, ((dvoid *)statement->stmt, OCI_HTYPE_STMT, statement->err, (dvoid**)&param, counter));
@@ -993,8 +1010,12 @@ int php_oci_bind_post_exec(zval *data)
9931010
* binds, php_oci_bind_out_callback() should have allocated a
9941011
* new string that we can modify here.
9951012
*/
1013+
#if PHP_VERSION_ID < 70300
9961014
SEPARATE_STRING(zv);
9971015
Z_STR_P(zv) = zend_string_extend(Z_STR_P(zv), Z_STRLEN_P(zv)+1, 0);
1016+
#else
1017+
ZVAL_NEW_STR(zv, zend_string_extend(Z_STR_P(zv), Z_STRLEN_P(zv)+1, 0));
1018+
#endif
9981019
Z_STRVAL_P(zv)[ Z_STRLEN_P(zv) ] = '\0';
9991020
} else if (Z_TYPE_P(zv) == IS_ARRAY) {
10001021
int i;
@@ -1257,7 +1278,11 @@ int php_oci_bind_by_name(php_oci_statement *statement, char *name, size_t name_l
12571278
zvtmp = zend_string_init(name, name_len, 0);
12581279
bindp = (php_oci_bind *) ecalloc(1, sizeof(php_oci_bind));
12591280
bindp = zend_hash_update_ptr(statement->binds, zvtmp, bindp);
1281+
#if PHP_VERSION_ID < 70300
12601282
zend_string_release(zvtmp);
1283+
#else
1284+
zend_string_release_ex(zvtmp, 0);
1285+
#endif
12611286
}
12621287

12631288
/* Make sure the minimum of value_sz is 1 to avoid ORA-3149
@@ -1528,6 +1553,7 @@ php_oci_out_column *php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAME
15281553
return NULL;
15291554
}
15301555
} else {
1556+
#if PHP_VERSION_ID < 70300
15311557
zval tmp;
15321558
/* NB: for PHP4 compat only, it should be using 'Z' instead */
15331559
tmp = *column_index;
@@ -1540,6 +1566,17 @@ php_oci_out_column *php_oci_statement_get_column_helper(INTERNAL_FUNCTION_PARAME
15401566
return NULL;
15411567
}
15421568
zval_ptr_dtor(&tmp);
1569+
#else
1570+
zend_long tmp;
1571+
/* NB: for PHP4 compat only, it should be using 'Z' instead */
1572+
1573+
tmp = zval_get_long(column_index);
1574+
column = php_oci_statement_get_column(statement, tmp, NULL, 0);
1575+
if (!column) {
1576+
php_error_docref(NULL, E_WARNING, "Invalid column index \"" ZEND_LONG_FMT "\"", tmp);
1577+
return NULL;
1578+
}
1579+
#endif
15431580
}
15441581
return column;
15451582
}
@@ -1602,8 +1639,13 @@ int php_oci_bind_array_by_name(php_oci_statement *statement, char *name, size_t
16021639

16031640
ZEND_ASSERT(Z_ISREF_P(var));
16041641
val = Z_REFVAL_P(var);
1642+
#if PHP_VERSION_ID < 70300
16051643
SEPARATE_ZVAL_NOREF(val);
16061644
convert_to_array(val);
1645+
#else
1646+
convert_to_array(val);
1647+
SEPARATE_ARRAY(val);
1648+
#endif
16071649

16081650
if (maxlength < -1) {
16091651
php_error_docref(NULL, E_WARNING, "Invalid max length value (" ZEND_LONG_FMT ")", maxlength);
@@ -1706,7 +1748,11 @@ int php_oci_bind_array_by_name(php_oci_statement *statement, char *name, size_t
17061748

17071749
zvtmp = zend_string_init(name, name_len, 0);
17081750
zend_hash_update_ptr(statement->binds, zvtmp, bind);
1751+
#if PHP_VERSION_ID < 70300
17091752
zend_string_release(zvtmp);
1753+
#else
1754+
zend_string_release_ex(zvtmp, 0);
1755+
#endif
17101756

17111757
statement->errcode = 0; /* retain backwards compat with OCI8 1.4 */
17121758
return 0;

0 commit comments

Comments
 (0)