source: git/omalloc/omalloc.c @ 85bcd6

spielwiese
Last change on this file since 85bcd6 was 6ce030f, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
removal of the $Id$ svn tag from everywhere NOTE: the git SHA1 may be used instead (only on special places) NOTE: the libraries Singular/LIB/*.lib still contain the marker due to our current use of svn
  • Property mode set to 100644
File size: 2.5 KB
Line 
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/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) ((void)0)
21#endif
22
23void* calloc(size_t nmemb, size_t size)
24{
25  void* addr;
26  if (size == 0) size = 1;
27  if (nmemb == 0) nmemb = 1;
28
29  size = size*nmemb;
30  omTypeAlloc0Aligned(void*, addr, size);
31  OM_MARK_AS_STATIC(addr);
32  return addr;
33}
34
35void* malloc(size_t size)
36{
37  void* addr;
38  if (size == 0) size = 1;
39
40  omTypeAllocAligned(void*, addr, size);
41  OM_MARK_AS_STATIC(addr);
42  return addr;
43}
44
45void free(void* addr)
46{
47  omfree(addr);
48}
49
50void* valloc(size_t size)
51{
52  fprintf(stderr, "omalloc Warning: valloc not yet implemented\n");
53  fflush(NULL);
54  return NULL;
55}
56
57#if defined(sgi)
58void* memalign(size_t size_1, size_t size_2)
59#elif (defined(__sun) && (defined(__sparc) || defined(__i386) || defined(__x86_64)) || defined(__CYGWIN__))
60void* memalign(size_t size_1, size_t size_2)
61#else
62void* memalign(void* alignment, size_t size)
63#endif
64{
65  fprintf(stderr, "omalloc Warning: memalign not yet implemented\n");
66  fflush(NULL);
67  return NULL;
68}
69
70void* realloc(void* old_addr, size_t new_size)
71{
72  if (old_addr && new_size)
73  {
74    void* new_addr;
75    omTypeReallocAligned(old_addr, void*, new_addr, new_size);
76    OM_MARK_AS_STATIC(new_addr);
77    return new_addr;
78  }
79  else
80  {
81    free(old_addr);
82    return malloc(new_size);
83  }
84}
85
86/* on some systems strdup is a macro -- replace it unless OMALLOC_FUNC
87   is defined */
88#ifndef OMALLOC_USES_MALLOC
89#if !defined(OMALLOC_FUNC)
90#undef strdup
91#endif
92char* strdup_(const char* addr)
93{
94  char* n_s;
95  if (addr)
96  {
97    n_s = omStrDup(addr);
98    OM_MARK_AS_STATIC(n_s);
99    return n_s;
100  }
101  return NULL;
102}
103#endif
104void freeSize(void* addr, size_t size)
105{
106  if (addr) omFreeSize(addr, size);
107}
108
109void* reallocSize(void* old_addr, size_t old_size, size_t new_size)
110{
111  if (old_addr && new_size)
112  {
113   void* new_addr;
114    omTypeReallocAlignedSize(old_addr, old_size, void*, new_addr, new_size);
115    OM_MARK_AS_STATIC(new_addr);
116    return new_addr;
117  }
118  else
119  {
120    freeSize(old_addr, old_size);
121    return malloc(new_size);
122  }
123}
124#endif
Note: See TracBrowser for help on using the repository browser.