Skip to content

Commit 7ef035e

Browse files
committed
Add compat macros for PHP 7.4
1 parent 90435be commit 7ef035e

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

src/BSON/Iterator.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,23 +342,24 @@ static void php_phongo_iterator_it_rewind(zend_object_iterator* iter)
342342
php_phongo_iterator_rewind(intern);
343343
}
344344

345+
#if PHP_VERSION_ID >= 80000
345346
static HashTable* php_phongo_iterator_it_get_gc(zend_object_iterator* iter, zval** table, int* n)
346347
{
347348
*n = 1;
348349
*table = &iter->data;
349350
return NULL;
350351
}
352+
#endif
351353

352-
static const zend_object_iterator_funcs php_phongo_iterator_it_funcs = {
354+
static const zend_object_iterator_funcs php_phongo_iterator_it_funcs = PHONGO_ITERATOR_FUNCS(
353355
php_phongo_iterator_it_dtor,
354356
php_phongo_iterator_it_valid,
355357
php_phongo_iterator_it_get_current_data,
356358
php_phongo_iterator_it_get_current_key,
357359
php_phongo_iterator_it_move_forward,
358360
php_phongo_iterator_it_rewind,
359361
NULL,
360-
php_phongo_iterator_it_get_gc,
361-
};
362+
php_phongo_iterator_it_get_gc);
362363

363364
static zend_object_iterator* php_phongo_iterator_get_iterator(zend_class_entry* ce, zval* object, int by_ref)
364365
{

src/phongo_compat.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,42 @@ zend_bool zend_array_is_list(zend_array* array);
303303
typedef ZEND_RESULT_CODE zend_result;
304304
#endif
305305

306+
/* get_gc iterator handler was added in PHP 8.0 */
307+
#if PHP_VERSION_ID >= 80000
308+
#define PHONGO_ITERATOR_FUNCS(dtor, valid, get_current_data, get_current_key, move_forward, rewind, invalidate_current, get_gc) \
309+
{ \
310+
(dtor), \
311+
(valid), \
312+
(get_current_data), \
313+
(get_current_key), \
314+
(move_forward), \
315+
(rewind), \
316+
(invalidate_current), \
317+
(get_gc), \
318+
}
319+
#else
320+
#define PHONGO_ITERATOR_FUNCS(dtor, valid, get_current_data, get_current_key, move_forward, rewind, invalidate_current, get_gc) \
321+
{ \
322+
(dtor), \
323+
(valid), \
324+
(get_current_data), \
325+
(get_current_key), \
326+
(move_forward), \
327+
(rewind), \
328+
(invalidate_current), \
329+
}
330+
#endif
331+
332+
/* ZVAL_OBJ_COPY was added in PHP 8.0 */
333+
#ifndef ZVAL_OBJ_COPY
334+
#define ZVAL_OBJ_COPY(z, o) \
335+
do { \
336+
zval* __z = (z); \
337+
zend_object* __o = (o); \
338+
GC_ADDREF(__o); \
339+
Z_OBJ_P(__z) = __o; \
340+
Z_TYPE_INFO_P(__z) = IS_OBJECT_EX; \
341+
} while (0)
342+
#endif
343+
306344
#endif /* PHONGO_COMPAT_H */

0 commit comments

Comments
 (0)