summaryrefslogtreecommitdiffstats
path: root/event-build.patch
blob: 453a4a67bf0e2d57ca2ce2deab804fe8d445e539 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
From cec64c28a80b2644cce2e9cd6c1fbfecb6439957 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
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 >= 0x02011000
+					| 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 >= 0x02011000
 	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 >= 0x02011000
+					| 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 >= 0x02011000
 	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 < 0x02011000) {
     die('skip this test is for libevent version >= 2.1');
 }
 ?>
-- 
2.41.0