• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ivmai / bdwgc / 1486

20 Apr 2023 10:28AM UTC coverage: 76.615% (+0.1%) from 76.519%
1486

push

travis-ci-com

ivmai
Provide global non-throwing operator new/delete in gccpp library

Note: this might require define GC_INCLUDE_NEW by client before
include gc_cpp.h on Windows hosts (to have nothrow_t declared before
the global inline operator new and delete are defined).

* gc_cpp.cc [(!_MSC_VER && !__DMC__ || GC_NO_INLINE_STD_NEW)
&& !GC_INLINE_STD_NEW && GC_OPERATOR_NEW_NOTHROW] (operator new,
operator delete): Define with nothrow_t argument.
* gc_cpp.cc [(!_MSC_VER && !__DMC__ || GC_NO_INLINE_STD_NEW)
&& !GC_INLINE_STD_NEW && GC_OPERATOR_NEW_ARRAY && !CPPCHECK
&& GC_OPERATOR_NEW_NOTHROW] (operator new[], operator delete[]):
Likewise.
* include/gc/gc_cpp.h [GC_INLINE_STD_NEW && GC_OPERATOR_NEW_ARRAY
&& GC_OPERATOR_NEW_NOTHROW] (operator new[], operator delete[]):
Likewise.
* include/gc/gc_cpp.h [GC_INLINE_STD_NEW && GC_OPERATOR_NEW_NOTHROW]
(operator new, operator delete): Likewise.
* include/gc/gc_cpp.h [!GC_OPERATOR_NEW_NOTHROW
&& !GC_NO_OPERATOR_NEW_NOTHROW && (GC_INCLUDE_NEW
&& (__cplusplus>=201103L || _MSVC_LANG>=201103L)
|| __NOTHROW_T_DEFINED)] (GC_OPERATOR_NEW_NOTHROW): Define macro;
add comment.
* include/gc/gc_cpp.h [!GC_INLINE_STD_NEW && GC_NO_INLINE_STD_NEW
&& _MSC_VER && GC_OPERATOR_NEW_ARRAY && GC_OPERATOR_NEW_NOTHROW]
(operator new[], operator delete[]): Add prototype with nothrow_t
argument (with commented out GC_ATTR_MALLOC).
* include/gc/gc_cpp.h [!GC_INLINE_STD_NEW && GC_NO_INLINE_STD_NEW
&& _MSC_VER && GC_OPERATOR_NEW_NOTHROW] (operator new,
operator delete): Likewise.

7781 of 10156 relevant lines covered (76.61%)

8930874.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

62.5
/gc_cpp.cc
1
/*
2
 * Copyright (c) 1994 by Xerox Corporation.  All rights reserved.
3
 *
4
 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
5
 * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
6
 *
7
 * Permission is hereby granted to use or copy this program
8
 * for any purpose, provided the above notices are retained on all copies.
9
 * Permission to modify the code and to distribute modified code is granted,
10
 * provided the above notices are retained, and a notice that the code was
11
 * modified is included with the above copyright notice.
12
 */
13

14
/*************************************************************************
15
This implementation module for gc_cpp.h provides an implementation of
16
the global operators "new" and "delete" that calls the Boehm
17
allocator.  All objects allocated by this implementation will be
18
uncollectible but part of the root set of the collector.
19

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

25
#ifdef HAVE_CONFIG_H
26
# include "config.h"
27
#endif
28

29
#ifndef GC_BUILD
30
# define GC_BUILD
31
#endif
32

33
#define GC_DONT_INCL_WINDOWS_H
34
#include "gc/gc.h"
35

36
#ifndef GC_INCLUDE_NEW
37
# define GC_INCLUDE_NEW
38
#endif
39
#include "gc/gc_cpp.h"
40

41
#if (!defined(_MSC_VER) && !defined(__DMC__) \
42
     || defined(GC_NO_INLINE_STD_NEW)) && !defined(GC_INLINE_STD_NEW)
43

44
# if defined(GC_NEW_ABORTS_ON_OOM) || defined(_LIBCPP_NO_EXCEPTIONS)
45
#   define GC_ALLOCATOR_THROW_OR_ABORT() GC_abort_on_oom()
46
# else
47
    // Use bad_alloc() directly instead of GC_throw_bad_alloc() call.
48
#   define GC_ALLOCATOR_THROW_OR_ABORT() throw std::bad_alloc()
49
# endif
50

51
  void* operator new(GC_SIZE_T size) GC_DECL_NEW_THROW
×
52
  {
53
    void* obj = GC_MALLOC_UNCOLLECTABLE(size);
×
54
    if (0 == obj)
×
55
      GC_ALLOCATOR_THROW_OR_ABORT();
×
56
    return obj;
×
57
  }
58

59
# ifdef _MSC_VER
60
    // This new operator is used by VC++ in case of Debug builds.
61
    void* operator new(GC_SIZE_T size, int /* nBlockUse */,
62
                       const char* szFileName, int nLine)
63
    {
64
#     ifdef GC_DEBUG
65
        void* obj = GC_debug_malloc_uncollectable(size, szFileName, nLine);
66
#     else
67
        void* obj = GC_MALLOC_UNCOLLECTABLE(size);
68
        (void)szFileName; (void)nLine;
69
#     endif
70
      if (0 == obj)
71
        GC_ALLOCATOR_THROW_OR_ABORT();
72
      return obj;
73
    }
74
# endif // _MSC_VER
75

76
  void operator delete(void* obj) GC_NOEXCEPT
14,000✔
77
  {
78
    GC_FREE(obj);
14,000✔
79
  }
14,000✔
80

81
# ifdef GC_OPERATOR_NEW_NOTHROW
82
    void* operator new(GC_SIZE_T size, const std::nothrow_t&) GC_NOEXCEPT
83
    {
84
      return GC_MALLOC_UNCOLLECTABLE(size);
85
    }
86

87
    void operator delete(void* obj, const std::nothrow_t&) GC_NOEXCEPT
88
    {
89
      GC_FREE(obj);
90
    }
91
# endif // GC_OPERATOR_NEW_NOTHROW
92

93
# if defined(GC_OPERATOR_NEW_ARRAY) && !defined(CPPCHECK)
94
    void* operator new[](GC_SIZE_T size) GC_DECL_NEW_THROW
14,000✔
95
    {
96
      void* obj = GC_MALLOC_UNCOLLECTABLE(size);
14,000✔
97
      if (0 == obj)
14,000✔
98
        GC_ALLOCATOR_THROW_OR_ABORT();
×
99
      return obj;
14,000✔
100
    }
101

102
#   ifdef _MSC_VER
103
      // This new operator is used by VC++ 7+ in Debug builds.
104
      void* operator new[](GC_SIZE_T size, int nBlockUse,
105
                           const char* szFileName, int nLine)
106
      {
107
        return operator new(size, nBlockUse, szFileName, nLine);
108
      }
109
#   endif // _MSC_VER
110

111
    void operator delete[](void* obj) GC_NOEXCEPT
14,000✔
112
    {
113
      GC_FREE(obj);
14,000✔
114
    }
14,000✔
115

116
#   ifdef GC_OPERATOR_NEW_NOTHROW
117
      void* operator new[](GC_SIZE_T size, const std::nothrow_t&) GC_NOEXCEPT
118
      {
119
        return GC_MALLOC_UNCOLLECTABLE(size);
120
      }
121

122
      void operator delete[](void* obj, const std::nothrow_t&) GC_NOEXCEPT
123
      {
124
        GC_FREE(obj);
125
      }
126
#   endif // GC_OPERATOR_NEW_NOTHROW
127
# endif // GC_OPERATOR_NEW_ARRAY
128

129
# ifdef GC_OPERATOR_SIZED_DELETE
130
    void operator delete(void* obj, GC_SIZE_T) GC_NOEXCEPT
131
    {
132
      GC_FREE(obj);
133
    }
134

135
#   if defined(GC_OPERATOR_NEW_ARRAY) && !defined(CPPCHECK)
136
      void operator delete[](void* obj, GC_SIZE_T) GC_NOEXCEPT
137
      {
138
        GC_FREE(obj);
139
      }
140
#   endif
141
# endif // GC_OPERATOR_SIZED_DELETE
142

143
#endif // !_MSC_VER && !__DMC__ || GC_NO_INLINE_STD_NEW
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc