aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/functiontype.c2
-rw-r--r--src/stdlib/paths.c3
-rw-r--r--src/stdlib/structs.c3
-rw-r--r--src/stdlib/structs.h3
-rw-r--r--src/stdlib/types.h11
5 files changed, 4 insertions, 18 deletions
diff --git a/src/stdlib/functiontype.c b/src/stdlib/functiontype.c
index 3270e0ca..6fc0d6bf 100644
--- a/src/stdlib/functiontype.c
+++ b/src/stdlib/functiontype.c
@@ -19,5 +19,5 @@ Text_t Func$as_text(const void *fn, bool colorize, const TypeInfo_t *type) {
public
PUREFUNC bool Func$is_none(const void *obj, const TypeInfo_t *info) {
(void)info;
- return *(void **)obj == NULL;
+ return ((Closure_t *)obj)->fn == NULL;
}
diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c
index d630ad7d..74526f7d 100644
--- a/src/stdlib/paths.c
+++ b/src/stdlib/paths.c
@@ -690,10 +690,11 @@ OptionalClosure_t Path$by_line(Path_t path) {
// be closed by GC finalizers.
GC_gcollect();
f = fopen(path_str, "r");
- if (f == NULL) return NONE_CLOSURE;
}
}
+ if (f == NULL) return NONE_CLOSURE;
+
FILE **wrapper = GC_MALLOC(sizeof(FILE *));
*wrapper = f;
GC_register_finalizer(wrapper, (void *)_line_reader_cleanup, NULL, NULL, NULL);
diff --git a/src/stdlib/structs.c b/src/stdlib/structs.c
index b08d7967..885b903c 100644
--- a/src/stdlib/structs.c
+++ b/src/stdlib/structs.c
@@ -160,9 +160,8 @@ PUREFUNC public Text_t Struct$as_text(const void *obj, bool colorize, const Type
return Text$concat(text, Text(")"));
}
-PUREFUNC public bool Struct$is_none(const void *obj, const TypeInfo_t *type) { return *(bool *)(obj + type->size); }
-
public
+
void Struct$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type) {
ptrdiff_t byte_offset = 0;
ptrdiff_t bit_offset = 0;
diff --git a/src/stdlib/structs.h b/src/stdlib/structs.h
index 368a670a..a582e9fb 100644
--- a/src/stdlib/structs.h
+++ b/src/stdlib/structs.h
@@ -13,7 +13,6 @@ PUREFUNC int32_t Struct$compare(const void *x, const void *y, const TypeInfo_t *
PUREFUNC bool Struct$equal(const void *x, const void *y, const TypeInfo_t *type);
PUREFUNC bool PackedData$equal(const void *x, const void *y, const TypeInfo_t *type);
PUREFUNC Text_t Struct$as_text(const void *obj, bool colorize, const TypeInfo_t *type);
-PUREFUNC bool Struct$is_none(const void *obj, const TypeInfo_t *type);
void Struct$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type);
void Struct$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *type);
@@ -23,7 +22,6 @@ void Struct$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo
.compare = Struct$compare, \
.equal = Struct$equal, \
.as_text = Struct$as_text, \
- .is_none = Struct$is_none, \
.serialize = Struct$serialize, \
.deserialize = Struct$deserialize, \
}
@@ -34,7 +32,6 @@ void Struct$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo
.compare = Struct$compare, \
.equal = PackedData$equal, \
.as_text = Struct$as_text, \
- .is_none = Struct$is_none, \
.serialize = Struct$serialize, \
.deserialize = Struct$deserialize, \
}
diff --git a/src/stdlib/types.h b/src/stdlib/types.h
index 85567815..bd2474fa 100644
--- a/src/stdlib/types.h
+++ b/src/stdlib/types.h
@@ -102,14 +102,3 @@ Text_t Type$as_text(const void *typeinfo, bool colorize, const TypeInfo_t *type)
.tag = TypeInfoInfo, \
.TypeInfoInfo.type_str = typestr, \
.metamethods = {.serialize = cannot_serialize, .deserialize = cannot_deserialize, .as_text = Type$as_text}})
-
-#define DEFINE_OPTIONAL_TYPE(t, unpadded_size, name) \
- typedef struct { \
- union { \
- t value; \
- struct { \
- char _padding[unpadded_size]; \
- Bool_t has_value; \
- }; \
- }; \
- } name