Files
wlan-ap/feeds/ucentral/ucode/patches/0004-include-add-uc_fn_thisval.patch
John Crispin 6129f525d5 udevstats: add new package
This package uses eBPF to do traffic accounting ont he WAN port

Fixes: WIFI-12183
Signed-off-by: John Crispin <john@phrozen.org>
2023-01-27 12:18:37 +01:00

103 lines
2.9 KiB
Diff

From c0e413c21f7b114a70282041a0049196869dd15f Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@nbd.name>
Date: Wed, 4 Jan 2023 14:12:43 +0100
Subject: [PATCH] include: add uc_fn_thisval()
Can be used to get rid of a layer of pointer indirection in resource type
handlers.
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
include/ucode/lib.h | 14 +++++++++++++-
include/ucode/types.h | 1 +
types.c | 22 +++++++++++++++++++---
3 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/include/ucode/lib.h b/include/ucode/lib.h
index 0709702..74d8866 100644
--- a/include/ucode/lib.h
+++ b/include/ucode/lib.h
@@ -38,14 +38,26 @@ __hidden void uc_error_message_indent(char **msg);
__hidden uc_value_t *uc_require_library(uc_vm_t *vm, uc_value_t *nameval, bool so_only);
/* vm helper */
+static inline uc_value_t *
+_uc_fn_this_res(uc_vm_t *vm)
+{
+ return vm->callframes.entries[vm->callframes.count - 1].ctx;
+}
static inline void *
_uc_fn_this(uc_vm_t *vm, const char *expected_type)
{
- return ucv_resource_dataptr(vm->callframes.entries[vm->callframes.count - 1].ctx, expected_type);
+ return ucv_resource_dataptr(_uc_fn_this_res(vm), expected_type);
+}
+
+static inline void *
+_uc_fn_thisval(uc_vm_t *vm, const char *expected_type)
+{
+ return ucv_resource_data(_uc_fn_this_res(vm), expected_type);
}
#define uc_fn_this(...) _uc_fn_this(vm, __VA_ARGS__)
+#define uc_fn_thisval(...) _uc_fn_thisval(vm, __VA_ARGS__)
static inline uc_value_t *
_uc_fn_arg(uc_vm_t *vm, size_t nargs, size_t n)
diff --git a/include/ucode/types.h b/include/ucode/types.h
index bae2dd5..22fe9a9 100644
--- a/include/ucode/types.h
+++ b/include/ucode/types.h
@@ -392,6 +392,7 @@ uc_resource_type_t *ucv_resource_type_add(uc_vm_t *, const char *, uc_value_t *,
uc_resource_type_t *ucv_resource_type_lookup(uc_vm_t *, const char *);
uc_value_t *ucv_resource_new(uc_resource_type_t *, void *);
+void *ucv_resource_data(uc_value_t *uv, const char *);
void **ucv_resource_dataptr(uc_value_t *, const char *);
uc_value_t *ucv_regexp_new(const char *, bool, bool, bool, char **);
diff --git a/types.c b/types.c
index 8a7986b..cde2221 100644
--- a/types.c
+++ b/types.c
@@ -1096,8 +1096,8 @@ ucv_resource_new(uc_resource_type_t *type, void *data)
return &res->header;
}
-void **
-ucv_resource_dataptr(uc_value_t *uv, const char *name)
+static uc_resource_t *
+ucv_resource_check(uc_value_t *uv, const char *name)
{
uc_resource_t *res = (uc_resource_t *)uv;
@@ -1109,7 +1109,23 @@ ucv_resource_dataptr(uc_value_t *uv, const char *name)
return NULL;
}
- return &res->data;
+ return res;
+}
+
+void *
+ucv_resource_data(uc_value_t *uv, const char *name)
+{
+ uc_resource_t *res = ucv_resource_check(uv, name);
+
+ return res ? res->data : NULL;
+}
+
+void **
+ucv_resource_dataptr(uc_value_t *uv, const char *name)
+{
+ uc_resource_t *res = ucv_resource_check(uv, name);
+
+ return res ? &res->data : NULL;
}
--
2.34.1