Skip to content

Commit a782f23

Browse files
committed
PHP 8 - fixing segfaults
1 parent 4da3b23 commit a782f23

Some content is hidden

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

52 files changed

+677
-530
lines changed

ext/php_driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef int pid_t;
4646
# error PHP 5.6.0 or later is required in order to build the driver
4747
#endif
4848

49-
#if PHP_VERSION_ID >= 80000
49+
#if PHP_MAJOR_VERSION >= 8
5050
#ifndef TSRMLS_D
5151
#define TSRMLS_D void
5252
#define TSRMLS_DC

ext/src/BatchStatement.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static zend_object_handlers php_driver_batch_statement_handlers;
125125

126126
static HashTable *
127127
php_driver_batch_statement_properties(
128-
#if PHP_VERSION_ID >= 80000
128+
#if PHP_MAJOR_VERSION >= 8
129129
zend_object *object TSRMLS_DC
130130
#else
131131
zval *object TSRMLS_DC
@@ -140,6 +140,9 @@ php_driver_batch_statement_properties(
140140
static int
141141
php_driver_batch_statement_compare(zval *obj1, zval *obj2 TSRMLS_DC)
142142
{
143+
#if PHP_MAJOR_VERSION >= 8
144+
ZEND_COMPARE_OBJECTS_FALLBACK(obj1, obj2);
145+
#endif
143146
if (Z_OBJCE_P(obj1) != Z_OBJCE_P(obj2))
144147
return 1; /* different classes */
145148

@@ -182,14 +185,10 @@ void php_driver_define_BatchStatement(TSRMLS_D)
182185

183186
memcpy(&php_driver_batch_statement_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
184187
php_driver_batch_statement_handlers.get_properties = php_driver_batch_statement_properties;
185-
#if PHP_VERSION_ID >= 80000
186-
php_driver_batch_statement_handlers.compare = php_driver_batch_statement_compare;
187-
#else
188-
#if PHP_VERSION_ID >= 80000
188+
#if PHP_MAJOR_VERSION >= 8
189189
php_driver_batch_statement_handlers.compare = php_driver_batch_statement_compare;
190190
#else
191191
php_driver_batch_statement_handlers.compare_objects = php_driver_batch_statement_compare;
192-
#endif
193192
#endif
194193
php_driver_batch_statement_handlers.clone_obj = NULL;
195194
}

ext/src/Bigint.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ static php_driver_value_handlers php_driver_bigint_handlers;
395395

396396
static HashTable *
397397
php_driver_bigint_gc(
398-
#if PHP_VERSION_ID >= 80000
398+
#if PHP_MAJOR_VERSION >= 8
399399
zend_object *object,
400400
#else
401401
zval *object,
@@ -409,7 +409,7 @@ php_driver_bigint_gc(
409409

410410
static HashTable *
411411
php_driver_bigint_properties(
412-
#if PHP_VERSION_ID >= 80000
412+
#if PHP_MAJOR_VERSION >= 8
413413
zend_object *object TSRMLS_DC
414414
#else
415415
zval *object TSRMLS_DC
@@ -419,13 +419,11 @@ php_driver_bigint_properties(
419419
php5to7_zval type;
420420
php5to7_zval value;
421421

422-
php_driver_numeric *self = PHP_DRIVER_GET_NUMERIC(
423-
#if PHP_VERSION_ID >= 80000
424-
(zval*) object
422+
#if PHP_MAJOR_VERSION >= 8
423+
php_driver_numeric *self = PHP5TO7_ZEND_OBJECT_GET(numeric, object);
425424
#else
426-
object
425+
php_driver_numeric *self = PHP_DRIVER_GET_NUMERIC(object);
427426
#endif
428-
);
429427
HashTable *props = zend_std_get_properties(object TSRMLS_CC);
430428

431429
type = php_driver_type_scalar(CASS_VALUE_TYPE_BIGINT TSRMLS_CC);
@@ -441,6 +439,9 @@ php_driver_bigint_properties(
441439
static int
442440
php_driver_bigint_compare(zval *obj1, zval *obj2 TSRMLS_DC)
443441
{
442+
#if PHP_MAJOR_VERSION >= 8
443+
ZEND_COMPARE_OBJECTS_FALLBACK(obj1, obj2);
444+
#endif
444445
php_driver_numeric *bigint1 = NULL;
445446
php_driver_numeric *bigint2 = NULL;
446447

@@ -467,20 +468,18 @@ php_driver_bigint_hash_value(zval *obj TSRMLS_DC)
467468

468469
static int
469470
php_driver_bigint_cast(
470-
#if PHP_VERSION_ID >= 80000
471-
zend_object *object,
471+
#if PHP_MAJOR_VERSION >= 8
472+
zend_object *object,
472473
#else
473-
zval *object,
474+
zval *object,
474475
#endif
475-
zval *retval, int type TSRMLS_DC)
476+
zval *retval, int type TSRMLS_DC)
476477
{
477-
php_driver_numeric *self = PHP_DRIVER_GET_NUMERIC(
478-
#if PHP_VERSION_ID >= 80000
479-
(zval*) object
478+
#if PHP_MAJOR_VERSION >= 8
479+
php_driver_numeric *self = PHP5TO7_ZEND_OBJECT_GET(numeric, object);
480480
#else
481-
object
481+
php_driver_numeric *self = PHP_DRIVER_GET_NUMERIC(object);
482482
#endif
483-
);
484483

485484
switch (type) {
486485
case IS_LONG:
@@ -531,7 +530,11 @@ void php_driver_define_Bigint(TSRMLS_D)
531530
#if PHP_VERSION_ID >= 50400
532531
php_driver_bigint_handlers.std.get_gc = php_driver_bigint_gc;
533532
#endif
534-
php_driver_bigint_handlers.std.compare = php_driver_bigint_compare;
533+
#if PHP_MAJOR_VERSION >= 8
534+
php_driver_bigint_handlers.std.compare = php_driver_bigint_compare;
535+
#else
536+
php_driver_bigint_handlers.std.compare_objects = php_driver_bigint_compare;
537+
#endif
535538
php_driver_bigint_handlers.std.cast_object = php_driver_bigint_cast;
536539

537540
php_driver_bigint_handlers.hash_value = php_driver_bigint_hash_value;

ext/src/Blob.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,13 @@ static php_driver_value_handlers php_driver_blob_handlers;
114114

115115
static HashTable *
116116
php_driver_blob_gc(
117-
#if PHP_VERSION_ID >= 80000
117+
#if PHP_MAJOR_VERSION >= 8
118118
zend_object *object,
119119
#else
120120
zval *object,
121121
#endif
122-
php5to7_zval_gc table, int *n TSRMLS_DC)
122+
php5to7_zval_gc table, int *n TSRMLS_DC
123+
)
123124
{
124125
*table = NULL;
125126
*n = 0;
@@ -128,10 +129,10 @@ php_driver_blob_gc(
128129

129130
static HashTable *
130131
php_driver_blob_properties(
131-
#if PHP_VERSION_ID >= 80000
132-
zend_object *object TSRMLS_DC
132+
#if PHP_MAJOR_VERSION >= 8
133+
zend_object *object
133134
#else
134-
zval *object TSRMLS_DC
135+
zval *object TSRMLS_DC
135136
#endif
136137
)
137138
{
@@ -140,13 +141,11 @@ php_driver_blob_properties(
140141
php5to7_zval type;
141142
php5to7_zval bytes;
142143

143-
php_driver_blob *self = PHP_DRIVER_GET_BLOB(
144-
#if PHP_VERSION_ID >= 80000
145-
(zval*) object
144+
#if PHP_MAJOR_VERSION >= 8
145+
php_driver_blob *self = PHP5TO7_ZEND_OBJECT_GET(blob, object);
146146
#else
147-
object
147+
php_driver_blob *self = PHP_DRIVER_GET_BLOB(object);
148148
#endif
149-
);
150149
HashTable *props = zend_std_get_properties(object TSRMLS_CC);
151150

152151
type = php_driver_type_scalar(CASS_VALUE_TYPE_BLOB TSRMLS_CC);
@@ -164,6 +163,9 @@ php_driver_blob_properties(
164163
static int
165164
php_driver_blob_compare(zval *obj1, zval *obj2 TSRMLS_DC)
166165
{
166+
#if PHP_MAJOR_VERSION >= 8
167+
ZEND_COMPARE_OBJECTS_FALLBACK(obj1, obj2);
168+
#endif
167169
php_driver_blob *blob1 = NULL;
168170
php_driver_blob *blob2 = NULL;
169171

@@ -223,10 +225,10 @@ void php_driver_define_Blob(TSRMLS_D)
223225
#if PHP_VERSION_ID >= 50400
224226
php_driver_blob_handlers.std.get_gc = php_driver_blob_gc;
225227
#endif
226-
#if PHP_VERSION_ID >= 80000
228+
#if PHP_MAJOR_VERSION >= 8
227229
php_driver_blob_handlers.std.compare = php_driver_blob_compare;
228230
#else
229-
#if PHP_VERSION_ID >= 80000
231+
#if PHP_MAJOR_VERSION >= 8
230232
php_driver_blob_handlers.std.compare = php_driver_blob_compare;
231233
#else
232234
php_driver_blob_handlers.std.compare_objects = php_driver_blob_compare;

ext/src/Cluster/Builder.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ static zend_object_handlers php_driver_cluster_builder_handlers;
10641064

10651065
static HashTable*
10661066
php_driver_cluster_builder_gc(
1067-
#if PHP_VERSION_ID >= 80000
1067+
#if PHP_MAJOR_VERSION >= 8
10681068
zend_object *object,
10691069
#else
10701070
zval *object,
@@ -1079,7 +1079,7 @@ php_driver_cluster_builder_gc(
10791079

10801080
static HashTable*
10811081
php_driver_cluster_builder_properties(
1082-
#if PHP_VERSION_ID >= 80000
1082+
#if PHP_MAJOR_VERSION >= 8
10831083
zend_object *object TSRMLS_DC
10841084
#else
10851085
zval *object TSRMLS_DC
@@ -1121,7 +1121,7 @@ php_driver_cluster_builder_properties(
11211121
php5to7_zval connectionHeartbeatInterval;
11221122

11231123
php_driver_cluster_builder *self = PHP_DRIVER_GET_CLUSTER_BUILDER(
1124-
#if PHP_VERSION_ID >= 80000
1124+
#if PHP_MAJOR_VERSION >= 8
11251125
(zval*) object
11261126
#else
11271127
object
@@ -1461,10 +1461,10 @@ void php_driver_define_ClusterBuilder(TSRMLS_D)
14611461
#if PHP_VERSION_ID >= 50400
14621462
php_driver_cluster_builder_handlers.get_gc = php_driver_cluster_builder_gc;
14631463
#endif
1464-
#if PHP_VERSION_ID >= 80000
1464+
#if PHP_MAJOR_VERSION >= 8
14651465
php_driver_cluster_builder_handlers.compare = php_driver_cluster_builder_compare;
14661466
#else
1467-
#if PHP_VERSION_ID >= 80000
1467+
#if PHP_MAJOR_VERSION >= 8
14681468
php_driver_cluster_builder_handlers.compare = php_driver_cluster_builder_compare;
14691469
#else
14701470
php_driver_cluster_builder_handlers.compare_objects = php_driver_cluster_builder_compare;

ext/src/Collection.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_value, 0, ZEND_RETURN_VALUE, 1)
283283
ZEND_ARG_INFO(0, value)
284284
ZEND_END_ARG_INFO()
285285

286+
#if PHP_MAJOR_VERSION >= 8
287+
ZEND_BEGIN_ARG_INFO_EX(arginfo_values, 0, ZEND_RETURN_VALUE, 1)
288+
ZEND_ARG_VARIADIC_INFO(0, value)
289+
ZEND_END_ARG_INFO()
290+
#endif
291+
286292
ZEND_BEGIN_ARG_INFO_EX(arginfo_index, 0, ZEND_RETURN_VALUE, 1)
287293
ZEND_ARG_INFO(0, index)
288294
ZEND_END_ARG_INFO()
@@ -294,7 +300,11 @@ static zend_function_entry php_driver_collection_methods[] = {
294300
PHP_ME(Collection, __construct, arginfo__construct, ZEND_ACC_CTOR|ZEND_ACC_PUBLIC)
295301
PHP_ME(Collection, type, arginfo_none, ZEND_ACC_PUBLIC)
296302
PHP_ME(Collection, values, arginfo_none, ZEND_ACC_PUBLIC)
303+
#if PHP_MAJOR_VERSION >= 8
304+
PHP_ME(Collection, add, arginfo_values, ZEND_ACC_PUBLIC)
305+
#else
297306
PHP_ME(Collection, add, arginfo_value, ZEND_ACC_PUBLIC)
307+
#endif
298308
PHP_ME(Collection, get, arginfo_index, ZEND_ACC_PUBLIC)
299309
PHP_ME(Collection, find, arginfo_value, ZEND_ACC_PUBLIC)
300310
/* Countable */
@@ -313,7 +323,7 @@ static php_driver_value_handlers php_driver_collection_handlers;
313323

314324
static HashTable *
315325
php_driver_collection_gc(
316-
#if PHP_VERSION_ID >= 80000
326+
#if PHP_MAJOR_VERSION >= 8
317327
zend_object *object,
318328
#else
319329
zval *object,
@@ -327,7 +337,7 @@ php_driver_collection_gc(
327337

328338
static HashTable *
329339
php_driver_collection_properties(
330-
#if PHP_VERSION_ID >= 80000
340+
#if PHP_MAJOR_VERSION >= 8
331341
zend_object *object
332342
#else
333343
zval *object TSRMLS_DC
@@ -336,13 +346,11 @@ php_driver_collection_properties(
336346
{
337347
php5to7_zval values;
338348

339-
php_driver_collection *self = PHP_DRIVER_GET_COLLECTION(
340-
#if PHP_VERSION_ID >= 80000
341-
(zval*) object
349+
#if PHP_MAJOR_VERSION >= 8
350+
php_driver_collection *self = PHP5TO7_ZEND_OBJECT_GET(collection, object);
342351
#else
343-
object
352+
php_driver_collection *self = PHP_DRIVER_GET_COLLECTION(object);
344353
#endif
345-
);
346354
HashTable *props = zend_std_get_properties(object TSRMLS_CC);
347355

348356
PHP5TO7_ZEND_HASH_UPDATE(props,
@@ -361,6 +369,9 @@ php_driver_collection_properties(
361369
static int
362370
php_driver_collection_compare(zval *obj1, zval *obj2 TSRMLS_DC)
363371
{
372+
#if PHP_MAJOR_VERSION >= 8
373+
ZEND_COMPARE_OBJECTS_FALLBACK(obj1, obj2);
374+
#endif
364375
HashPosition pos1;
365376
HashPosition pos2;
366377
php5to7_zval *current1;
@@ -460,14 +471,10 @@ void php_driver_define_Collection(TSRMLS_D)
460471
#if PHP_VERSION_ID >= 50400
461472
php_driver_collection_handlers.std.get_gc = php_driver_collection_gc;
462473
#endif
463-
#if PHP_VERSION_ID >= 80000
464-
php_driver_collection_handlers.std.compare = php_driver_collection_compare;
465-
#else
466-
#if PHP_VERSION_ID >= 80000
474+
#if PHP_MAJOR_VERSION >= 8
467475
php_driver_collection_handlers.std.compare = php_driver_collection_compare;
468476
#else
469477
php_driver_collection_handlers.std.compare_objects = php_driver_collection_compare;
470-
#endif
471478
#endif
472479
php_driver_collection_ce->ce_flags |= PHP5TO7_ZEND_ACC_FINAL;
473480
php_driver_collection_ce->create_object = php_driver_collection_new;

0 commit comments

Comments
 (0)