File: gc_cpp.cc

package info (click to toggle)
libgc 1:7.6.4-0.4
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,956 kB
  • sloc: ansic: 35,613; sh: 4,193; cpp: 1,247; makefile: 163; asm: 99
file content (80 lines) | stat: -rw-r--r-- 2,358 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 1994 by Xerox Corporation.  All rights reserved.
 *
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
 *
 * Permission is hereby granted to copy this code for any purpose,
 * provided the above notices are retained on all copies.
 */

/*************************************************************************
This implementation module for gc_c++.h provides an implementation of
the global operators "new" and "delete" that calls the Boehm
allocator.  All objects allocated by this implementation will be
uncollectible but part of the root set of the collector.

You should ensure (using implementation-dependent techniques) that the
linker finds this module before the library that defines the default
built-in "new" and "delete".
**************************************************************************/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#ifndef GC_BUILD
# define GC_BUILD
#endif

#include "gc_cpp.h"

#if !defined(GC_NEW_DELETE_NEED_THROW) && defined(__GNUC__) \
    && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
# define GC_NEW_DELETE_NEED_THROW
#endif

#ifdef GC_NEW_DELETE_NEED_THROW
# include <new> /* for std::bad_alloc */
# define GC_DECL_NEW_THROW throw(std::bad_alloc)
# define GC_DECL_DELETE_THROW throw()
#else
# define GC_DECL_NEW_THROW /* empty */
# define GC_DECL_DELETE_THROW /* empty */
#endif // !GC_NEW_DELETE_NEED_THROW

#ifndef _MSC_VER

  void* operator new(size_t size) GC_DECL_NEW_THROW {
    return GC_MALLOC_UNCOLLECTABLE(size);
  }

  void operator delete(void* obj) GC_DECL_DELETE_THROW {
    GC_FREE(obj);
  }

# if defined(GC_OPERATOR_NEW_ARRAY) && !defined(CPPCHECK)
    void* operator new[](size_t size) GC_DECL_NEW_THROW {
      return GC_MALLOC_UNCOLLECTABLE(size);
    }

    void operator delete[](void* obj) GC_DECL_DELETE_THROW {
      GC_FREE(obj);
    }
# endif // GC_OPERATOR_NEW_ARRAY

# if __cplusplus > 201103L // C++14
    void operator delete(void* obj, size_t size) GC_DECL_DELETE_THROW {
      (void)size; // size is ignored
      GC_FREE(obj);
    }

#   if defined(GC_OPERATOR_NEW_ARRAY) && !defined(CPPCHECK)
      void operator delete[](void* obj, size_t size) GC_DECL_DELETE_THROW {
        (void)size;
        GC_FREE(obj);
      }
#   endif
# endif // C++14

#endif // !_MSC_VER