summaryrefslogtreecommitdiffhomepage
path: root/types.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-02-07 00:20:16 +0100
committerJo-Philipp Wich <jo@mein.io>2022-02-07 00:22:12 +0100
commit11adf0c4ea91e63ec523849c2846fd07bf4348f5 (patch)
treed2c3aed28eb7c043c73b84ea3af0837225ee02a5 /types.c
parent3a49192f3a1e8a5d348cdbfccd0a16d74ba61e3d (diff)
source: convert source objects into proper uc_value_t type
Instead of implementing a custom limited refcount logic, turn uc_source_t instances into proper uc_value_t objects. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'types.c')
-rw-r--r--types.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/types.c b/types.c
index b096b71..a8de8e4 100644
--- a/types.c
+++ b/types.c
@@ -56,6 +56,7 @@ ucv_typename(uc_value_t *uv)
case UC_UPVALUE: return "upvalue";
case UC_RESOURCE: return "resource";
case UC_PROGRAM: return "program";
+ case UC_SOURCE: return "source";
}
return "unknown";
@@ -124,6 +125,7 @@ ucv_gc_mark(uc_value_t *uv)
uc_object_t *object;
uc_array_t *array;
uc_resource_t *resource;
+ uc_program_t *program;
struct lh_entry *entry;
size_t i;
@@ -184,6 +186,14 @@ ucv_gc_mark(uc_value_t *uv)
break;
+ case UC_PROGRAM:
+ program = (uc_program_t *)uv;
+
+ if (program->source)
+ ucv_gc_mark(&program->source->header);
+
+ break;
+
default:
break;
}
@@ -198,6 +208,7 @@ ucv_free(uc_value_t *uv, bool retain)
uc_closure_t *closure;
uc_program_t *program;
uc_upvalref_t *upval;
+ uc_source_t *source;
uc_regexp_t *regexp;
uc_object_t *object;
uc_array_t *array;
@@ -270,7 +281,18 @@ ucv_free(uc_value_t *uv, bool retain)
uc_program_function_free(func);
uc_vallist_free(&program->constants);
- uc_source_put(program->source);
+ ucv_put_value(&program->source->header, retain);
+ break;
+
+ case UC_SOURCE:
+ source = (uc_source_t *)uv;
+
+ if (source->runpath != source->filename)
+ free(source->runpath);
+
+ uc_vector_clear(&source->lineinfo);
+ fclose(source->fp);
+ free(source->buffer);
break;
}
@@ -1329,6 +1351,7 @@ ucv_to_json(uc_value_t *uv)
case UC_RESOURCE:
case UC_UPVALUE:
case UC_PROGRAM:
+ case UC_SOURCE:
case UC_NULL:
return NULL;
}
@@ -1672,6 +1695,14 @@ ucv_to_stringbuf_formatted(uc_vm_t *vm, uc_stringbuf_t *pb, uc_value_t *uv, size
json ? "\"" : "",
uv,
json ? "\"" : "");
+
+ break;
+
+ case UC_SOURCE:
+ ucv_stringbuf_printf(pb, "%s<source %p>%s",
+ json ? "\"" : "",
+ uv,
+ json ? "\"" : "");
}
ucv_clear_mark(uv);