mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
1741d8c161
The debugging features previously available via JQ_DEBUG are now command-line options.
38 lines
616 B
C
38 lines
616 B
C
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "jv_alloc.h"
|
|
|
|
static void memory_exhausted() {
|
|
fprintf(stderr, "error: cannot allocate memory\n");
|
|
abort();
|
|
}
|
|
|
|
void* jv_mem_alloc(size_t sz) {
|
|
void* p = malloc(sz);
|
|
if (!p) {
|
|
memory_exhausted();
|
|
}
|
|
return p;
|
|
}
|
|
|
|
void jv_mem_free(void* p) {
|
|
free(p);
|
|
}
|
|
|
|
void* jv_mem_realloc(void* p, size_t sz) {
|
|
p = realloc(p, sz);
|
|
if (!p) {
|
|
memory_exhausted();
|
|
}
|
|
return p;
|
|
}
|
|
|
|
#ifndef NDEBUG
|
|
volatile char jv_mem_uninitialised;
|
|
__attribute__((constructor)) void jv_mem_uninit_setup(){
|
|
char* p = malloc(1);
|
|
jv_mem_uninitialised = *p;
|
|
free(p);
|
|
}
|
|
#endif
|