[Gc] Round 3 or 4 of C++ throw/nothrow patch.

Talbot, George Gtalbot at ansarisbio.com
Thu Dec 17 08:06:50 PST 2009


Hi all,

I think I've addressed the issues with this patch that you guys have told me about in the past.  This patch, when applied, does the following:

1)  Adds both throwing and non-throwing versions of operator ::new to gc_cpp.h, with some code implementing these in gc_cpp.cc.  The throwing versions of these throw std::bad_alloc when the collector can't satisfy a memory allocation request, as per the C++ standard.  The non-throwing versions return 0 when the collector can't satisfy a memory allocation request, also as per the standard.

2)  Adds a new function, gc_cpp_init(), which initializes the collector via GC_INIT() and installs an out-of-memory function that throws std::bad_alloc.

3)  Adds a new configuration option --enable-new-collectable, which when given to configure defines GC_NEW_COLLECTABLE in include/private/config.h.  This symbol, when defined, causes the implementations of the default operator ::new to use GC_MALLOC instead of GC_MALLOC_UNCOLLECTABLE.  This option is very useful in programs that use the Standard C++ Library (assuming the allocator passes through memory requests to operator ::new as the GNU Libstdc++ does) so that memory allocated via the Standard C++ Library becomes collectable without having to supply a custom allocator.

Programs and installations that don't call gc_cpp_init() and don't use the --enable-new-collectable configure option will be fully source compatible, and the behavior of the collector will be unchanged.

I believe (hope) that I've addressed the concerns that folks previously had with this patch.  Let me know if it looks OK to you.  If it does, can it be applied?

Thanks.

--
George T. Talbot
<gtalbot at locuspharma.com>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: cpp-throw.patch
Type: application/octet-stream
Size: 14542 bytes
Desc: cpp-throw.patch
Url : http://napali.hpl.hp.com/pipermail/gc/attachments/20091217/b1edb0fb/cpp-throw-0001.obj


More information about the Gc mailing list