-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introducing memory functions that abort program on failure
- Loading branch information
Showing
29 changed files
with
147 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <stdlib.h> | ||
|
||
#include "sb-common.h" | ||
|
||
void *malloc_or_die(size_t n) | ||
{ | ||
void *p = malloc(n); | ||
if (!p && 0 < n) | ||
LOG_MEMERROR(); | ||
return p; | ||
} | ||
|
||
|
||
void *malloc_array_or_die(size_t nmemb, size_t n) | ||
{ | ||
void *p = reallocarray(NULL, nmemb, n); | ||
if (!p && 0 < n) | ||
LOG_MEMERROR(); | ||
return p; | ||
} | ||
|
||
|
||
void *calloc_or_die(size_t nmemb, size_t n) | ||
{ | ||
void *p = calloc(nmemb, n); | ||
if (!p && 0 < n) | ||
LOG_MEMERROR(); | ||
return p; | ||
} | ||
|
||
|
||
void *realloc_array_or_die(void *ptr, size_t nmemb, size_t n) | ||
{ | ||
void *p = reallocarray(ptr, nmemb, n); | ||
if (!p && 0 < n) | ||
LOG_MEMERROR(); | ||
return p; | ||
} | ||
|
||
|
||
void *realloc_or_die(void *ptr, size_t n) | ||
{ | ||
void *p = realloc(ptr, n); | ||
if (!p && 0 < n) | ||
LOG_MEMERROR(); | ||
return p; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <stdlib.h> | ||
|
||
#define FREE(p) do { \ | ||
if (PREDICT_LIKELY((p)!=NULL)) \ | ||
free(p); \ | ||
p = NULL; \ | ||
} while (0) | ||
|
||
#define MALLOC_TYPE(t) ((t)malloc_or_die(sizeof(t))) | ||
|
||
void *reallocarray(void *optr, size_t nmemb, size_t size); | ||
|
||
void *realloc_array_or_die(void *ptr, size_t nmemb, size_t n); | ||
void *malloc_array_or_die(size_t nmemb, size_t n); | ||
void *malloc_or_die(size_t n); | ||
void *calloc_or_die(size_t nmemb, size_t n); | ||
void *realloc_or_die(void *ptr, size_t n); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.