diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-02-07 00:20:16 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-02-07 00:22:12 +0100 |
commit | 11adf0c4ea91e63ec523849c2846fd07bf4348f5 (patch) | |
tree | d2c3aed28eb7c043c73b84ea3af0837225ee02a5 /source.c | |
parent | 3a49192f3a1e8a5d348cdbfccd0a16d74ba61e3d (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 'source.c')
-rw-r--r-- | source.c | 44 |
1 files changed, 8 insertions, 36 deletions
@@ -31,13 +31,15 @@ uc_source_new_file(const char *path) return NULL; src = xalloc(ALIGN(sizeof(*src)) + strlen(path) + 1); + + src->header.type = UC_SOURCE; + src->header.refcount = 1; + src->fp = fp; src->buffer = NULL; src->filename = strcpy((char *)src + ALIGN(sizeof(*src)), path); src->runpath = src->filename; - src->usecount = 1; - src->lineinfo.count = 0; src->lineinfo.entries = NULL; @@ -54,12 +56,14 @@ uc_source_new_buffer(const char *name, char *buf, size_t len) return NULL; src = xalloc(ALIGN(sizeof(*src)) + strlen(name) + 1); + + src->header.type = UC_SOURCE; + src->header.refcount = 1; + src->fp = fp; src->buffer = buf; src->filename = strcpy((char *)src + ALIGN(sizeof(*src)), name); - src->usecount = 1; - src->lineinfo.count = 0; src->lineinfo.entries = NULL; @@ -91,38 +95,6 @@ uc_source_get_line(uc_source_t *source, size_t *offset) return 0; } -uc_source_t * -uc_source_get(uc_source_t *source) -{ - if (!source) - return NULL; - - source->usecount++; - - return source; -} - -void -uc_source_put(uc_source_t *source) -{ - if (!source) - return; - - if (source->usecount > 1) { - source->usecount--; - - return; - } - - if (source->runpath != source->filename) - free(source->runpath); - - uc_vector_clear(&source->lineinfo); - fclose(source->fp); - free(source->buffer); - free(source); -} - uc_source_type_t uc_source_type_test(uc_source_t *source) { |