diff options
author | Jo-Philipp Wich <jo@mein.io> | 2024-10-18 14:50:58 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2024-10-24 08:55:53 +0200 |
commit | b1bd7b53123e3e3b8da2fc30bda8dc22c2cdb170 (patch) | |
tree | e0970319d7c538b4bec0a4b223dc436b3f3e2b45 | |
parent | 3408edf99bf214792ea17ff3d67b08890701c2b4 (diff) |
types: add ucv_resource_create() helper
Introduce a new inline convenience function ucv_resource_create() which
simplifies creating resource values by resource type name by combining
resource type lookup and resource value creation in one call.
This function will be used in subsequent refactoring to eliminate global
static variables.
Suggested-by: Isaac de Wolff <idewolff@vincitech.nl>
[separated from original commit, move ucv_resource_create() into types.h]
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | include/ucode/types.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/include/ucode/types.h b/include/ucode/types.h index 2334029..bf8b9f2 100644 --- a/include/ucode/types.h +++ b/include/ucode/types.h @@ -422,6 +422,17 @@ 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 *); +static inline uc_value_t * +ucv_resource_create(uc_vm_t *vm, const char *typename, void *value) +{ + uc_resource_type_t *t = NULL; + + if (typename && (t = ucv_resource_type_lookup(vm, typename)) == NULL) + return NULL; + + return ucv_resource_new(t, value); +} + uc_value_t *ucv_regexp_new(const char *, bool, bool, bool, char **); uc_value_t *ucv_upvalref_new(size_t); |