arraylist, scoped cleanup takes a ptr

This commit is contained in:
pantonshire committed 2026-04-27 07:56:27 +01:00
1 parent 31e88525ae
commit 1dd5d52bc2
7 files changed
+40 -12

No files matched your search

+3 -2
View File
@@ -42,6 +42,7 @@ struct owd_event {
struct owd_eventloop {
struct intrusive_list event_list;
bool valid;
#if defined(OWD_EVENTLOOP_KQUEUE)
uintptr_t kqueue_timer_next;
@@ -66,7 +67,7 @@ void owd_eventloop_remove(struct owd_eventloop *el, struct owd_event *e);
int owd_eventloop_add_timer(struct owd_eventloop *el, struct owd_event *e, uint64_t millis, bool oneshot);
int owd_eventloop_add_fd(struct owd_eventloop *el, struct owd_event *e, int fd, uint32_t flags);
DEF_SCOPED_TYPE(eventloop_stack, struct owd_eventloop *, NULL, owd_eventloop_cleanup)
DEF_SCOPED_TYPE(eventloop_stack, struct owd_eventloop, (struct owd_eventloop) { .valid = false }, owd_eventloop_cleanup)
#define EVENTLOOP_STACK_SCOPED(VAL) SCOPED(eventloop_stack, struct owd_eventloop *, VAL)
#define EVENTLOOP_STACK_SCOPED(VAL) SCOPED(eventloop_stack, struct owd_eventloop, VAL)
#define EVENTLOOP_STACK_CLOSE(EL) _scoped_eventloop_stack_cleanup(EL)
+3 -3
View File
@@ -5,9 +5,9 @@
#include "scoped.h"
static inline void _close_if_nonnegative(int fd) {
if (fd >= 0)
close(fd);
static inline void _close_if_nonnegative(int *fd) {
if (*fd >= 0)
close(*fd);
}
DEF_SCOPED_TYPE(fd, int, -1, _close_if_nonnegative)
+5 -1
View File
@@ -5,7 +5,11 @@
#include "scoped.h"
#include "typecheck.h"
DEF_SCOPED_TYPE(mem, void *, NULL, free)
static inline void _mem_free(void **p) {
free(*p);
}
DEF_SCOPED_TYPE(mem, void *, NULL, _mem_free)
#define MEM_SCOPED(TYPE, VAL) SCOPED(mem, TYPE *, VAL)
#define MEM_FREE(TYPE, MEM) ({ CHECK_TYPE(TYPE **, MEM), (TYPE *)_scoped_mem_cleanup((void **)(MEM)); })
+1 -1
View File
@@ -5,7 +5,7 @@
return (UNOCCUPIED); \
} \
static inline void _scoped_##NAME##_cleanup(TYPE *_val) { \
CLEANUP_FN(*_val); \
CLEANUP_FN(_val); \
*_val = (UNOCCUPIED); \
} \
static inline void _scoped_##NAME##_cleanup_raw(void *_val) { \