Compare commits
No commits in common. "f84e3a3a27d626405173bd84055c299969cf7033" and "7b20909c540b8e87d0e4dd061cd82f5c36c79f01" have entirely different histories.
f84e3a3a27
...
7b20909c54
32
drop.c
32
drop.c
|
@ -1,38 +1,6 @@
|
||||||
#include "drop.h"
|
#include "drop.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
|
||||||
static IDrop _builtin_drop = {
|
|
||||||
.drop = free
|
|
||||||
};
|
|
||||||
|
|
||||||
void default_drop(void* data) {
|
void default_drop(void* data) {
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define impl_builtin_Drop_for(T)\
|
|
||||||
Drop T##_as_Drop(T *x) {\
|
|
||||||
return (Drop){.tc = &_builtin_drop, .data = x};\
|
|
||||||
}\
|
|
||||||
Drop T##_to_Drop(T x) {\
|
|
||||||
float *data = malloc(sizeof(float));\
|
|
||||||
return (Drop){.tc = &_builtin_drop, .data = data};\
|
|
||||||
}
|
|
||||||
|
|
||||||
void TEST_drop_builtins() {
|
|
||||||
// TEST float
|
|
||||||
float *ff = new(float);
|
|
||||||
free(ff);
|
|
||||||
Drop f = new_as(float, Drop);
|
|
||||||
f.tc->drop(f.data);
|
|
||||||
// TEST int
|
|
||||||
int *ii = new(int);
|
|
||||||
free(ii);
|
|
||||||
Drop i = new_as(int, Drop);
|
|
||||||
i.tc->drop(i.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_builtin_Drop_for(float);
|
|
||||||
impl_builtin_Drop_for(double);
|
|
||||||
impl_builtin_Drop_for(int);
|
|
||||||
impl_builtin_Drop_for(unsigned);
|
|
||||||
impl_builtin_Drop_for(size_t);
|
|
||||||
|
|
13
drop.h
13
drop.h
|
@ -2,7 +2,6 @@
|
||||||
#define CUTES_DROP_H
|
#define CUTES_DROP_H
|
||||||
|
|
||||||
#include "typeclass_helpers.h"
|
#include "typeclass_helpers.h"
|
||||||
#include "stddef.h"
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void (*const drop)(void* self);
|
void (*const drop)(void* self);
|
||||||
|
@ -31,16 +30,4 @@ Drop T##_as_Drop(T* x) {\
|
||||||
};\
|
};\
|
||||||
return (Drop){.tc = &tc, .data = x};\
|
return (Drop){.tc = &tc, .data = x};\
|
||||||
}
|
}
|
||||||
|
|
||||||
Drop float_as_Drop(float *x);
|
|
||||||
Drop float_to_Drop(float x);
|
|
||||||
Drop double_as_Drop(double *x);
|
|
||||||
Drop double_to_Drop(double x);
|
|
||||||
Drop int_as_Drop(int *x);
|
|
||||||
Drop int_to_Drop(int x);
|
|
||||||
Drop unsigned_as_Drop(unsigned *x);
|
|
||||||
Drop unsigned_to_Drop(unsigned x);
|
|
||||||
Drop size_t_as_Drop(size_t *x);
|
|
||||||
Drop size_t_to_Drop(size_t x);
|
|
||||||
|
|
||||||
#endif // !CUTES_DROP_H
|
#endif // !CUTES_DROP_H
|
||||||
|
|
2
list.c
2
list.c
|
@ -29,7 +29,7 @@ List list_with_len(size_t element_size, size_t len) {
|
||||||
|
|
||||||
List list_copy(const List* source) {
|
List list_copy(const List* source) {
|
||||||
List self = list_init(source->element_size);
|
List self = list_init(source->element_size);
|
||||||
list_set_len(&self, source->len);
|
list_set_len(&self, source->cap);
|
||||||
if(self.cap > 0) {
|
if(self.cap > 0) {
|
||||||
memcpy(self.data, source->data, source->element_size * source->len);
|
memcpy(self.data, source->data, source->element_size * source->len);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,7 +7,4 @@ __Return (*const __Name##_)(__VA_ARGS__) = __Name; (void)__Name##_
|
||||||
#define decl_typeclass_impl(__Typeclass, __Type)\
|
#define decl_typeclass_impl(__Typeclass, __Type)\
|
||||||
extern __Typeclass __Type##_as_##__Typeclass(__Type*);
|
extern __Typeclass __Type##_as_##__Typeclass(__Type*);
|
||||||
|
|
||||||
#define new(T) malloc(sizeof(T))
|
|
||||||
#define new_as(T, TC) T##_as_##TC(new(T))
|
|
||||||
|
|
||||||
#endif // !CUTES_TYPECLASS_HELPERS_H
|
#endif // !CUTES_TYPECLASS_HELPERS_H
|
||||||
|
|
Loading…
Reference in New Issue