/* A stand-in for a library that hands out resources the way raylib does — a * Load that allocates, an Unload that frees, a Get that answers something the * library keeps — for programs/res-leaks.flan. Nothing here needs a window or * a library installed. * * Thing has padding after `flag` and after `w`, so a key made from its bytes * would read whatever those bytes happened to hold. */ #include #include typedef struct { int32_t id; uint8_t flag; float w; void *data; } Thing; Thing LoadThing(int32_t id) { Thing t = { id, 1, 0.5f, malloc(16) }; return t; } void UnloadThing(Thing t) { free(t.data); } /* Changes the Thing in place, as ImageFormat changes an Image. */ void ThingGrow(Thing *t) { void *d = realloc(t->data, 64); if (d != NULL) t->data = d; t->w *= 2.0f; } /* The library's own Thing, which a caller must not unload. */ Thing GetDefaultThing(void) { Thing t = { 0, 0, 0.0f, NULL }; return t; } unsigned char *LoadBytes(int32_t n) { return (unsigned char *)malloc((size_t)n); } void UnloadBytes(unsigned char *p) { free(p); }