My Project  UNKNOWN_GIT_VERSION
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 
25 void* 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);
33  OM_MARK_AS_STATIC(addr);
34  return addr;
35 }
36 
37 void free(void* addr)
38 {
39  omfree(addr);
40 }
41 
42 void* valloc(size_t size)
43 {
44  fputs("omalloc Warning: valloc not yet implemented\n",stderr);
45  fflush(NULL);
46  return NULL;
47 }
48 
49 void* memalign(size_t size_1, size_t size_2)
50 {
51  fputs("omalloc Warning: memalign not yet implemented\n",stderr);
52  fflush(NULL);
53  return NULL;
54 }
55 
56 void* realloc(void* old_addr, size_t new_size)
57 {
58  if (old_addr && new_size)
59  {
60  void* new_addr;
61  omTypeReallocAligned(old_addr, void*, new_addr, new_size);
62  OM_MARK_AS_STATIC(new_addr);
63  return new_addr;
64  }
65  else
66  {
67  free(old_addr);
68  return malloc(new_size);
69  }
70 }
71 
72 /* on some systems strdup is a macro -- replace it unless OMALLOC_FUNC
73  is defined */
74 #ifndef OMALLOC_USES_MALLOC
75 #if !defined(OMALLOC_FUNC)
76 #undef strdup
77 #endif
78 char* strdup_(const char* addr)
79 {
80  char* n_s;
81  if (addr)
82  {
83  n_s = omStrDup(addr);
84  OM_MARK_AS_STATIC(n_s);
85  return n_s;
86  }
87  return NULL;
88 }
89 #endif
90 #endif
91 
92 void* malloc(size_t size)
93 {
94  void* addr;
95  if (size == 0) size = 1;
96 
97  omTypeAllocAligned(void*, addr, size);
98  OM_MARK_AS_STATIC(addr);
99  return addr;
100 }
101 
102 void freeSize(void* addr, size_t size)
103 {
104  if (addr) omFreeSize(addr, size);
105 }
106 
107 void* reallocSize(void* old_addr, size_t old_size, size_t new_size)
108 {
109  if (old_addr && new_size)
110  {
111  void* new_addr;
112  omTypeReallocAlignedSize(old_addr, old_size, void*, new_addr, new_size);
113  OM_MARK_AS_STATIC(new_addr);
114  return new_addr;
115  }
116  else
117  {
118  freeSize(old_addr, old_size);
119  return malloc(new_size);
120  }
121 }
122 #endif
void * reallocSize(void *old_addr, size_t old_size, size_t new_size)
Definition: omalloc.c:107
#define omTypeReallocAligned
Definition: omAllocDecl.h:281
#define calloc
Definition: omAllocFunc.c:11
#define valloc
Definition: omAllocFunc.c:18
#define omTypeReallocAlignedSize
Definition: omAllocDecl.h:276
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define realloc
Definition: omAllocFunc.c:14
#define omTypeAlloc0Aligned
Definition: omAllocDecl.h:272
void * malloc(size_t size)
Definition: omalloc.c:92
#define omfree(addr)
Definition: omAllocDecl.h:237
#define free
Definition: omAllocFunc.c:12
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define memalign
Definition: omAllocFunc.c:16
#define strdup_
Definition: mmstd.c:30
#define NULL
Definition: omList.c:10
void freeSize(void *addr, size_t size)
Definition: omalloc.c:102
#define OM_MARK_AS_STATIC(addr)
Definition: omalloc.c:20
#define omTypeAllocAligned
Definition: omAllocDecl.h:271
#define omStrDup(s)
Definition: omAllocDecl.h:263