mirror of
https://github.com/bellard/quickjs.git
synced 2024-11-22 05:38:11 +08:00
added container_of macro
This commit is contained in:
parent
1692f2a7a3
commit
c3599515c8
3
cutils.h
3
cutils.h
@ -49,6 +49,9 @@
|
|||||||
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
#define countof(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
#endif
|
#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;
|
typedef int BOOL;
|
||||||
|
|
||||||
#ifndef FALSE
|
#ifndef FALSE
|
||||||
|
3
list.h
3
list.h
@ -36,8 +36,7 @@ struct list_head {
|
|||||||
#define LIST_HEAD_INIT(el) { &(el), &(el) }
|
#define LIST_HEAD_INIT(el) { &(el), &(el) }
|
||||||
|
|
||||||
/* return the pointer of type 'type *' containing 'el' as field 'member' */
|
/* return the pointer of type 'type *' containing 'el' as field 'member' */
|
||||||
#define list_entry(el, type, member) \
|
#define list_entry(el, type, member) container_of(el, type, member)
|
||||||
((type *)((uint8_t *)(el) - offsetof(type, member)))
|
|
||||||
|
|
||||||
static inline void init_list_head(struct list_head *head)
|
static inline void init_list_head(struct list_head *head)
|
||||||
{
|
{
|
||||||
|
@ -4064,7 +4064,7 @@ void JS_FreeCString(JSContext *ctx, const char *ptr)
|
|||||||
if (!ptr)
|
if (!ptr)
|
||||||
return;
|
return;
|
||||||
/* purposely removing constness */
|
/* 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));
|
JS_FreeValue(ctx, JS_MKPTR(JS_TAG_STRING, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user