ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
allocate.c File Reference
#include "allocate.h"
#include "error.h"
#include "internal.h"
#include "logging.h"
#include <string.h>
Include dependency graph for allocate.c:

Go to the source code of this file.

Macros

#define LOGPREFIX   "ALLOCATE"
 

Functions

void * kissat_malloc (kissat *solver, size_t bytes)
 
void kissat_free (kissat *solver, void *ptr, size_t bytes)
 
char * kissat_strdup (kissat *solver, const char *str)
 
void kissat_freestr (struct kissat *solver, char *str)
 
void * kissat_nalloc (kissat *solver, size_t n, size_t size)
 
void * kissat_calloc (kissat *solver, size_t n, size_t size)
 
void kissat_dealloc (kissat *solver, void *ptr, size_t n, size_t size)
 
void * kissat_realloc (kissat *solver, void *p, size_t old_bytes, size_t new_bytes)
 
void * kissat_nrealloc (kissat *solver, void *p, size_t o, size_t n, size_t size)
 

Macro Definition Documentation

◆ LOGPREFIX

#define LOGPREFIX   "ALLOCATE"

Definition at line 7 of file allocate.c.

Function Documentation

◆ kissat_calloc()

void * kissat_calloc ( kissat * solver,
size_t n,
size_t size )

Definition at line 97 of file allocate.c.

97 {
98 void *res;
99 if (!n || !size)
100 return 0;
101 if (MAX_SIZE_T / size < n)
102 kissat_fatal ("invalid 'kissat_calloc (..., %zu, %zu)' call", n, size);
103 res = calloc (n, size);
104 LOG4 ("calloc (%zu, %zu) = %p", n, size, res);
105 const size_t bytes = n * size;
106 if (!res)
107 kissat_fatal ("out-of-memory allocating "
108 "%zu = %zu x %zu bytes",
109 bytes, n, size);
110 inc_bytes (solver, bytes);
111 return res;
112}
void kissat_fatal(const char *fmt,...)
Definition error.c:58
#define solver
Definition kitten.c:211
#define LOG4(...)
Definition logging.h:358
unsigned long long size
Definition giaNewBdd.h:39
char * calloc()
#define MAX_SIZE_T
Definition utilities.h:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kissat_dealloc()

void kissat_dealloc ( kissat * solver,
void * ptr,
size_t n,
size_t size )

Definition at line 114 of file allocate.c.

114 {
115 if (!n || !size)
116 return;
117 if (MAX_SIZE_T / size < n)
118 kissat_fatal ("invalid 'kissat_dealloc (..., %zu, %zu)' call", n, size);
119 const size_t bytes = n * size;
120 kissat_free (solver, ptr, bytes);
121}
void kissat_free(kissat *solver, void *ptr, size_t bytes)
Definition allocate.c:61
Here is the call graph for this function:

◆ kissat_free()

void kissat_free ( kissat * solver,
void * ptr,
size_t bytes )

Definition at line 61 of file allocate.c.

61 {
62 if (ptr) {
63 LOG4 ("free (%p[%zu])", ptr, bytes);
64 dec_bytes (solver, bytes);
65 free (ptr);
66 } else
67 KISSAT_assert (!bytes);
68}
#define KISSAT_assert(ignore)
Definition global.h:13
VOID_HACK free()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kissat_freestr()

void kissat_freestr ( struct kissat * solver,
char * str )

Definition at line 75 of file allocate.c.

75 {
76 KISSAT_assert (str);
77 kissat_free (solver, str, strlen (str) + 1);
78}
int strlen()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kissat_malloc()

void * kissat_malloc ( kissat * solver,
size_t bytes )

Definition at line 49 of file allocate.c.

49 {
50 void *res;
51 if (!bytes)
52 return 0;
53 res = malloc (bytes);
54 LOG4 ("malloc (%zu) = %p", bytes, res);
55 if (!res)
56 kissat_fatal ("out-of-memory allocating %zu bytes", bytes);
57 inc_bytes (solver, bytes);
58 return res;
59}
char * malloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kissat_nalloc()

void * kissat_nalloc ( kissat * solver,
size_t n,
size_t size )

Definition at line 80 of file allocate.c.

80 {
81 void *res;
82 if (!n || !size)
83 return 0;
84 if (MAX_SIZE_T / size < n)
85 kissat_fatal ("invalid 'kissat_nalloc (..., %zu, %zu)' call", n, size);
86 const size_t bytes = n * size;
87 res = malloc (bytes);
88 LOG4 ("nalloc (%zu, %zu) = %p", n, size, res);
89 if (!res)
90 kissat_fatal ("out-of-memory allocating "
91 "%zu = %zu x %zu bytes",
92 bytes, n, size);
93 inc_bytes (solver, bytes);
94 return res;
95}
Here is the call graph for this function:

◆ kissat_nrealloc()

void * kissat_nrealloc ( kissat * solver,
void * p,
size_t o,
size_t n,
size_t size )

Definition at line 151 of file allocate.c.

152 {
153 if (!size) {
154 KISSAT_assert (!p);
155 KISSAT_assert (!o);
156 return 0;
157 }
158 const size_t max = MAX_SIZE_T / size;
159 if (max < o || max < n)
160 kissat_fatal ("invalid 'kissat_nrealloc (..., %zu, %zu, %zu)' call", o,
161 n, size);
162 return kissat_realloc (solver, p, o * size, n * size);
163}
void * kissat_realloc(kissat *solver, void *p, size_t old_bytes, size_t new_bytes)
Definition allocate.c:123
Cube * p
Definition exorList.c:222
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kissat_realloc()

void * kissat_realloc ( kissat * solver,
void * p,
size_t old_bytes,
size_t new_bytes )

Definition at line 123 of file allocate.c.

124 {
125 if (old_bytes == new_bytes)
126 return p;
127 if (!new_bytes) {
128 kissat_free (solver, p, old_bytes);
129 return 0;
130 }
131 dec_bytes (solver, old_bytes);
132#ifdef LOGGING
133 if (GET_OPTION (log) > 3)
134 kissat_begin_logging (solver, LOGPREFIX, "realloc (%p[%zu, %zu) = ", p,
135 old_bytes, new_bytes);
136#endif
137 void *res = realloc (p, new_bytes);
138#ifdef LOGGING
139 if (GET_OPTION (log) > 3) {
140 printf ("%p", res);
141 kissat_end_logging ();
142 }
143#endif
144 if (new_bytes && !res)
145 kissat_fatal ("out-of-memory reallocating from %zu to %zu bytes",
146 old_bytes, new_bytes);
147 inc_bytes (solver, new_bytes);
148 return res;
149}
#define LOGPREFIX
Definition allocate.c:7
#define GET_OPTION(N)
Definition options.h:295
char * realloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kissat_strdup()

char * kissat_strdup ( kissat * solver,
const char * str )

Definition at line 70 of file allocate.c.

70 {
71 char *res = (char*)kissat_malloc (solver, strlen (str) + 1);
72 return strcpy (res, str);
73}
void * kissat_malloc(kissat *solver, size_t bytes)
Definition allocate.c:49
char * strcpy()
Here is the call graph for this function:
Here is the caller graph for this function: