summaryrefslogtreecommitdiffhomepage
path: root/object.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-03-11 11:23:38 +0100
committerJo-Philipp Wich <jo@mein.io>2021-03-11 11:39:40 +0100
commita4785102dc58ce9c8facb716f18d3aaad0538cba (patch)
treece9a42990050bdc6e44fd751718e21d5878afa4f /object.c
parent40fed16a0beb0eb4af251f6375bd9002cf05e8c5 (diff)
object: prevent registering the same ressource type multiple times
When a module registering custom ressource types, such as "fs.so", is required multiple times we need to ensure that only one instance of a given ressource type is registered, otherwise objects created after subsequent requires will cease to function since the internal type prototype mismatches. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'object.c')
-rw-r--r--object.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/object.c b/object.c
index c0a5227..df81fda 100644
--- a/object.c
+++ b/object.c
@@ -357,6 +357,13 @@ static uc_ressource_types res_types;
uc_ressource_type *
uc_ressource_type_add(const char *name, uc_prototype *proto, void (*freefn)(void *))
{
+ uc_ressource_type *existing;
+
+ existing = uc_ressource_type_lookup(name);
+
+ if (existing)
+ return existing;
+
uc_vector_grow(&res_types);
res_types.entries[res_types.count].name = name;