(#477) Replace all instances of malloc with nth_alloc

master
rexim 2018-11-05 19:41:51 +07:00
parent 5e7d3cb389
commit 9d160a8438
28 changed files with 110 additions and 73 deletions

View File

@ -137,6 +137,10 @@ add_executable(repl
src/ebisp/gc.c
src/str.h
src/str.c
src/system/log.h
src/system/log.c
src/system/nth_alloc.h
src/system/nth_alloc.c
)
add_executable(nothing_test
src/ebisp/builtins.c
@ -166,6 +170,10 @@ add_executable(nothing_test
test/main.c
test/test.h
test/tokenizer_suite.h
src/system/log.h
src/system/log.c
src/system/nth_alloc.h
src/system/nth_alloc.c
)
target_link_libraries(nothing ${SDL2_LIBRARY} ${SDL2_MIXER_LIBRARY})
target_link_libraries(nothing_test ${SDL2_LIBRARY} ${SDL2_MIXER_LIBRARY})

View File

@ -4,12 +4,13 @@
#include <stdio.h>
#include "game.h"
#include "ui/edit_field.h"
#include "game/level.h"
#include "ui/console.h"
#include "game/sound_samples.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "ui/console.h"
#include "ui/edit_field.h"
typedef enum Game_state {
GAME_STATE_RUNNING = 0,
@ -45,7 +46,7 @@ Game *create_game(const char *level_file_path,
return NULL;
}
Game *game = PUSH_LT(lt, malloc(sizeof(Game)), free);
Game *game = PUSH_LT(lt, nth_alloc(sizeof(Game)), free);
if (game == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
@ -62,7 +63,7 @@ Game *create_game(const char *level_file_path,
RETURN_LT(lt, NULL);
}
game->level_file_path = PUSH_LT(lt, malloc(sizeof(char) * (strlen(level_file_path) + 1)), free);
game->level_file_path = PUSH_LT(lt, nth_alloc(sizeof(char) * (strlen(level_file_path) + 1)), free);
if (game->level_file_path == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -6,6 +6,7 @@
#include "camera.h"
#include "sdl/renderer.h"
#include "system/error.h"
#include "system/nth_alloc.h"
#define RATIO_X 16.0f
#define RATIO_Y 9.0f
@ -33,7 +34,7 @@ static Triangle camera_triangle(const Camera *camera,
Camera *create_camera(SDL_Renderer *renderer,
Sprite_font *font)
{
Camera *camera = malloc(sizeof(Camera));
Camera *camera = nth_alloc(sizeof(Camera));
if (camera == NULL) {
throw_error(ERROR_TYPE_LIBC);

View File

@ -17,6 +17,7 @@
#include "system/line_stream.h"
#include "system/lt.h"
#include "system/lt/lt_adapters.h"
#include "system/nth_alloc.h"
#define LEVEL_LINE_MAX_LENGTH 512
@ -45,7 +46,7 @@ Level *create_level_from_file(const char *file_name)
return NULL;
}
Level *const level = PUSH_LT(lt, malloc(sizeof(Level)), free);
Level *const level = PUSH_LT(lt, nth_alloc(sizeof(Level)), free);
if (level == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -4,8 +4,9 @@
#include "math/rand.h"
#include "math/rect.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/line_stream.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#define BACKGROUND_CHUNK_COUNT 5
#define BACKGROUND_CHUNK_WIDTH 250.0f
@ -34,7 +35,7 @@ Background *create_background(Color base_color)
return NULL;
}
Background *background = PUSH_LT(lt, malloc(sizeof(Background)), free);
Background *background = PUSH_LT(lt, nth_alloc(sizeof(Background)), free);
if (background == NULL) {
RETURN_LT(lt, NULL);
}

View File

@ -5,8 +5,9 @@
#include "game/level/player.h"
#include "game/level/player/rigid_rect.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/line_stream.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
struct Boxes
{
@ -25,7 +26,7 @@ Boxes *create_boxes_from_line_stream(LineStream *line_stream)
return NULL;
}
Boxes *boxes = PUSH_LT(lt, malloc(sizeof(Boxes)), free);
Boxes *boxes = PUSH_LT(lt, nth_alloc(sizeof(Boxes)), free);
if (boxes == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
@ -39,7 +40,7 @@ Boxes *create_boxes_from_line_stream(LineStream *line_stream)
RETURN_LT(lt, NULL);
}
boxes->bodies = PUSH_LT(lt, malloc(sizeof(Rigid_rect*) * boxes->count), free);
boxes->bodies = PUSH_LT(lt, nth_alloc(sizeof(Rigid_rect*) * boxes->count), free);
if (boxes->bodies == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -7,8 +7,9 @@
#include "math/triangle.h"
#include "str.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/line_stream.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#define GOAL_RADIUS 10.0f
#define GOAL_MAX_ID_SIZE 36
@ -42,7 +43,7 @@ Goals *create_goals_from_line_stream(LineStream *line_stream)
return NULL;
}
Goals *const goals = PUSH_LT(lt, malloc(sizeof(Goals)), free);
Goals *const goals = PUSH_LT(lt, nth_alloc(sizeof(Goals)), free);
if (goals == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
@ -59,39 +60,39 @@ Goals *create_goals_from_line_stream(LineStream *line_stream)
goals->ids = PUSH_LT(
lt,
malloc(sizeof(char*) * goals->count),
nth_alloc(sizeof(char*) * goals->count),
free);
if (goals->ids == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
for (size_t i = 0; i < goals->count; ++i) {
goals->ids[i] = PUSH_LT(lt, malloc(sizeof(char) * GOAL_MAX_ID_SIZE), free);
goals->ids[i] = PUSH_LT(lt, nth_alloc(sizeof(char) * GOAL_MAX_ID_SIZE), free);
if (goals->ids[i] == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
}
goals->points = PUSH_LT(lt, malloc(sizeof(Point) * goals->count), free);
goals->points = PUSH_LT(lt, nth_alloc(sizeof(Point) * goals->count), free);
if (goals->points == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
goals->regions = PUSH_LT(lt, malloc(sizeof(Rect) * goals->count), free);
goals->regions = PUSH_LT(lt, nth_alloc(sizeof(Rect) * goals->count), free);
if (goals->regions == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
goals->colors = PUSH_LT(lt, malloc(sizeof(Color) * goals->count), free);
goals->colors = PUSH_LT(lt, nth_alloc(sizeof(Color) * goals->count), free);
if (goals->colors == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
goals->cue_states = PUSH_LT(lt, malloc(sizeof(int) * goals->count), free);
goals->cue_states = PUSH_LT(lt, nth_alloc(sizeof(int) * goals->count), free);
if (goals->cue_states == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -2,10 +2,11 @@
#include "game/camera.h"
#include "game/level/labels.h"
#include "system/error.h"
#include "system/lt.h"
#include "str.h"
#include "system/error.h"
#include "system/line_stream.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
struct Labels
{
@ -27,7 +28,7 @@ Labels *create_labels_from_line_stream(LineStream *line_stream)
return NULL;
}
Labels * const labels = PUSH_LT(lt, malloc(sizeof(Labels)), free);
Labels * const labels = PUSH_LT(lt, nth_alloc(sizeof(Labels)), free);
if (labels == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
@ -42,31 +43,31 @@ Labels *create_labels_from_line_stream(LineStream *line_stream)
RETURN_LT(lt, NULL);
}
labels->positions = PUSH_LT(lt, malloc(sizeof(Vec) * labels->count), free);
labels->positions = PUSH_LT(lt, nth_alloc(sizeof(Vec) * labels->count), free);
if (labels->positions == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
labels->colors = PUSH_LT(lt, malloc(sizeof(Color) * labels->count), free);
labels->colors = PUSH_LT(lt, nth_alloc(sizeof(Color) * labels->count), free);
if (labels->colors == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
labels->texts = PUSH_LT(lt, malloc(sizeof(char*) * labels->count), free);
labels->texts = PUSH_LT(lt, nth_alloc(sizeof(char*) * labels->count), free);
if (labels->texts == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
labels->states = PUSH_LT(lt, malloc(sizeof(float) * labels->count), free);
labels->states = PUSH_LT(lt, nth_alloc(sizeof(float) * labels->count), free);
if (labels->states == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
labels->visible = PUSH_LT(lt, malloc(sizeof(int) * labels->count), free);
labels->visible = PUSH_LT(lt, nth_alloc(sizeof(int) * labels->count), free);
if (labels->visible == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -10,6 +10,7 @@
#include "system/error.h"
#include "system/lt.h"
#include "system/line_stream.h"
#include "system/nth_alloc.h"
#define LAVA_BOINGNESS 2500.0f
@ -28,7 +29,7 @@ Lava *create_lava_from_line_stream(LineStream *line_stream)
return NULL;
}
Lava *lava = PUSH_LT(lt, malloc(sizeof(Lava)), free);
Lava *lava = PUSH_LT(lt, nth_alloc(sizeof(Lava)), free);
if (lava == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
@ -42,7 +43,7 @@ Lava *create_lava_from_line_stream(LineStream *line_stream)
RETURN_LT(lt, NULL);
}
lava->rects = PUSH_LT(lt, malloc(sizeof(Wavy_rect*) * lava->rects_count), free);
lava->rects = PUSH_LT(lt, nth_alloc(sizeof(Wavy_rect*) * lava->rects_count), free);
if (lava->rects == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -8,6 +8,7 @@
#include "system/error.h"
#include "system/line_stream.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "wavy_rect.h"
#define WAVE_PILLAR_WIDTH 10.0f
@ -28,7 +29,7 @@ Wavy_rect *create_wavy_rect(Rect rect, Color color)
return NULL;
}
Wavy_rect *wavy_rect = PUSH_LT(lt, malloc(sizeof(Wavy_rect)), free);
Wavy_rect *wavy_rect = PUSH_LT(lt, nth_alloc(sizeof(Wavy_rect)), free);
if (wavy_rect == NULL) {
throw_error(ERROR_TYPE_SDL2);
RETURN_LT(lt, NULL);

View File

@ -5,6 +5,7 @@
#include "physical_world.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#define PHYSICAL_WORLD_CAPACITY 256
#define PHYSICAL_WORLD_GRAVITY 1500.0f
@ -25,7 +26,7 @@ Physical_world *create_physical_world(void)
}
Physical_world * const physical_world =
PUSH_LT(lt, malloc(sizeof(Physical_world)), free);
PUSH_LT(lt, nth_alloc(sizeof(Physical_world)), free);
if (physical_world == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
@ -34,7 +35,7 @@ Physical_world *create_physical_world(void)
physical_world->solids =
PUSH_LT(
lt,
malloc(sizeof(Solid_ref) * PHYSICAL_WORLD_CAPACITY),
nth_alloc(sizeof(Solid_ref) * PHYSICAL_WORLD_CAPACITY),
free);
if (physical_world->solids == NULL) {
throw_error(ERROR_TYPE_LIBC);

View File

@ -9,6 +9,7 @@
#include "system/lt.h"
#include "system/lt/lt_adapters.h"
#include "system/line_stream.h"
#include "system/nth_alloc.h"
struct Platforms {
Lt *lt;
@ -27,7 +28,7 @@ Platforms *create_platforms_from_line_stream(LineStream *line_stream)
return NULL;
}
Platforms *platforms = PUSH_LT(lt, malloc(sizeof(Platforms)), free);
Platforms *platforms = PUSH_LT(lt, nth_alloc(sizeof(Platforms)), free);
if (platforms == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
@ -42,13 +43,13 @@ Platforms *create_platforms_from_line_stream(LineStream *line_stream)
RETURN_LT(lt, NULL);
}
platforms->rects = PUSH_LT(lt, malloc(sizeof(Rect) * platforms->rects_size), free);
platforms->rects = PUSH_LT(lt, nth_alloc(sizeof(Rect) * platforms->rects_size), free);
if (platforms->rects == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
platforms->colors = PUSH_LT(lt, malloc(sizeof(Color) * platforms->rects_size), free);
platforms->colors = PUSH_LT(lt, nth_alloc(sizeof(Color) * platforms->rects_size), free);
if (platforms->colors == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -10,8 +10,9 @@
#include "platforms.h"
#include "player.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/line_stream.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#define PLAYER_WIDTH 25.0f
#define PLAYER_HEIGHT 25.0f
@ -48,7 +49,7 @@ Player *create_player(float x, float y, Color color)
return NULL;
}
Player *player = PUSH_LT(lt, malloc(sizeof(Player)), free);
Player *player = PUSH_LT(lt, nth_alloc(sizeof(Player)), free);
if (player == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -5,6 +5,7 @@
#include "math/rand.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#define DYING_RECT_PIECE_COUNT 20
#define DYING_RECT_PIECE_SIZE 20.0f
@ -36,7 +37,7 @@ Dying_rect *create_dying_rect(Color color,
return NULL;
}
Dying_rect *dying_rect = PUSH_LT(lt, malloc(sizeof(Dying_rect)), free);
Dying_rect *dying_rect = PUSH_LT(lt, nth_alloc(sizeof(Dying_rect)), free);
if (dying_rect == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
@ -48,7 +49,7 @@ Dying_rect *create_dying_rect(Color color,
dying_rect->duration = duration;
dying_rect->time_passed = duration;
dying_rect->pieces = PUSH_LT(lt, malloc(sizeof(Piece) * DYING_RECT_PIECE_COUNT), free);
dying_rect->pieces = PUSH_LT(lt, nth_alloc(sizeof(Piece) * DYING_RECT_PIECE_COUNT), free);
if (dying_rect->pieces == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -9,8 +9,9 @@
#include "rigid_rect.h"
#include "str.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/line_stream.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#define RIGID_RECT_MAX_ID_SIZE 36
@ -61,14 +62,14 @@ Rigid_rect *create_rigid_rect(Rect rect, Color color, const char *id)
return NULL;
}
Rigid_rect *rigid_rect = PUSH_LT(lt, malloc(sizeof(Rigid_rect)), free);
Rigid_rect *rigid_rect = PUSH_LT(lt, nth_alloc(sizeof(Rigid_rect)), free);
if (rigid_rect == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
rigid_rect->lt = lt;
rigid_rect->id = malloc(sizeof(char) * RIGID_RECT_MAX_ID_SIZE);
rigid_rect->id = nth_alloc(sizeof(char) * RIGID_RECT_MAX_ID_SIZE);
if (rigid_rect->id == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -1,16 +1,17 @@
#include <assert.h>
#include "player.h"
#include "regions.h"
#include "script.h"
#include "ebisp/gc.h"
#include "ebisp/interpreter.h"
#include "ebisp/parser.h"
#include "ebisp/scope.h"
#include "player.h"
#include "regions.h"
#include "script.h"
#include "str.h"
#include "system/error.h"
#include "system/line_stream.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
enum RegionState {
RS_PLAYER_INSIDE = 0,
@ -37,7 +38,7 @@ Regions *create_regions_from_line_stream(LineStream *line_stream, Level *level)
Regions *regions = PUSH_LT(
lt,
malloc(sizeof(Regions)),
nth_alloc(sizeof(Regions)),
free);
if (regions == NULL) {
throw_error(ERROR_TYPE_LIBC);
@ -55,7 +56,7 @@ Regions *create_regions_from_line_stream(LineStream *line_stream, Level *level)
regions->rects = PUSH_LT(
lt,
malloc(sizeof(Rect) * regions->count),
nth_alloc(sizeof(Rect) * regions->count),
free);
if (regions->rects == NULL) {
throw_error(ERROR_TYPE_LIBC);
@ -64,7 +65,7 @@ Regions *create_regions_from_line_stream(LineStream *line_stream, Level *level)
regions->scripts = PUSH_LT(
lt,
malloc(sizeof(Script*) * regions->count),
nth_alloc(sizeof(Script*) * regions->count),
free);
if (regions->scripts == NULL) {
throw_error(ERROR_TYPE_LIBC);
@ -73,7 +74,7 @@ Regions *create_regions_from_line_stream(LineStream *line_stream, Level *level)
regions->states = PUSH_LT(
lt,
malloc(sizeof(bool) * regions->count),
nth_alloc(sizeof(bool) * regions->count),
free);
if (regions->states == NULL) {
throw_error(ERROR_TYPE_LIBC);

View File

@ -9,6 +9,7 @@
#include "system/error.h"
#include "system/line_stream.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "ui/console.h"
struct Script
@ -27,7 +28,7 @@ Script *create_script_from_line_stream(LineStream *line_stream, Level *level)
return NULL;
}
Script *script = PUSH_LT(lt, malloc(sizeof(Script)), free);
Script *script = PUSH_LT(lt, nth_alloc(sizeof(Script)), free);
if (script == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -8,6 +8,7 @@
#include "sound_samples.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
struct Sound_samples
{
@ -39,7 +40,7 @@ Sound_samples *create_sound_samples(const char *sample_files[],
return NULL;
}
Sound_samples *sound_samples = PUSH_LT(lt, malloc(sizeof(Sound_samples)), free);
Sound_samples *sound_samples = PUSH_LT(lt, nth_alloc(sizeof(Sound_samples)), free);
if (sound_samples == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
@ -47,7 +48,7 @@ Sound_samples *create_sound_samples(const char *sample_files[],
sound_samples->samples = PUSH_LT(
lt,
malloc(sizeof(Mix_Chunk*) * sample_files_count),
nth_alloc(sizeof(Mix_Chunk*) * sample_files_count),
free);
if (sound_samples->samples == NULL) {
throw_error(ERROR_TYPE_LIBC);

View File

@ -8,6 +8,7 @@
#include "sprite_font.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#define FONT_ROW_SIZE 18
@ -28,7 +29,7 @@ Sprite_font *create_sprite_font_from_file(const char *bmp_file_path,
return NULL;
}
Sprite_font * const sprite_font = PUSH_LT(lt, malloc(sizeof(Sprite_font)), free);
Sprite_font * const sprite_font = PUSH_LT(lt, nth_alloc(sizeof(Sprite_font)), free);
if (sprite_font == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -5,6 +5,7 @@
#include <assert.h>
#include "str.h"
#include "system/nth_alloc.h"
char *string_duplicate(const char *str,
const char *str_end)
@ -14,7 +15,7 @@ char *string_duplicate(const char *str,
}
const size_t n = str_end == NULL ? strlen(str) : (size_t) (str_end - str);
char *dup_str = malloc(sizeof(char) * (n + 1));
char *dup_str = nth_alloc(sizeof(char) * (n + 1));
if (dup_str == NULL) {
return NULL;
}
@ -48,6 +49,7 @@ char *string_append(char *prefix, const char *suffix)
return string_duplicate(suffix, NULL);
}
/* TODO: there is not nth_realloc */
prefix = realloc(prefix, strlen(prefix) + strlen(suffix) + 1);
return strcat(prefix, suffix);
}

View File

@ -6,6 +6,7 @@
#include "line_stream.h"
#include "lt.h"
#include "lt/lt_adapters.h"
#include "system/nth_alloc.h"
struct LineStream
{
@ -29,7 +30,7 @@ LineStream *create_line_stream(const char *filename,
LineStream *line_stream = PUSH_LT(
lt,
malloc(sizeof(LineStream)),
nth_alloc(sizeof(LineStream)),
free);
if (line_stream == NULL) {
throw_error(ERROR_TYPE_LIBC);
@ -48,7 +49,7 @@ LineStream *create_line_stream(const char *filename,
line_stream->buffer = PUSH_LT(
lt,
malloc(sizeof(char) * capacity),
nth_alloc(sizeof(char) * capacity),
free);
if (line_stream->buffer == NULL) {
throw_error(ERROR_TYPE_LIBC);

View File

@ -5,6 +5,7 @@
#include "lt.h"
#include "lt/lt_slot.h"
#include "system/error.h"
#include "system/nth_alloc.h"
#define INITIAL_FRAME_BUFFER_SIZE 16
@ -17,16 +18,16 @@ struct Lt
Lt *create_lt()
{
Lt *lt = malloc(sizeof(Lt));
Lt *lt = nth_alloc(sizeof(Lt));
if(lt == NULL) {
throw_error(ERROR_TYPE_LIBC);
goto malloc_lt_fail;
goto nth_alloc_lt_fail;
}
lt->frames = malloc(sizeof(Lt_slot*) * INITIAL_FRAME_BUFFER_SIZE);
lt->frames = nth_alloc(sizeof(Lt_slot*) * INITIAL_FRAME_BUFFER_SIZE);
if (lt->frames == NULL) {
throw_error(ERROR_TYPE_LIBC);
goto malloc_lt_slots_fail;
goto nth_alloc_lt_slots_fail;
}
lt->capacity = INITIAL_FRAME_BUFFER_SIZE;
@ -34,9 +35,9 @@ Lt *create_lt()
return lt;
malloc_lt_slots_fail:
nth_alloc_lt_slots_fail:
free(lt);
malloc_lt_fail:
nth_alloc_lt_fail:
return NULL;
}

View File

@ -4,6 +4,7 @@
#include "lt_slot.h"
#include "system/error.h"
#include "system/nth_alloc.h"
struct Lt_slot
{
@ -16,7 +17,7 @@ Lt_slot *create_lt_slot(void *resource, Lt_destroy resource_destroy)
assert(resource);
assert(resource_destroy);
Lt_slot *lt_slot = malloc(sizeof(Lt_slot));
Lt_slot *lt_slot = nth_alloc(sizeof(Lt_slot));
if (lt_slot == NULL) {
throw_error(ERROR_TYPE_LIBC);
return NULL;

View File

@ -1,14 +1,15 @@
#include <assert.h>
#include "game/level.h"
#include "game/level/player/rigid_rect.h"
#include "ebisp/gc.h"
#include "ebisp/interpreter.h"
#include "ebisp/parser.h"
#include "ebisp/scope.h"
#include "game/level.h"
#include "game/level/player/rigid_rect.h"
#include "sdl/renderer.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#include "ui/console.h"
#include "ui/edit_field.h"
#include "ui/history.h"
@ -88,7 +89,7 @@ Console *create_console(Level *level,
return NULL;
}
Console *console = PUSH_LT(lt, malloc(sizeof(Console)), free);
Console *console = PUSH_LT(lt, nth_alloc(sizeof(Console)), free);
if (console == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
@ -133,7 +134,7 @@ Console *create_console(Level *level,
console->eval_result = PUSH_LT(
lt,
malloc(sizeof(char) * CONSOLE_EVAL_RESULT_SIZE),
nth_alloc(sizeof(char) * CONSOLE_EVAL_RESULT_SIZE),
free);
if (console->eval_result == NULL) {
RETURN_LT(lt, NULL);

View File

@ -6,6 +6,7 @@
#include "sdl/renderer.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
#define BUFFER_CAPACITY 256
@ -38,14 +39,14 @@ Edit_field *create_edit_field(const Sprite_font *font,
return NULL;
}
Edit_field *const edit_field = PUSH_LT(lt, malloc(sizeof(Edit_field)), free);
Edit_field *const edit_field = PUSH_LT(lt, nth_alloc(sizeof(Edit_field)), free);
if (edit_field == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);
}
edit_field->lt = lt;
edit_field->buffer = PUSH_LT(lt, malloc(sizeof(char) * (BUFFER_CAPACITY + 10)), free);
edit_field->buffer = PUSH_LT(lt, nth_alloc(sizeof(char) * (BUFFER_CAPACITY + 10)), free);
if (edit_field->buffer == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -3,9 +3,10 @@
#include <assert.h>
#include "history.h"
#include "system/lt.h"
#include "system/error.h"
#include "str.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
struct History
{
@ -26,7 +27,7 @@ History *create_history(size_t capacity)
History *history = PUSH_LT(
lt,
malloc(sizeof(History)),
nth_alloc(sizeof(History)),
free);
if (history == NULL) {
throw_error(ERROR_TYPE_LIBC);

View File

@ -9,6 +9,7 @@
#include "str.h"
#include "system/error.h"
#include "system/lt.h"
#include "system/nth_alloc.h"
struct Log
{
@ -32,7 +33,7 @@ Log *create_log(const Sprite_font *font,
return NULL;
}
Log *log = PUSH_LT(lt, malloc(sizeof(Log)), free);
Log *log = PUSH_LT(lt, nth_alloc(sizeof(Log)), free);
if (log == NULL) {
throw_error(ERROR_TYPE_LIBC);
RETURN_LT(lt, NULL);

View File

@ -3,6 +3,8 @@
#include "math/point.h"
// TODO: ui/log unit may collide with system/log unit
typedef struct Log Log;
Log *create_log(const Sprite_font *font,