#include "drop.h" #include "stdlib.h" static IDrop _builtin_drop = { .drop = free }; void default_drop(void* 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);