2024-01-25 13:13:42 +00:00
|
|
|
#include "drop.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
2024-09-10 07:47:55 +00:00
|
|
|
static IDrop _builtin_drop = {
|
|
|
|
.drop = free
|
|
|
|
};
|
|
|
|
|
2024-01-25 13:13:42 +00:00
|
|
|
void default_drop(void* data) {
|
|
|
|
free(data);
|
|
|
|
}
|
2024-09-10 07:47:55 +00:00
|
|
|
|
|
|
|
#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);
|