misc: update libtf

This commit is contained in:
mcolonna 2024-04-09 14:11:46 +02:00
parent 1caa74227d
commit e37b38b1ca
6 changed files with 24 additions and 26 deletions

View file

@ -11,7 +11,7 @@ PRINTF_CODE = \
ft_strjoin stream1 stream2 utils1 utils2 ft_strjoin stream1 stream2 utils1 utils2
PRINTF_SRCS = tf_printf/src/ PRINTF_SRCS = tf_printf/src/
PRINTF_INCLUDES = ./ tf_printf/include/ PRINTF_INCLUDES = ./ tf_printf/include/
WHAT = LIBTF v7 WHAT = LIBTF v9
USED = malloc() free() write() USED = malloc() free() write()
# It works and I probably won't change it for the rest of my life # It works and I probably won't change it for the rest of my life

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/18 16:37:23 by mcolonna #+# #+# */ /* Created: 2023/12/18 16:37:23 by mcolonna #+# #+# */
/* Updated: 2024/03/11 14:03:48 by mcolonna ### ########.fr */ /* Updated: 2024/03/12 16:06:59 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,28 +14,25 @@
# define MEM_UTILS_H # define MEM_UTILS_H
# include "libtf.h" # include "libtf.h"
# include "mem_utils.h"
# include <stdlib.h> # include <stdlib.h>
typedef struct s_memclass_in *t_memclass_in; typedef struct s_memclass_in t_memclass_in;
typedef struct s_element t_element; typedef struct s_element t_element;
typedef struct s_memclass_in *t_memclass_in;
typedef struct s_element typedef struct s_element
{ {
void *address; void *address;
t_memclass_in subclass; t_memclass_in *subclass;
t_element *previous; t_element *previous;
t_element *next; t_element *next;
t_memclass_in mc; t_memclass_in *mc;
} t_element; } t_element;
typedef struct s_memclass_in typedef struct s_memclass_in
{ {
t_element *first; t_element *first;
t_element *parent_element; t_element *parent_element;
} *t_memclass_in; } t_memclass_in;
void *create_address_with_element(t_element *element, size_t size); void *create_address_with_element(t_element *element, size_t size);

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/18 11:08:16 by mcolonna #+# #+# */ /* Created: 2023/12/18 11:08:16 by mcolonna #+# #+# */
/* Updated: 2024/03/11 14:03:06 by mcolonna ### ########.fr */ /* Updated: 2024/03/12 16:05:15 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,9 +16,9 @@
t_memclass mem_newclass(t_err *err) t_memclass mem_newclass(t_err *err)
{ {
t_memclass_in r; t_memclass_in *r;
r = malloc(sizeof(struct s_memclass_in)); r = malloc(sizeof(t_memclass_in));
if (!r) if (!r)
return ((*err)("alloc error"), NULL); return ((*err)("alloc error"), NULL);
r->first = NULL; r->first = NULL;
@ -30,9 +30,9 @@ void *mem_alloc(t_err *err, t_memclass mc, size_t size)
{ {
void *r; void *r;
t_element *new_element; t_element *new_element;
t_memclass_in mc_in; t_memclass_in *mc_in;
mc_in = (t_memclass_in) mc; mc_in = (t_memclass_in *) mc;
new_element = malloc(sizeof(t_element)); new_element = malloc(sizeof(t_element));
if (!new_element) if (!new_element)
return ((*err)("alloc error"), NULL); return ((*err)("alloc error"), NULL);
@ -57,7 +57,7 @@ void mem_freeall(t_memclass mc)
if (!mc) if (!mc)
return ; return ;
el = ((t_memclass_in) mc)->first; el = ((t_memclass_in *) mc)->first;
while (el) while (el)
{ {
next = el->next; next = el->next;
@ -68,8 +68,8 @@ void mem_freeall(t_memclass mc)
free(el); free(el);
el = next; el = next;
} }
if (((t_memclass_in) mc)->parent_element) if (((t_memclass_in *) mc)->parent_element)
freeelement(((t_memclass_in) mc)->parent_element); freeelement(((t_memclass_in *) mc)->parent_element);
free(mc); free(mc);
} }
@ -86,11 +86,11 @@ void mem_free(void *address)
t_memclass mem_subclass(t_err *err, t_memclass parent) t_memclass mem_subclass(t_err *err, t_memclass parent)
{ {
t_memclass_in r; t_memclass_in *r;
t_memclass_in parent_in; t_memclass_in *parent_in;
t_element *new_element; t_element *new_element;
parent_in = (t_memclass_in) parent; parent_in = (t_memclass_in *) parent;
r = mem_newclass(err); r = mem_newclass(err);
if (!r) if (!r)
return (err("alloc error"), NULL); return (err("alloc error"), NULL);

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 14:28:19 by mcolonna #+# #+# */ /* Created: 2023/11/06 14:28:19 by mcolonna #+# #+# */
/* Updated: 2024/03/25 14:53:04 by mcolonna ### ########.fr */ /* Updated: 2024/03/25 14:45:18 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/22 13:39:04 by mcolonna #+# #+# */ /* Created: 2023/12/22 13:39:04 by mcolonna #+# #+# */
/* Updated: 2024/02/15 15:28:25 by mcolonna ### ########.fr */ /* Updated: 2024/04/09 14:05:13 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -28,7 +28,7 @@ t_string str_dup(t_err err, t_memclass mc, t_const_string str)
t_string r; t_string r;
int i; int i;
r = mem_alloc(err, mc, str_len(str) * sizeof(char)); r = mem_alloc(err, mc, (str_len(str) + 1) * sizeof(char));
if (!r) if (!r)
return (r); return (r);
i = 0; i = 0;

View file

@ -6,7 +6,7 @@
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */ /* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/26 15:05:30 by mcolonna #+# #+# */ /* Created: 2024/02/26 15:05:30 by mcolonna #+# #+# */
/* Updated: 2024/04/08 17:15:15 by mcolonna ### ########.fr */ /* Updated: 2024/04/09 13:55:56 by mcolonna ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -45,10 +45,11 @@ void display_erase(void)
void display_flush(void) void display_flush(void)
{ {
const t_memclass mc = mem_subclass(error_err, g_env.mc); const t_memclass mc = mem_subclass(error_err, g_env.mc);
t_string str;
mlx_put_image_to_window(g_env.mlx, g_env.win, g_screenbuf.img, 0, 0); mlx_put_image_to_window(g_env.mlx, g_env.win, g_screenbuf.img, 0, 0);
mlx_string_put(g_env.mlx, g_env.win, 0, 10, 0xFFFFFF, str = str_inttostr(error_err, mc, g_env.moves);
str_inttostr(error_err, mc, g_env.moves)); mlx_string_put(g_env.mlx, g_env.win, 0, 10, 0xFFFFFF, str);
mem_freeall(mc); mem_freeall(mc);
} }