My Project
Loading...
Searching...
No Matches
omalloc.c
Go to the documentation of this file.
1/*******************************************************************
2 * File: omalloc.c
3 * Purpose: implementation of ANSI-C conforming malloc functions
4 * -- the real version
5 * Author: obachman@mathematik.uni-kl.de (Olaf Bachmann)
6 * Created: 11/99
7 *******************************************************************/
8
9#include <stdlib.h>
10#include <stdio.h>
11
12#ifndef OMALLOC_C
13#define OMALLOC_C
14
15#include "omalloc.h"
16
17#ifdef OM_MALLOC_MARK_AS_STATIC
18#define OM_MARK_AS_STATIC(addr) omMarkAsStaticAddr(addr)
19#else
20#define OM_MARK_AS_STATIC(addr) do {} while (0)
21#endif
22
23#if OM_PROVIDE_MALLOC > 0
24
25void* calloc(size_t nmemb, size_t size)
26{
27 void* addr;
28 if (size == 0) size = 1;
29 if (nmemb == 0) nmemb = 1;
30
31 size = size*nmemb;
32 omTypeAlloc0Aligned(void*, addr, size);
34 return addr;
35}
36
37void free(void* addr)
38{
39 omfree(addr);
40}
41
42void* valloc(size_t size)
43{
44 fputs("omalloc Warning: valloc not yet implemented\n",stderr);
45 fflush(NULL);
46 return NULL;
47}
48
49void* realloc(void* old_addr, size_t new_size)
50{
51 if (old_addr && new_size)
52 {
53 void* new_addr;
54 omTypeReallocAligned(old_addr, void*, new_addr, new_size);
55 OM_MARK_AS_STATIC(new_addr);
56 return new_addr;
57 }
58 else
59 {
60 free(old_addr);
61 return malloc(new_size);
62 }
63}
64
65/* on some systems strdup is a macro -- replace it unless OMALLOC_FUNC
66 is defined */
67#ifndef OMALLOC_USES_MALLOC
68#if !defined(OMALLOC_FUNC)
69#undef strdup
70#endif
71char* strdup_(const char* addr)
72{
73 char* n_s;
74 if (addr)
75 {
76 n_s = omStrDup(addr);
78 return n_s;
79 }
80 return NULL;
81}
82#endif
83#endif
84
85void* malloc(size_t size)
86{
87 void* addr;
88 if (size == 0) size = 1;
89
90 omTypeAllocAligned(void*, addr, size);
92 return addr;
93}
94
95void freeSize(void* addr, size_t size)
96{
97 if (addr) omFreeSize(addr, size);
98}
99
100void* reallocSize(void* old_addr, size_t old_size, size_t new_size)
101{
102 if (old_addr && new_size)
103 {
104 void* new_addr;
105 omTypeReallocAlignedSize(old_addr, old_size, void*, new_addr, new_size);
106 OM_MARK_AS_STATIC(new_addr);
107 return new_addr;
108 }
109 else
110 {
111 freeSize(old_addr, old_size);
112 return malloc(new_size);
113 }
114}
115#endif
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define strdup_
Definition: mmstd.c:29
#define omStrDup(s)
Definition: omAllocDecl.h:263
#define omfree(addr)
Definition: omAllocDecl.h:237
#define omTypeReallocAlignedSize
Definition: omAllocDecl.h:276
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omTypeAlloc0Aligned
Definition: omAllocDecl.h:272
#define omTypeReallocAligned
Definition: omAllocDecl.h:281
#define omTypeAllocAligned
Definition: omAllocDecl.h:271
#define realloc
Definition: omAllocFunc.c:16
#define freeSize
Definition: omAllocFunc.c:15
#define valloc
Definition: omAllocFunc.c:19
#define free
Definition: omAllocFunc.c:14
#define calloc
Definition: omAllocFunc.c:13
#define malloc
Definition: omAllocFunc.c:12
#define reallocSize
Definition: omAllocFunc.c:17
#define NULL
Definition: omList.c:12
#define OM_MARK_AS_STATIC(addr)
Definition: omalloc.c:20