summaryrefslogtreecommitdiffhomepage
path: root/include
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 /include
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 'include')
-rw-r--r--include/ucode/source.h11
-rw-r--r--include/ucode/types.h6
2 files changed, 13 insertions, 4 deletions
diff --git a/include/ucode/source.h b/include/ucode/source.h
index b05e84b..e0339a4 100644
--- a/include/ucode/source.h
+++ b/include/ucode/source.h
@@ -37,8 +37,15 @@ uc_source_t *uc_source_new_buffer(const char *name, char *buf, size_t len);
size_t uc_source_get_line(uc_source_t *source, size_t *offset);
-uc_source_t *uc_source_get(uc_source_t *source);
-void uc_source_put(uc_source_t *source);
+static inline uc_source_t *
+uc_source_get(uc_source_t *source) {
+ return (uc_source_t *)ucv_get(source ? &source->header : NULL);
+}
+
+static inline void
+uc_source_put(uc_source_t *source) {
+ ucv_put(source ? &source->header : NULL);
+}
uc_source_type_t uc_source_type_test(uc_source_t *source);
diff --git a/include/ucode/types.h b/include/ucode/types.h
index ff87ca7..8e2030a 100644
--- a/include/ucode/types.h
+++ b/include/ucode/types.h
@@ -40,7 +40,8 @@ typedef enum uc_type {
UC_CLOSURE,
UC_UPVALUE,
UC_RESOURCE,
- UC_PROGRAM
+ UC_PROGRAM,
+ UC_SOURCE
} uc_type_t;
typedef struct uc_value {
@@ -66,9 +67,10 @@ typedef struct {
uc_declare_vector(uc_lineinfo_t, uint8_t);
typedef struct {
+ uc_value_t header;
char *filename, *runpath, *buffer;
FILE *fp;
- size_t usecount, off;
+ size_t off;
uc_lineinfo_t lineinfo;
} uc_source_t;