diff options
author | Fabrice Bellard <fabrice@bellard.org> | 2023-12-22 11:03:44 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-12-22 15:05:54 +0100 |
commit | 140995dcac79e7fafaae52f56a31cdf7f7074fde (patch) | |
tree | 079ac605b498683dc8080aab033fd691eedd0745 /lib/quickjs | |
parent | 4c5bcfbac974718732ca9ab6729178c8a08c4cf3 (diff) | |
download | chawan-140995dcac79e7fafaae52f56a31cdf7f7074fde.tar.gz |
added container_of macro
Diffstat (limited to 'lib/quickjs')
-rw-r--r-- | lib/quickjs/cutils.h | 3 | ||||
-rw-r--r-- | lib/quickjs/list.h | 3 | ||||
-rw-r--r-- | lib/quickjs/quickjs.c | 2 |
3 files changed, 5 insertions, 3 deletions
diff --git a/lib/quickjs/cutils.h b/lib/quickjs/cutils.h index 31f7cd84..8399d614 100644 --- a/lib/quickjs/cutils.h +++ b/lib/quickjs/cutils.h @@ -49,6 +49,9 @@ #define countof(x) (sizeof(x) / sizeof((x)[0])) #endif +/* return the pointer of type 'type *' containing 'ptr' as field 'member' */ +#define container_of(ptr, type, member) ((type *)((uint8_t *)(ptr) - offsetof(type, member))) + typedef int BOOL; #ifndef FALSE diff --git a/lib/quickjs/list.h b/lib/quickjs/list.h index 0a1bc5a4..5c182340 100644 --- a/lib/quickjs/list.h +++ b/lib/quickjs/list.h @@ -36,8 +36,7 @@ struct list_head { #define LIST_HEAD_INIT(el) { &(el), &(el) } /* return the pointer of type 'type *' containing 'el' as field 'member' */ -#define list_entry(el, type, member) \ - ((type *)((uint8_t *)(el) - offsetof(type, member))) +#define list_entry(el, type, member) container_of(el, type, member) static inline void init_list_head(struct list_head *head) { diff --git a/lib/quickjs/quickjs.c b/lib/quickjs/quickjs.c index 8f348e7e..a9e89211 100644 --- a/lib/quickjs/quickjs.c +++ b/lib/quickjs/quickjs.c @@ -4088,7 +4088,7 @@ void JS_FreeCString(JSContext *ctx, const char *ptr) if (!ptr) return; /* purposely removing constness */ - p = (JSString *)(void *)(ptr - offsetof(JSString, u)); + p = container_of(ptr, JSString, u); JS_FreeValue(ctx, JS_MKPTR(JS_TAG_STRING, p)); } |