Skip to content

Commit

Permalink
types: add ucv_resource_create() helper
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Jo-Philipp Wich <[email protected]>
  • Loading branch information
jow- committed Oct 18, 2024
1 parent 9cf53dd commit 9857522
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/ucode/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,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 uc_resource_new(t, value);
}

uc_value_t *ucv_regexp_new(const char *, bool, bool, bool, char **);

uc_value_t *ucv_upvalref_new(size_t);
Expand Down

0 comments on commit 9857522

Please sign in to comment.