-
Notifications
You must be signed in to change notification settings - Fork 570
Expand file tree
/
Copy pathunixutil.cpp
More file actions
81 lines (70 loc) · 1.88 KB
/
unixutil.cpp
File metadata and controls
81 lines (70 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//-----------------------------------------------------------------------------
// Utility functions that run on Unix. Notably, our memory allocation;
// we use two separate allocators, one for long-lived stuff and one for
// stuff that gets freed after every regeneration of the model, to save us
// the trouble of freeing the latter explicitly.
//
// Copyright 2016 [email protected].
//-----------------------------------------------------------------------------
#include "../solvespace.h"
void dbp(const char *str, ...)
{
va_list f;
static char buf[1024*50];
va_start(f, str);
vsnprintf(buf, sizeof(buf), str, f);
va_end(f);
fputs(buf, stderr);
fputc('\n', stderr);
}
void GetAbsoluteFilename(char *file)
{
}
//-----------------------------------------------------------------------------
// A separate heap, on which we allocate expressions. Maybe a bit faster,
// since no fragmentation issues whatsoever, and it also makes it possible
// to be sloppy with our memory management, and just free everything at once
// at the end.
//-----------------------------------------------------------------------------
struct HeapList {
HeapList *next;
};
static HeapList *TempHeap;
void *AllocTemporary(int n)
{
HeapList *l = (HeapList*)malloc(n + sizeof(HeapList));
if(!l) oops();
l->next = TempHeap;
TempHeap = l;
return (void*)((intptr_t)l + sizeof(HeapList));
}
void FreeTemporary(void *p) {
}
void FreeAllTemporary(void)
{
while(TempHeap) {
HeapList *next = TempHeap->next;
free(TempHeap);
TempHeap = next;
}
}
void *MemRealloc(void *p, int n) {
if(!p) {
return MemAlloc(n);
}
p = realloc(p, n);
if(!p) oops();
return p;
}
void *MemAlloc(int n) {
void *p = malloc(n);
if(!p) oops();
return p;
}
void MemFree(void *p) {
free(p);
}
void vl(void) {
}
void InitHeaps(void) {
}