From cec64c28a80b2644cce2e9cd6c1fbfecb6439957 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 16 Oct 2023 08:39:26 +0200 Subject: [PATCH] Fix build with libevent < 2.1.10 --- php7/classes/dns.c | 12 +++++++----- php7/php_event.c | 2 ++ php8/classes/dns.c | 12 +++++++----- php8/php_event.c | 2 ++ tests/36-dns-base-construct-init-flags.phpt | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/php7/classes/dns.c b/php7/classes/dns.c index 3a7bb37..3286efa 100644 --- a/php7/classes/dns.c +++ b/php7/classes/dns.c @@ -55,11 +55,11 @@ PHP_METHOD(EventDnsBase, __construct) PHP_EVENT_ASSERT(dnsb); PHP_EVENT_ASSERT(base->base != NULL); - if (Z_TYPE_P(zinitialize) == IS_TRUE) { - flags = EVDNS_BASE_INITIALIZE_NAMESERVERS; - } else if (Z_TYPE_P(zinitialize) == IS_FALSE) { + if (Z_TYPE_P(zinitialize) == IS_FALSE) { flags = 0; #if LIBEVENT_VERSION_NUMBER >= 0x02010000 + } else if (Z_TYPE_P(zinitialize) == IS_TRUE) { + flags = EVDNS_BASE_INITIALIZE_NAMESERVERS; } else if (Z_TYPE_P(zinitialize) == IS_LONG) { long lflags = Z_LVAL_P(zinitialize); @@ -70,8 +70,10 @@ PHP_METHOD(EventDnsBase, __construct) flags = lflags; if (flags & ~(EVDNS_BASE_DISABLE_WHEN_INACTIVE - | EVDNS_BASE_INITIALIZE_NAMESERVERS - | EVDNS_BASE_NAMESERVERS_NO_DEFAULT)) { +#if LIBEVENT_VERSION_NUMBER >= 0x02010a00 + | EVDNS_BASE_NAMESERVERS_NO_DEFAULT +#endif + | EVDNS_BASE_INITIALIZE_NAMESERVERS)) { zend_throw_exception_ex(php_event_get_exception(), 0, "Invalid initialization flags"); goto fail; } diff --git a/php7/php_event.c b/php7/php_event.c index a903020..6676cad 100644 --- a/php7/php_event.c +++ b/php7/php_event.c @@ -1254,6 +1254,8 @@ PHP_MINIT_FUNCTION(event) /* Constructor initialization flags */ PHP_EVENT_REG_CLASS_CONST_LONG(php_event_dns_base_ce, DISABLE_WHEN_INACTIVE, EVDNS_BASE_DISABLE_WHEN_INACTIVE); PHP_EVENT_REG_CLASS_CONST_LONG(php_event_dns_base_ce, INITIALIZE_NAMESERVERS, EVDNS_BASE_INITIALIZE_NAMESERVERS); +#endif +#if LIBEVENT_VERSION_NUMBER >= 0x02010a00 PHP_EVENT_REG_CLASS_CONST_LONG(php_event_dns_base_ce, NAMESERVERS_NO_DEFAULT, EVDNS_BASE_NAMESERVERS_NO_DEFAULT); #endif diff --git a/php8/classes/dns.c b/php8/classes/dns.c index 075b24b..1c08c1e 100644 --- a/php8/classes/dns.c +++ b/php8/classes/dns.c @@ -55,11 +55,11 @@ PHP_EVENT_METHOD(EventDnsBase, __construct) PHP_EVENT_ASSERT(dnsb); PHP_EVENT_ASSERT(base->base != NULL); - if (Z_TYPE_P(zinitialize) == IS_TRUE) { - flags = EVDNS_BASE_INITIALIZE_NAMESERVERS; - } else if (Z_TYPE_P(zinitialize) == IS_FALSE) { + if (Z_TYPE_P(zinitialize) == IS_FALSE) { flags = 0; #if LIBEVENT_VERSION_NUMBER >= 0x02010000 + } else if (Z_TYPE_P(zinitialize) == IS_TRUE) { + flags = EVDNS_BASE_INITIALIZE_NAMESERVERS; } else if (Z_TYPE_P(zinitialize) == IS_LONG) { long lflags = Z_LVAL_P(zinitialize); @@ -70,8 +70,10 @@ PHP_EVENT_METHOD(EventDnsBase, __construct) flags = lflags; if (flags & ~(EVDNS_BASE_DISABLE_WHEN_INACTIVE - | EVDNS_BASE_INITIALIZE_NAMESERVERS - | EVDNS_BASE_NAMESERVERS_NO_DEFAULT)) { +#if LIBEVENT_VERSION_NUMBER >= 0x02010a00 + | EVDNS_BASE_NAMESERVERS_NO_DEFAULT +#endif + | EVDNS_BASE_INITIALIZE_NAMESERVERS)) { zend_throw_exception_ex(php_event_get_exception(), 0, "Invalid initialization flags"); goto fail; } diff --git a/php8/php_event.c b/php8/php_event.c index e593b80..17b66f3 100644 --- a/php8/php_event.c +++ b/php8/php_event.c @@ -1200,6 +1200,8 @@ PHP_MINIT_FUNCTION(event) /* Constructor initialization flags */ PHP_EVENT_REG_CLASS_CONST_LONG(php_event_dns_base_ce, DISABLE_WHEN_INACTIVE, EVDNS_BASE_DISABLE_WHEN_INACTIVE); PHP_EVENT_REG_CLASS_CONST_LONG(php_event_dns_base_ce, INITIALIZE_NAMESERVERS, EVDNS_BASE_INITIALIZE_NAMESERVERS); +#endif +#if LIBEVENT_VERSION_NUMBER >= 0x02010a00 PHP_EVENT_REG_CLASS_CONST_LONG(php_event_dns_base_ce, NAMESERVERS_NO_DEFAULT, EVDNS_BASE_NAMESERVERS_NO_DEFAULT); #endif diff --git a/tests/36-dns-base-construct-init-flags.phpt b/tests/36-dns-base-construct-init-flags.phpt index c0e8e7d..07cf7fc 100644 --- a/tests/36-dns-base-construct-init-flags.phpt +++ b/tests/36-dns-base-construct-init-flags.phpt @@ -7,7 +7,7 @@ if (!class_exists(EVENT_NS . "\\EventDnsBase")) { } $eventUtilClass = EVENT_NS . '\\EventUtil'; -if ($eventUtilClass::LIBEVENT_VERSION_NUMBER < 0x02010000) { +if ($eventUtilClass::LIBEVENT_VERSION_NUMBER < 0x02010a00) { die('skip this test is for libevent version >= 2.1'); } ?> -- 2.41.0