Backport from xs.

This commit is contained in:
default 2022-10-25 10:39:30 +02:00
parent c0faa84162
commit 641d46cb3d
2 changed files with 6 additions and 6 deletions

10
xs.h
View File

@ -35,8 +35,8 @@ typedef char d_char;
#define xs __attribute__ ((__cleanup__ (_xs_destroy))) d_char #define xs __attribute__ ((__cleanup__ (_xs_destroy))) d_char
void *xs_free(void *ptr); void *xs_free(void *ptr);
void *_xs_realloc(void *ptr, size_t size, const char *file, int line); void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char *func);
#define xs_realloc(ptr, size) _xs_realloc(ptr, size, __FILE__, __LINE__) #define xs_realloc(ptr, size) _xs_realloc(ptr, size, __FILE__, __LINE__, __FUNCTION__)
int _xs_blk_size(int sz); int _xs_blk_size(int sz);
void _xs_destroy(char **var); void _xs_destroy(char **var);
#define xs_debug() raise(SIGTRAP) #define xs_debug() raise(SIGTRAP)
@ -85,7 +85,7 @@ const char *xs_number_str(const char *v);
#ifdef XS_IMPLEMENTATION #ifdef XS_IMPLEMENTATION
void *_xs_realloc(void *ptr, size_t size, const char *file, int line) void *_xs_realloc(void *ptr, size_t size, const char *file, int line, const char *func)
{ {
d_char *ndata = realloc(ptr, size); d_char *ndata = realloc(ptr, size);
@ -99,9 +99,9 @@ void *_xs_realloc(void *ptr, size_t size, const char *file, int line)
FILE *f = fopen("xs_memory.out", "a"); FILE *f = fopen("xs_memory.out", "a");
if (ptr != NULL) if (ptr != NULL)
fprintf(f, "%p b\n", ptr); fprintf(f, "%p r\n", ptr);
fprintf(f, "%p a %ld %s %d\n", ndata, size, file, line); fprintf(f, "%p a %ld %s %d %s\n", ndata, size, file, line, func);
fclose(f); fclose(f);
} }
#endif #endif

View File

@ -1 +1 @@
/* 223ebe7a241f24ba043b32cb30d0428ac0d1dd5f */ /* 286f556255aa224a72b778c44b837b75170becf5 */