Skip to content

Commit 6c58d5f

Browse files
author
carpentry-heartbeat[bot]
committed
Add CARP_FORCE_POLL override, CARP_MALLOC NULL checks, and poll2 test wrapper
1 parent 1a2db03 commit 6c58d5f

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/poll.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ PollEvent PollEvent_copy(PollEvent* e) {
3535
* Platform-specific Poll implementation
3636
* -------------------------------------------------------------------------- */
3737

38-
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
38+
#if defined(CARP_FORCE_POLL)
39+
#define CARP_USE_POLL 1
40+
#include <poll.h>
41+
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
3942
#define CARP_USE_KQUEUE 1
4043
#include <sys/event.h>
4144
#elif defined(__linux__)
@@ -246,6 +249,9 @@ Poll Poll_create_() {
246249
p.capacity = 16;
247250
p.count = 0;
248251
p.fds = (struct pollfd*)CARP_MALLOC(p.capacity * sizeof(struct pollfd));
252+
if (!p.fds) {
253+
p.capacity = 0;
254+
}
249255
return p;
250256
}
251257

@@ -320,6 +326,10 @@ Array Poll_wait_(Poll* p, int timeout_ms) {
320326
result.len = ready;
321327
result.capacity = ready > 0 ? ready : 1;
322328
result.data = CARP_MALLOC(result.capacity * sizeof(PollEvent));
329+
if (!result.data) {
330+
result.len = 0; result.capacity = 0;
331+
return result;
332+
}
323333

324334
int j = 0;
325335
for (int i = 0; i < p->count && j < ready; i++) {

test/poll_test_poll2.carp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; Force the POSIX poll(2) backend regardless of platform, so CI can
2+
; exercise the fallback path even on Linux (epoll) and macOS (kqueue).
3+
(add-cflag "-DCARP_FORCE_POLL")
4+
(load "poll_test.carp")

0 commit comments

Comments
 (0)