From 5865f0044d4d75a2d988a8bf2ea3bc65ed6f4c18 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Wed, 25 Feb 2015 17:24:47 -0500 Subject: Isolate components of libgc (bzr r13946) --- src/CMakeLists.txt | 1 + src/Makefile.am | 2 + src/Makefile_insert | 9 +- src/composite-undo-stack-observer.h | 2 +- src/debug/demangle.cpp | 2 +- src/debug/gc-heap.h | 2 +- src/debug/heap.cpp | 2 +- src/debug/logger.cpp | 2 +- src/debug/simple-event.h | 2 +- src/display/nr-filter.h | 2 +- src/document-subset.h | 2 +- src/document.h | 2 +- src/gc-alloc.h | 90 ---------- src/gc-allocator.h | 0 src/gc-anchored.h | 2 +- src/gc-core.h | 213 ------------------------ src/gc-finalized.h | 2 +- src/gc-managed.h | 63 ------- src/gc-soft-ptr.h | 70 -------- src/gc.cpp | 312 ----------------------------------- src/inkview.cpp | 2 +- src/layer-manager.cpp | 2 +- src/layer-manager.h | 2 +- src/libgc/CMakeLists.txt | 15 ++ src/libgc/Makefile_insert | 13 ++ src/libgc/gc-alloc.h | 90 ++++++++++ src/libgc/gc-core.h | 213 ++++++++++++++++++++++++ src/libgc/gc-managed.h | 63 +++++++ src/libgc/gc-soft-ptr.h | 70 ++++++++ src/libgc/gc.cpp | 312 +++++++++++++++++++++++++++++++++++ src/main.cpp | 2 +- src/message-stack.h | 2 +- src/selection.h | 4 +- src/ui/clipboard.cpp | 2 +- src/ui/dialog/filedialog.cpp | 2 +- src/ui/dialog/filedialogimpl-win32.h | 2 +- src/ui/dialog/memory.cpp | 2 +- src/ui/dialog/ocaldialogs.cpp | 2 +- src/ui/view/view.h | 2 +- src/undo-stack-observer.h | 2 +- src/util/list.h | 2 +- src/util/share.h | 2 +- src/xml/attribute-record.h | 2 +- src/xml/composite-node-observer.h | 2 +- src/xml/event.h | 2 +- src/xml/log-builder.h | 2 +- src/xml/subtree.h | 2 +- 47 files changed, 813 insertions(+), 787 deletions(-) delete mode 100644 src/gc-alloc.h delete mode 100644 src/gc-allocator.h delete mode 100644 src/gc-core.h delete mode 100644 src/gc-managed.h delete mode 100644 src/gc-soft-ptr.h delete mode 100644 src/gc.cpp create mode 100644 src/libgc/CMakeLists.txt create mode 100644 src/libgc/Makefile_insert create mode 100644 src/libgc/gc-alloc.h create mode 100644 src/libgc/gc-core.h create mode 100644 src/libgc/gc-managed.h create mode 100644 src/libgc/gc-soft-ptr.h create mode 100644 src/libgc/gc.cpp (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 67b2d4918..208f31716 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -491,6 +491,7 @@ add_subdirectory(2geom) add_subdirectory(libavoid) add_subdirectory(libcola) add_subdirectory(libcroco) +add_subdirectory(libgc) add_subdirectory(libgdl) add_subdirectory(libuemf) add_subdirectory(libvpsc) diff --git a/src/Makefile.am b/src/Makefile.am index 1945c6f12..db70b3956 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,6 +29,7 @@ noinst_LIBRARIES = \ $(internal_GDL) \ libuemf/libuemf.a \ libcola/libcola.a \ + libgc/libgc.a \ libvpsc/libvpsc.a \ livarot/libvarot.a \ 2geom/lib2geom.a \ @@ -115,6 +116,7 @@ include filters/Makefile_insert include helper/Makefile_insert include io/Makefile_insert include libcroco/Makefile_insert +include libgc/Makefile_insert include libgdl/Makefile_insert include libnrtype/Makefile_insert include libavoid/Makefile_insert diff --git a/src/Makefile_insert b/src/Makefile_insert index 477180895..2bd457529 100644 --- a/src/Makefile_insert +++ b/src/Makefile_insert @@ -43,13 +43,8 @@ ink_common_sources += \ fill-or-stroke.h \ filter-chemistry.cpp filter-chemistry.h \ filter-enums.cpp filter-enums.h \ - gc-alloc.h \ - gc-anchored.h gc-anchored.cpp \ - gc-core.h \ - gc.cpp \ - gc-finalized.h gc-finalized.cpp \ - gc-managed.h \ - gc-soft-ptr.h \ + gc-anchored.cpp gc-anchored.h \ + gc-finalized.cpp gc-finalized.h \ gradient-chemistry.cpp gradient-chemistry.h \ gradient-drag.cpp gradient-drag.h \ graphlayout.cpp graphlayout.h \ diff --git a/src/composite-undo-stack-observer.h b/src/composite-undo-stack-observer.h index c93a2338b..00b1ab728 100644 --- a/src/composite-undo-stack-observer.h +++ b/src/composite-undo-stack-observer.h @@ -10,7 +10,7 @@ #ifndef SEEN_COMPOSITE_UNDO_COMMIT_OBSERVER_H #define SEEN_COMPOSITE_UNDO_COMMIT_OBSERVER_H -#include "gc-alloc.h" +#include "libgc/gc-alloc.h" #include "undo-stack-observer.h" #include diff --git a/src/debug/demangle.cpp b/src/debug/demangle.cpp index 2b00fb8e9..a6386ebd2 100644 --- a/src/debug/demangle.cpp +++ b/src/debug/demangle.cpp @@ -14,7 +14,7 @@ #include #include "debug/demangle.h" #include "util/format.h" -#include "gc-alloc.h" +#include "libgc/gc-alloc.h" namespace Inkscape { diff --git a/src/debug/gc-heap.h b/src/debug/gc-heap.h index 957f2067a..ec35a6d2f 100644 --- a/src/debug/gc-heap.h +++ b/src/debug/gc-heap.h @@ -12,7 +12,7 @@ #ifndef SEEN_INKSCAPE_DEBUG_GC_HEAP_H #define SEEN_INKSCAPE_DEBUG_GC_HEAP_H -#include "gc-core.h" +#include "libgc/gc-core.h" #include "debug/heap.h" namespace Inkscape { diff --git a/src/debug/heap.cpp b/src/debug/heap.cpp index 8e7a920ba..f522b737c 100644 --- a/src/debug/heap.cpp +++ b/src/debug/heap.cpp @@ -13,7 +13,7 @@ # include "config.h" #endif -#include "gc-alloc.h" +#include "libgc/gc-alloc.h" #include "debug/gc-heap.h" #include "debug/sysv-heap.h" #include diff --git a/src/debug/logger.cpp b/src/debug/logger.cpp index 485dbc365..5e977c764 100644 --- a/src/debug/logger.cpp +++ b/src/debug/logger.cpp @@ -15,7 +15,7 @@ #include "inkscape-version.h" #include "debug/logger.h" #include "debug/simple-event.h" -#include "gc-alloc.h" +#include "libgc/gc-alloc.h" namespace Inkscape { diff --git a/src/debug/simple-event.h b/src/debug/simple-event.h index 506ee1b03..7786a58d2 100644 --- a/src/debug/simple-event.h +++ b/src/debug/simple-event.h @@ -16,7 +16,7 @@ #include #include // g_assert() -#include "gc-alloc.h" +#include "libgc/gc-alloc.h" #include "debug/event.h" namespace Inkscape { diff --git a/src/display/nr-filter.h b/src/display/nr-filter.h index 9a30efabd..4c42b6f28 100644 --- a/src/display/nr-filter.h +++ b/src/display/nr-filter.h @@ -18,7 +18,7 @@ #include "display/nr-filter-types.h" #include "svg/svg-length.h" #include "sp-filter-units.h" -#include "gc-managed.h" +#include "libgc/gc-managed.h" namespace Inkscape { class DrawingContext; diff --git a/src/document-subset.h b/src/document-subset.h index 298b7872d..940124f83 100644 --- a/src/document-subset.h +++ b/src/document-subset.h @@ -14,7 +14,7 @@ #include #include -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "gc-anchored.h" class SPObject; diff --git a/src/document.h b/src/document.h index 22c341eae..42768b1be 100644 --- a/src/document.h +++ b/src/document.h @@ -21,7 +21,7 @@ #include #include "libcroco/cr-cascade.h" #include <2geom/forward.h> -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" #include diff --git a/src/gc-alloc.h b/src/gc-alloc.h deleted file mode 100644 index ba672ae2c..000000000 --- a/src/gc-alloc.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Inkscape::GC::Alloc - GC-aware STL allocator - * - * Copyright 2004 MenTaLguY - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * See the file COPYING for details. - * - */ - -#ifndef SEEN_INKSCAPE_GC_ALLOC_H -#define SEEN_INKSCAPE_GC_ALLOC_H - -#include -#include -#include "gc-core.h" - -namespace Inkscape { - -namespace GC { - -template -class Alloc { -public: - typedef T value_type; - typedef T *pointer; - typedef T const *const_pointer; - typedef T &reference; - typedef T const &const_reference; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; - - template - struct rebind { typedef Alloc other; }; - - Alloc() {} - template Alloc(Alloc const &) {} - - pointer address(reference r) { return &r; } - const_pointer address(const_reference r) { return &r; } - - size_type max_size() const { - return std::numeric_limits::max() / sizeof(T); - } - - pointer allocate(size_type count, void const * =NULL) { - return static_cast(::operator new(count * sizeof(T), SCANNED, collect)); - } - - void construct(pointer p, const_reference value) { - new (static_cast(p)) T(value); - } - void destroy(pointer p) { p->~T(); } - - void deallocate(pointer p, size_type) { ::operator delete(p, GC); } -}; - -// allocators with the same collection policy are interchangable - -template -bool operator==(Alloc const &, Alloc const &) { - return collect1 == collect2; -} - -template -bool operator!=(Alloc const &, Alloc const &) { - return collect1 != collect2; -} - -} - -} - -#endif -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/gc-allocator.h b/src/gc-allocator.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/gc-anchored.h b/src/gc-anchored.h index 99b78c784..a65c4f248 100644 --- a/src/gc-anchored.h +++ b/src/gc-anchored.h @@ -9,7 +9,7 @@ #ifndef SEEN_INKSCAPE_GC_ANCHORED_H #define SEEN_INKSCAPE_GC_ANCHORED_H -#include "gc-managed.h" +#include "libgc/gc-managed.h" namespace Inkscape { diff --git a/src/gc-core.h b/src/gc-core.h deleted file mode 100644 index d9d0bf4ff..000000000 --- a/src/gc-core.h +++ /dev/null @@ -1,213 +0,0 @@ -/** @file - * @brief Wrapper for Boehm GC - */ -/* Authors: - * MenTaLguY - * - * Copyright (C) 2004 MenTaLguY - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef SEEN_INKSCAPE_GC_CORE_H -#define SEEN_INKSCAPE_GC_CORE_H - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#ifdef HAVE_GC_GC_H -# include -#else -# include -#endif - -namespace Inkscape { -namespace GC { - -enum ScanPolicy { - SCANNED, - ATOMIC -}; - -enum CollectionPolicy { - AUTO, - MANUAL -}; - -enum Delete { - GC -}; - -typedef void (*CleanupFunc)(void *mem, void *data); - -struct Ops { - void (*do_init)(); - void *(*malloc)(std::size_t size); - void *(*malloc_atomic)(std::size_t size); - void *(*malloc_uncollectable)(std::size_t size); - void *(*malloc_atomic_uncollectable)(std::size_t size); - void *(*base)(void *ptr); - void (*register_finalizer_ignore_self)(void *base, - CleanupFunc func, void *data, - CleanupFunc *old_func, - void **old_data); - int (*general_register_disappearing_link)(void **p_ptr, - void const *base); - int (*unregister_disappearing_link)(void **p_ptr); - std::size_t (*get_heap_size)(); - std::size_t (*get_free_bytes)(); - void (*gcollect)(); - void (*enable)(); - void (*disable)(); - void (*free)(void *ptr); -}; - -struct Core { -public: - static void init(); - static inline void *malloc(std::size_t size) { - return _ops.malloc(size); - } - static inline void *malloc_atomic(std::size_t size) { - return _ops.malloc_atomic(size); - } - static inline void *malloc_uncollectable(std::size_t size) { - return _ops.malloc_uncollectable(size); - } - static inline void *malloc_atomic_uncollectable(std::size_t size) { - return _ops.malloc_atomic_uncollectable(size); - } - static inline void *base(void *ptr) { - return _ops.base(ptr); - } - static inline void register_finalizer_ignore_self(void *base, - CleanupFunc func, - void *data, - CleanupFunc *old_func, - void **old_data) - { - return _ops.register_finalizer_ignore_self(base, func, data, - old_func, old_data); - } - static inline int general_register_disappearing_link(void **p_ptr, - void *base) - { - return _ops.general_register_disappearing_link(p_ptr, base); - } - static inline int unregister_disappearing_link(void **p_ptr) { - return _ops.unregister_disappearing_link(p_ptr); - } - static inline std::size_t get_heap_size() { - return _ops.get_heap_size(); - } - static inline std::size_t get_free_bytes() { - return _ops.get_free_bytes(); - } - static inline void gcollect() { - _ops.gcollect(); - } - static inline void enable() { - _ops.enable(); - } - static inline void disable() { - _ops.disable(); - } - static inline void free(void *ptr) { - return _ops.free(ptr); - } -private: - static Ops _ops; -}; - -inline void init() { - Core::init(); -} - -void request_early_collection(); - -} -} - -inline void *operator new(std::size_t size, - Inkscape::GC::ScanPolicy scan, - Inkscape::GC::CollectionPolicy collect, - Inkscape::GC::CleanupFunc cleanup=NULL, - void *data=NULL) -throw(std::bad_alloc) -{ - using namespace Inkscape::GC; - - void *mem; - if ( collect == AUTO ) { - if ( scan == SCANNED ) { - mem = Core::malloc(size); - } else { - mem = Core::malloc_atomic(size); - } - } else { - if ( scan == SCANNED ) { - mem = Core::malloc_uncollectable(size); - } else { - mem = Core::malloc_atomic_uncollectable(size); - } - } - if (!mem) { - throw std::bad_alloc(); - } - if (cleanup) { - Core::register_finalizer_ignore_self(mem, cleanup, data, NULL, NULL); - } - return mem; -} - -inline void *operator new(std::size_t size, - Inkscape::GC::ScanPolicy scan, - Inkscape::GC::CleanupFunc cleanup=NULL, - void *data=NULL) -throw(std::bad_alloc) -{ - return operator new(size, scan, Inkscape::GC::AUTO, cleanup, data); -} - -inline void *operator new[](std::size_t size, - Inkscape::GC::ScanPolicy scan, - Inkscape::GC::CollectionPolicy collect, - Inkscape::GC::CleanupFunc cleanup=NULL, - void *data=NULL) -throw(std::bad_alloc) -{ - return operator new(size, scan, collect, cleanup, data); -} - -inline void *operator new[](std::size_t size, - Inkscape::GC::ScanPolicy scan, - Inkscape::GC::CleanupFunc cleanup=NULL, - void *data=NULL) -throw(std::bad_alloc) -{ - return operator new[](size, scan, Inkscape::GC::AUTO, cleanup, data); -} - -inline void operator delete(void *mem, Inkscape::GC::Delete) { - Inkscape::GC::Core::free(mem); -} - -inline void operator delete[](void *mem, Inkscape::GC::Delete) { - operator delete(mem, Inkscape::GC::GC); -} - -#endif -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/gc-finalized.h b/src/gc-finalized.h index 814a2af18..2df479833 100644 --- a/src/gc-finalized.h +++ b/src/gc-finalized.h @@ -18,7 +18,7 @@ #include #include -#include "gc-core.h" +#include "libgc/gc-core.h" namespace Inkscape { diff --git a/src/gc-managed.h b/src/gc-managed.h deleted file mode 100644 index 74d224c9b..000000000 --- a/src/gc-managed.h +++ /dev/null @@ -1,63 +0,0 @@ -/** @file - * @brief Base class for GC-managed objects - */ -/* Copyright 2004 MenTaLguY - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * See the file COPYING for details. - */ - -#ifndef SEEN_INKSCAPE_GC_MANAGED_H -#define SEEN_INKSCAPE_GC_MANAGED_H - -#include "gc-core.h" - -namespace Inkscape { - -namespace GC { - -/** @brief A base class for objects for whom the normal new and delete - * operators should use the garbage-collected allocator - */ -template -class Managed { -public: - void *operator new(std::size_t size, - ScanPolicy scan=default_scan, - CollectionPolicy collect=default_collect) - throw (std::bad_alloc) - { - return ::operator new(size, scan, collect); - } - - void *operator new[](std::size_t size, - ScanPolicy scan=default_scan, - CollectionPolicy collect=default_collect) - throw (std::bad_alloc) - { - return ::operator new[](size, scan, collect); - } - - void operator delete(void *p) { return ::operator delete(p, GC); } -}; - -} - -} - -#endif -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/gc-soft-ptr.h b/src/gc-soft-ptr.h deleted file mode 100644 index 9e7304939..000000000 --- a/src/gc-soft-ptr.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2006 MenTaLguY - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * See the file COPYING for details. - * - */ - -#ifndef SEEN_INKSCAPE_GC_SOFT_PTR_H -#define SEEN_INKSCAPE_GC_SOFT_PTR_H - -#include "gc-core.h" - -namespace Inkscape { - -namespace GC { - -/** - * A class for pointers which can be automatically cleared to break - * finalization cycles. - */ -template -class soft_ptr { -public: - soft_ptr(T *pointer=NULL) : _pointer(pointer) { - _register(); - } - - operator T *() const { return static_cast(_pointer); } - T &operator*() const { return *static_cast(_pointer); } - T *operator->() const { return static_cast(_pointer); } - T &operator[](int i) const { return static_cast(_pointer)[i]; } - - soft_ptr &operator=(T *pointer) { - _pointer = pointer; - return *this; - } - - // default copy - -private: - void _register() { - void *base=Core::base(this); - if (base) { - Core::general_register_disappearing_link(&_pointer, base); - } - } - - void *_pointer; -}; - -} - -} - -#endif -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/gc.cpp b/src/gc.cpp deleted file mode 100644 index 280a8b1dc..000000000 --- a/src/gc.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/** @file - * Wrapper for Boehm GC. - */ -/* Authors: - * MenTaLguY - * - * Copyright (C) 2004 MenTaLguY - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "gc-core.h" -#include -#include -#include -#include -#include -#include -#include - -namespace Inkscape { -namespace GC { - -namespace { - -void display_warning(char *msg, GC_word arg) { - g_warning(msg, arg); -} - -void do_init() { - GC_no_dls = 1; - GC_all_interior_pointers = 1; - GC_finalize_on_demand = 0; - - GC_INIT(); - - GC_set_warn_proc(&display_warning); -} - -void *debug_malloc(std::size_t size) { - return GC_debug_malloc(size, GC_EXTRAS); -} - -void *debug_malloc_atomic(std::size_t size) { - return GC_debug_malloc_atomic(size, GC_EXTRAS); -} - -void *debug_malloc_uncollectable(std::size_t size) { - return GC_debug_malloc_uncollectable(size, GC_EXTRAS); -} - -void *debug_malloc_atomic_uncollectable(std::size_t size) { - return GC_debug_malloc_uncollectable(size, GC_EXTRAS); -} - -std::ptrdiff_t compute_debug_base_fixup() { - char *base=reinterpret_cast(GC_debug_malloc(1, GC_EXTRAS)); - char *real_base=reinterpret_cast(GC_base(base)); - GC_debug_free(base); - return base - real_base; -} - -inline std::ptrdiff_t const &debug_base_fixup() { - static std::ptrdiff_t fixup=compute_debug_base_fixup(); - return fixup; -} - -void *debug_base(void *ptr) { - char *base=reinterpret_cast(GC_base(ptr)); - return base + debug_base_fixup(); -} - -int debug_general_register_disappearing_link(void **p_ptr, void const *base) { - char const *real_base = reinterpret_cast(base) - debug_base_fixup(); -#if (GC_MAJOR_VERSION >= 7 && GC_MINOR_VERSION >= 4) - return GC_general_register_disappearing_link(p_ptr, real_base); -#else // compatibility with older Boehm GC versions - return GC_general_register_disappearing_link(p_ptr, const_cast(real_base)); -#endif -} - -void dummy_do_init() {} - -void *dummy_base(void *) { return NULL; } - -void dummy_register_finalizer(void *, CleanupFunc, void *, - CleanupFunc *old_func, void **old_data) -{ - if (old_func) { - *old_func = NULL; - } - if (old_data) { - *old_data = NULL; - } -} - -int dummy_general_register_disappearing_link(void **, void const *) { return false; } - -int dummy_unregister_disappearing_link(void **/*link*/) { return false; } - -std::size_t dummy_get_heap_size() { return 0; } - -std::size_t dummy_get_free_bytes() { return 0; } - -void dummy_gcollect() {} - -void dummy_enable() {} - -void dummy_disable() {} - -Ops enabled_ops = { - &do_init, - &GC_malloc, - &GC_malloc_atomic, - &GC_malloc_uncollectable, - &GC_malloc_atomic_uncollectable, - &GC_base, - &GC_register_finalizer_ignore_self, -#if (GC_MAJOR_VERSION >= 7 && GC_MINOR_VERSION >= 4) - &GC_general_register_disappearing_link, -#else // compatibility with older Boehm GC versions - (int (*)(void**, const void*))(&GC_general_register_disappearing_link), -#endif - &GC_unregister_disappearing_link, - &GC_get_heap_size, - &GC_get_free_bytes, - &GC_gcollect, - &GC_enable, - &GC_disable, - &GC_free -}; - -Ops debug_ops = { - &do_init, - &debug_malloc, - &debug_malloc_atomic, - &debug_malloc_uncollectable, - &debug_malloc_atomic_uncollectable, - &debug_base, - &GC_debug_register_finalizer_ignore_self, - &debug_general_register_disappearing_link, - &GC_unregister_disappearing_link, - &GC_get_heap_size, - &GC_get_free_bytes, - &GC_gcollect, - &GC_enable, - &GC_disable, - &GC_debug_free -}; - -Ops disabled_ops = { - &dummy_do_init, - &std::malloc, - &std::malloc, - &std::malloc, - &std::malloc, - &dummy_base, - &dummy_register_finalizer, - &dummy_general_register_disappearing_link, - &dummy_unregister_disappearing_link, - &dummy_get_heap_size, - &dummy_get_free_bytes, - &dummy_gcollect, - &dummy_enable, - &dummy_disable, - &std::free -}; - -class InvalidGCModeError : public std::runtime_error { -public: - InvalidGCModeError(const char *mode) - : runtime_error(std::string("Unknown GC mode \"") + mode + "\"") - {} -}; - -Ops const &get_ops() throw (InvalidGCModeError) { - char *mode_string=std::getenv("_INKSCAPE_GC"); - if (mode_string) { - if (!std::strcmp(mode_string, "enable")) { - return enabled_ops; - } else if (!std::strcmp(mode_string, "debug")) { - return debug_ops; - } else if (!std::strcmp(mode_string, "disable")) { - return disabled_ops; - } else { - throw InvalidGCModeError(mode_string); - } - } else { - return enabled_ops; - } -} - -void die_because_not_initialized() { - g_error("Attempt to use GC allocator before call to Inkscape::GC::init()"); -} - -void *stub_malloc(std::size_t) { - die_because_not_initialized(); - return NULL; -} - -void *stub_base(void *) { - die_because_not_initialized(); - return NULL; -} - -void stub_register_finalizer_ignore_self(void *, CleanupFunc, void *, - CleanupFunc *, void **) -{ - die_because_not_initialized(); -} - -int stub_general_register_disappearing_link(void **, void const *) { - die_because_not_initialized(); - return 0; -} - -int stub_unregister_disappearing_link(void **) { - die_because_not_initialized(); - return 0; -} - -std::size_t stub_get_heap_size() { - die_because_not_initialized(); - return 0; -} - -std::size_t stub_get_free_bytes() { - die_because_not_initialized(); - return 0; -} - -void stub_gcollect() { - die_because_not_initialized(); -} - -void stub_enable() { - die_because_not_initialized(); -} - -void stub_disable() { - die_because_not_initialized(); -} - -void stub_free(void *) { - die_because_not_initialized(); -} - -} - -Ops Core::_ops = { - NULL, - &stub_malloc, - &stub_malloc, - &stub_malloc, - &stub_malloc, - &stub_base, - &stub_register_finalizer_ignore_self, - &stub_general_register_disappearing_link, - &stub_unregister_disappearing_link, - &stub_get_heap_size, - &stub_get_free_bytes, - &stub_gcollect, - &stub_enable, - &stub_disable, - &stub_free -}; - -void Core::init() { - try { - _ops = get_ops(); - } catch (InvalidGCModeError &e) { - g_warning("%s; enabling normal collection", e.what()); - _ops = enabled_ops; - } - - _ops.do_init(); -} - - -namespace { - -bool collection_requested=false; -bool collection_task() { - Core::gcollect(); - Core::gcollect(); - collection_requested=false; - return false; -} - -} - -void request_early_collection() { - if (!collection_requested) { - collection_requested=true; - Glib::signal_idle().connect(sigc::ptr_fun(&collection_task)); - } -} - -} -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/inkview.cpp b/src/inkview.cpp index 0b7b4d35c..5e96b56c5 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -47,7 +47,7 @@ #include #include -#include "gc-core.h" +#include "libgc/gc-core.h" #include "preferences.h" #include diff --git a/src/layer-manager.cpp b/src/layer-manager.cpp index b1e365fe2..ca8ab3475 100644 --- a/src/layer-manager.cpp +++ b/src/layer-manager.cpp @@ -11,7 +11,7 @@ #include #include #include -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "gc-finalized.h" #include "document.h" #include "desktop.h" diff --git a/src/layer-manager.h b/src/layer-manager.h index 9eea68004..8e108635d 100644 --- a/src/layer-manager.h +++ b/src/layer-manager.h @@ -15,7 +15,7 @@ #include "document-subset.h" #include "gc-finalized.h" -#include "gc-soft-ptr.h" +#include "libgc/gc-soft-ptr.h" class SPDesktop; class SPDocument; diff --git a/src/libgc/CMakeLists.txt b/src/libgc/CMakeLists.txt new file mode 100644 index 000000000..22dd464e1 --- /dev/null +++ b/src/libgc/CMakeLists.txt @@ -0,0 +1,15 @@ + +set(libgc_SRC + gc.cpp + + # ------- + # Headers + gc-alloc.h + gc-anchored.h + gc-core.h + gc-managed.h + gc-soft-ptr.h +) + +add_inkscape_lib(gc_LIB "${libgc_SRC}") +# add_inkscape_source("${libgc_SRC}") diff --git a/src/libgc/Makefile_insert b/src/libgc/Makefile_insert new file mode 100644 index 000000000..e899a5b4a --- /dev/null +++ b/src/libgc/Makefile_insert @@ -0,0 +1,13 @@ +## Makefile.am fragment sourced by src/Makefile.am. + +libgc/all: libgc/libgc.a + +libgc/clean: + rm -f libgc/libgc.a $(libgc_libgc_a_OBJECTS) + +libgc_libgc_a_SOURCES = \ + libgc/gc.cpp \ + libgc/gc-alloc.h \ + libgc/gc-core.h \ + libgc/gc-managed.h \ + libgc/gc-soft-ptr.h diff --git a/src/libgc/gc-alloc.h b/src/libgc/gc-alloc.h new file mode 100644 index 000000000..765b28b19 --- /dev/null +++ b/src/libgc/gc-alloc.h @@ -0,0 +1,90 @@ +/* + * Inkscape::GC::Alloc - GC-aware STL allocator + * + * Copyright 2004 MenTaLguY + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * See the file COPYING for details. + * + */ + +#ifndef SEEN_INKSCAPE_GC_ALLOC_H +#define SEEN_INKSCAPE_GC_ALLOC_H + +#include +#include +#include "libgc/gc-core.h" + +namespace Inkscape { + +namespace GC { + +template +class Alloc { +public: + typedef T value_type; + typedef T *pointer; + typedef T const *const_pointer; + typedef T &reference; + typedef T const &const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + template + struct rebind { typedef Alloc other; }; + + Alloc() {} + template Alloc(Alloc const &) {} + + pointer address(reference r) { return &r; } + const_pointer address(const_reference r) { return &r; } + + size_type max_size() const { + return std::numeric_limits::max() / sizeof(T); + } + + pointer allocate(size_type count, void const * =NULL) { + return static_cast(::operator new(count * sizeof(T), SCANNED, collect)); + } + + void construct(pointer p, const_reference value) { + new (static_cast(p)) T(value); + } + void destroy(pointer p) { p->~T(); } + + void deallocate(pointer p, size_type) { ::operator delete(p, GC); } +}; + +// allocators with the same collection policy are interchangable + +template +bool operator==(Alloc const &, Alloc const &) { + return collect1 == collect2; +} + +template +bool operator!=(Alloc const &, Alloc const &) { + return collect1 != collect2; +} + +} + +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libgc/gc-core.h b/src/libgc/gc-core.h new file mode 100644 index 000000000..d9d0bf4ff --- /dev/null +++ b/src/libgc/gc-core.h @@ -0,0 +1,213 @@ +/** @file + * @brief Wrapper for Boehm GC + */ +/* Authors: + * MenTaLguY + * + * Copyright (C) 2004 MenTaLguY + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_INKSCAPE_GC_CORE_H +#define SEEN_INKSCAPE_GC_CORE_H + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include +#ifdef HAVE_GC_GC_H +# include +#else +# include +#endif + +namespace Inkscape { +namespace GC { + +enum ScanPolicy { + SCANNED, + ATOMIC +}; + +enum CollectionPolicy { + AUTO, + MANUAL +}; + +enum Delete { + GC +}; + +typedef void (*CleanupFunc)(void *mem, void *data); + +struct Ops { + void (*do_init)(); + void *(*malloc)(std::size_t size); + void *(*malloc_atomic)(std::size_t size); + void *(*malloc_uncollectable)(std::size_t size); + void *(*malloc_atomic_uncollectable)(std::size_t size); + void *(*base)(void *ptr); + void (*register_finalizer_ignore_self)(void *base, + CleanupFunc func, void *data, + CleanupFunc *old_func, + void **old_data); + int (*general_register_disappearing_link)(void **p_ptr, + void const *base); + int (*unregister_disappearing_link)(void **p_ptr); + std::size_t (*get_heap_size)(); + std::size_t (*get_free_bytes)(); + void (*gcollect)(); + void (*enable)(); + void (*disable)(); + void (*free)(void *ptr); +}; + +struct Core { +public: + static void init(); + static inline void *malloc(std::size_t size) { + return _ops.malloc(size); + } + static inline void *malloc_atomic(std::size_t size) { + return _ops.malloc_atomic(size); + } + static inline void *malloc_uncollectable(std::size_t size) { + return _ops.malloc_uncollectable(size); + } + static inline void *malloc_atomic_uncollectable(std::size_t size) { + return _ops.malloc_atomic_uncollectable(size); + } + static inline void *base(void *ptr) { + return _ops.base(ptr); + } + static inline void register_finalizer_ignore_self(void *base, + CleanupFunc func, + void *data, + CleanupFunc *old_func, + void **old_data) + { + return _ops.register_finalizer_ignore_self(base, func, data, + old_func, old_data); + } + static inline int general_register_disappearing_link(void **p_ptr, + void *base) + { + return _ops.general_register_disappearing_link(p_ptr, base); + } + static inline int unregister_disappearing_link(void **p_ptr) { + return _ops.unregister_disappearing_link(p_ptr); + } + static inline std::size_t get_heap_size() { + return _ops.get_heap_size(); + } + static inline std::size_t get_free_bytes() { + return _ops.get_free_bytes(); + } + static inline void gcollect() { + _ops.gcollect(); + } + static inline void enable() { + _ops.enable(); + } + static inline void disable() { + _ops.disable(); + } + static inline void free(void *ptr) { + return _ops.free(ptr); + } +private: + static Ops _ops; +}; + +inline void init() { + Core::init(); +} + +void request_early_collection(); + +} +} + +inline void *operator new(std::size_t size, + Inkscape::GC::ScanPolicy scan, + Inkscape::GC::CollectionPolicy collect, + Inkscape::GC::CleanupFunc cleanup=NULL, + void *data=NULL) +throw(std::bad_alloc) +{ + using namespace Inkscape::GC; + + void *mem; + if ( collect == AUTO ) { + if ( scan == SCANNED ) { + mem = Core::malloc(size); + } else { + mem = Core::malloc_atomic(size); + } + } else { + if ( scan == SCANNED ) { + mem = Core::malloc_uncollectable(size); + } else { + mem = Core::malloc_atomic_uncollectable(size); + } + } + if (!mem) { + throw std::bad_alloc(); + } + if (cleanup) { + Core::register_finalizer_ignore_self(mem, cleanup, data, NULL, NULL); + } + return mem; +} + +inline void *operator new(std::size_t size, + Inkscape::GC::ScanPolicy scan, + Inkscape::GC::CleanupFunc cleanup=NULL, + void *data=NULL) +throw(std::bad_alloc) +{ + return operator new(size, scan, Inkscape::GC::AUTO, cleanup, data); +} + +inline void *operator new[](std::size_t size, + Inkscape::GC::ScanPolicy scan, + Inkscape::GC::CollectionPolicy collect, + Inkscape::GC::CleanupFunc cleanup=NULL, + void *data=NULL) +throw(std::bad_alloc) +{ + return operator new(size, scan, collect, cleanup, data); +} + +inline void *operator new[](std::size_t size, + Inkscape::GC::ScanPolicy scan, + Inkscape::GC::CleanupFunc cleanup=NULL, + void *data=NULL) +throw(std::bad_alloc) +{ + return operator new[](size, scan, Inkscape::GC::AUTO, cleanup, data); +} + +inline void operator delete(void *mem, Inkscape::GC::Delete) { + Inkscape::GC::Core::free(mem); +} + +inline void operator delete[](void *mem, Inkscape::GC::Delete) { + operator delete(mem, Inkscape::GC::GC); +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libgc/gc-managed.h b/src/libgc/gc-managed.h new file mode 100644 index 000000000..9f6d9c2f6 --- /dev/null +++ b/src/libgc/gc-managed.h @@ -0,0 +1,63 @@ +/** @file + * @brief Base class for GC-managed objects + */ +/* Copyright 2004 MenTaLguY + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * See the file COPYING for details. + */ + +#ifndef SEEN_INKSCAPE_GC_MANAGED_H +#define SEEN_INKSCAPE_GC_MANAGED_H + +#include "libgc/gc-core.h" + +namespace Inkscape { + +namespace GC { + +/** @brief A base class for objects for whom the normal new and delete + * operators should use the garbage-collected allocator + */ +template +class Managed { +public: + void *operator new(std::size_t size, + ScanPolicy scan=default_scan, + CollectionPolicy collect=default_collect) + throw (std::bad_alloc) + { + return ::operator new(size, scan, collect); + } + + void *operator new[](std::size_t size, + ScanPolicy scan=default_scan, + CollectionPolicy collect=default_collect) + throw (std::bad_alloc) + { + return ::operator new[](size, scan, collect); + } + + void operator delete(void *p) { return ::operator delete(p, GC); } +}; + +} + +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libgc/gc-soft-ptr.h b/src/libgc/gc-soft-ptr.h new file mode 100644 index 000000000..bb26ebb04 --- /dev/null +++ b/src/libgc/gc-soft-ptr.h @@ -0,0 +1,70 @@ +/* + * Copyright 2006 MenTaLguY + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * See the file COPYING for details. + * + */ + +#ifndef SEEN_INKSCAPE_GC_SOFT_PTR_H +#define SEEN_INKSCAPE_GC_SOFT_PTR_H + +#include "libgc/gc-core.h" + +namespace Inkscape { + +namespace GC { + +/** + * A class for pointers which can be automatically cleared to break + * finalization cycles. + */ +template +class soft_ptr { +public: + soft_ptr(T *pointer=NULL) : _pointer(pointer) { + _register(); + } + + operator T *() const { return static_cast(_pointer); } + T &operator*() const { return *static_cast(_pointer); } + T *operator->() const { return static_cast(_pointer); } + T &operator[](int i) const { return static_cast(_pointer)[i]; } + + soft_ptr &operator=(T *pointer) { + _pointer = pointer; + return *this; + } + + // default copy + +private: + void _register() { + void *base=Core::base(this); + if (base) { + Core::general_register_disappearing_link(&_pointer, base); + } + } + + void *_pointer; +}; + +} + +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/libgc/gc.cpp b/src/libgc/gc.cpp new file mode 100644 index 000000000..044fc6065 --- /dev/null +++ b/src/libgc/gc.cpp @@ -0,0 +1,312 @@ +/** @file + * Wrapper for Boehm GC. + */ +/* Authors: + * MenTaLguY + * + * Copyright (C) 2004 MenTaLguY + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "libgc/gc-core.h" +#include +#include +#include +#include +#include +#include +#include + +namespace Inkscape { +namespace GC { + +namespace { + +void display_warning(char *msg, GC_word arg) { + g_warning(msg, arg); +} + +void do_init() { + GC_no_dls = 1; + GC_all_interior_pointers = 1; + GC_finalize_on_demand = 0; + + GC_INIT(); + + GC_set_warn_proc(&display_warning); +} + +void *debug_malloc(std::size_t size) { + return GC_debug_malloc(size, GC_EXTRAS); +} + +void *debug_malloc_atomic(std::size_t size) { + return GC_debug_malloc_atomic(size, GC_EXTRAS); +} + +void *debug_malloc_uncollectable(std::size_t size) { + return GC_debug_malloc_uncollectable(size, GC_EXTRAS); +} + +void *debug_malloc_atomic_uncollectable(std::size_t size) { + return GC_debug_malloc_uncollectable(size, GC_EXTRAS); +} + +std::ptrdiff_t compute_debug_base_fixup() { + char *base=reinterpret_cast(GC_debug_malloc(1, GC_EXTRAS)); + char *real_base=reinterpret_cast(GC_base(base)); + GC_debug_free(base); + return base - real_base; +} + +inline std::ptrdiff_t const &debug_base_fixup() { + static std::ptrdiff_t fixup=compute_debug_base_fixup(); + return fixup; +} + +void *debug_base(void *ptr) { + char *base=reinterpret_cast(GC_base(ptr)); + return base + debug_base_fixup(); +} + +int debug_general_register_disappearing_link(void **p_ptr, void const *base) { + char const *real_base = reinterpret_cast(base) - debug_base_fixup(); +#if (GC_MAJOR_VERSION >= 7 && GC_MINOR_VERSION >= 4) + return GC_general_register_disappearing_link(p_ptr, real_base); +#else // compatibility with older Boehm GC versions + return GC_general_register_disappearing_link(p_ptr, const_cast(real_base)); +#endif +} + +void dummy_do_init() {} + +void *dummy_base(void *) { return NULL; } + +void dummy_register_finalizer(void *, CleanupFunc, void *, + CleanupFunc *old_func, void **old_data) +{ + if (old_func) { + *old_func = NULL; + } + if (old_data) { + *old_data = NULL; + } +} + +int dummy_general_register_disappearing_link(void **, void const *) { return false; } + +int dummy_unregister_disappearing_link(void **/*link*/) { return false; } + +std::size_t dummy_get_heap_size() { return 0; } + +std::size_t dummy_get_free_bytes() { return 0; } + +void dummy_gcollect() {} + +void dummy_enable() {} + +void dummy_disable() {} + +Ops enabled_ops = { + &do_init, + &GC_malloc, + &GC_malloc_atomic, + &GC_malloc_uncollectable, + &GC_malloc_atomic_uncollectable, + &GC_base, + &GC_register_finalizer_ignore_self, +#if (GC_MAJOR_VERSION >= 7 && GC_MINOR_VERSION >= 4) + &GC_general_register_disappearing_link, +#else // compatibility with older Boehm GC versions + (int (*)(void**, const void*))(&GC_general_register_disappearing_link), +#endif + &GC_unregister_disappearing_link, + &GC_get_heap_size, + &GC_get_free_bytes, + &GC_gcollect, + &GC_enable, + &GC_disable, + &GC_free +}; + +Ops debug_ops = { + &do_init, + &debug_malloc, + &debug_malloc_atomic, + &debug_malloc_uncollectable, + &debug_malloc_atomic_uncollectable, + &debug_base, + &GC_debug_register_finalizer_ignore_self, + &debug_general_register_disappearing_link, + &GC_unregister_disappearing_link, + &GC_get_heap_size, + &GC_get_free_bytes, + &GC_gcollect, + &GC_enable, + &GC_disable, + &GC_debug_free +}; + +Ops disabled_ops = { + &dummy_do_init, + &std::malloc, + &std::malloc, + &std::malloc, + &std::malloc, + &dummy_base, + &dummy_register_finalizer, + &dummy_general_register_disappearing_link, + &dummy_unregister_disappearing_link, + &dummy_get_heap_size, + &dummy_get_free_bytes, + &dummy_gcollect, + &dummy_enable, + &dummy_disable, + &std::free +}; + +class InvalidGCModeError : public std::runtime_error { +public: + InvalidGCModeError(const char *mode) + : runtime_error(std::string("Unknown GC mode \"") + mode + "\"") + {} +}; + +Ops const &get_ops() throw (InvalidGCModeError) { + char *mode_string=std::getenv("_INKSCAPE_GC"); + if (mode_string) { + if (!std::strcmp(mode_string, "enable")) { + return enabled_ops; + } else if (!std::strcmp(mode_string, "debug")) { + return debug_ops; + } else if (!std::strcmp(mode_string, "disable")) { + return disabled_ops; + } else { + throw InvalidGCModeError(mode_string); + } + } else { + return enabled_ops; + } +} + +void die_because_not_initialized() { + g_error("Attempt to use GC allocator before call to Inkscape::GC::init()"); +} + +void *stub_malloc(std::size_t) { + die_because_not_initialized(); + return NULL; +} + +void *stub_base(void *) { + die_because_not_initialized(); + return NULL; +} + +void stub_register_finalizer_ignore_self(void *, CleanupFunc, void *, + CleanupFunc *, void **) +{ + die_because_not_initialized(); +} + +int stub_general_register_disappearing_link(void **, void const *) { + die_because_not_initialized(); + return 0; +} + +int stub_unregister_disappearing_link(void **) { + die_because_not_initialized(); + return 0; +} + +std::size_t stub_get_heap_size() { + die_because_not_initialized(); + return 0; +} + +std::size_t stub_get_free_bytes() { + die_because_not_initialized(); + return 0; +} + +void stub_gcollect() { + die_because_not_initialized(); +} + +void stub_enable() { + die_because_not_initialized(); +} + +void stub_disable() { + die_because_not_initialized(); +} + +void stub_free(void *) { + die_because_not_initialized(); +} + +} + +Ops Core::_ops = { + NULL, + &stub_malloc, + &stub_malloc, + &stub_malloc, + &stub_malloc, + &stub_base, + &stub_register_finalizer_ignore_self, + &stub_general_register_disappearing_link, + &stub_unregister_disappearing_link, + &stub_get_heap_size, + &stub_get_free_bytes, + &stub_gcollect, + &stub_enable, + &stub_disable, + &stub_free +}; + +void Core::init() { + try { + _ops = get_ops(); + } catch (InvalidGCModeError &e) { + g_warning("%s; enabling normal collection", e.what()); + _ops = enabled_ops; + } + + _ops.do_init(); +} + + +namespace { + +bool collection_requested=false; +bool collection_task() { + Core::gcollect(); + Core::gcollect(); + collection_requested=false; + return false; +} + +} + +void request_early_collection() { + if (!collection_requested) { + collection_requested=true; + Glib::signal_idle().connect(sigc::ptr_fun(&collection_task)); + } +} + +} +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : diff --git a/src/main.cpp b/src/main.cpp index 15576109d..5dd8b7cff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,7 +52,7 @@ #include #include -#include "gc-core.h" +#include "libgc/gc-core.h" #ifdef AND #undef AND diff --git a/src/message-stack.h b/src/message-stack.h index 42bf4e8a7..e8d2aa202 100644 --- a/src/message-stack.h +++ b/src/message-stack.h @@ -22,7 +22,7 @@ #include #include -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" #include "message.h" diff --git a/src/selection.h b/src/selection.h index 5964b20e8..e8c85241e 100644 --- a/src/selection.h +++ b/src/selection.h @@ -19,10 +19,10 @@ #include #include -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" -#include "gc-soft-ptr.h" +#include "libgc/gc-soft-ptr.h" #include "sp-item.h" diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 5802a1be3..f1c19d18e 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -32,7 +32,7 @@ #include #include #include // for g_file_set_contents etc., used in _onGet and paste -#include "gc-core.h" +#include "libgc/gc-core.h" #include "xml/repr.h" #include "inkscape.h" #include "io/stringstream.h" diff --git a/src/ui/dialog/filedialog.cpp b/src/ui/dialog/filedialog.cpp index 00ed09551..ca46403a0 100644 --- a/src/ui/dialog/filedialog.cpp +++ b/src/ui/dialog/filedialog.cpp @@ -19,7 +19,7 @@ #include "filedialogimpl-gtkmm.h" #include "filedialog.h" -#include "gc-core.h" +#include "libgc/gc-core.h" #include "ui/dialog-events.h" #include "extension/output.h" #include "preferences.h" diff --git a/src/ui/dialog/filedialogimpl-win32.h b/src/ui/dialog/filedialogimpl-win32.h index f77249abd..1d3640646 100644 --- a/src/ui/dialog/filedialogimpl-win32.h +++ b/src/ui/dialog/filedialogimpl-win32.h @@ -24,7 +24,7 @@ #include "filedialogimpl-gtkmm.h" -#include "gc-core.h" +#include "libgc/gc-core.h" // define WINVER high enough so we get the correct OPENFILENAMEW size #ifndef WINVER #define WINVER 0x0500 diff --git a/src/ui/dialog/memory.cpp b/src/ui/dialog/memory.cpp index 0008eb284..e5fb6b563 100644 --- a/src/ui/dialog/memory.cpp +++ b/src/ui/dialog/memory.cpp @@ -20,7 +20,7 @@ #include #include -#include "gc-core.h" +#include "libgc/gc-core.h" #include "debug/heap.h" #include "verbs.h" diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp index c4dd9df98..e8778d14c 100644 --- a/src/ui/dialog/ocaldialogs.cpp +++ b/src/ui/dialog/ocaldialogs.cpp @@ -26,7 +26,7 @@ #include "path-prefix.h" #include "filedialogimpl-gtkmm.h" #include "ui/interface.h" -#include "gc-core.h" +#include "libgc/gc-core.h" #include "ui/dialog-events.h" #include "io/sys.h" #include "preferences.h" diff --git a/src/ui/view/view.h b/src/ui/view/view.h index 48f4d2549..8edff8709 100644 --- a/src/ui/view/view.h +++ b/src/ui/view/view.h @@ -15,7 +15,7 @@ #include #include #include "message.h" -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" #include <2geom/forward.h> diff --git a/src/undo-stack-observer.h b/src/undo-stack-observer.h index 1057ace8f..a2bcb3a23 100644 --- a/src/undo-stack-observer.h +++ b/src/undo-stack-observer.h @@ -10,7 +10,7 @@ #ifndef SEEN_UNDO_COMMIT_OBSERVER_H #define SEEN_UNDO_COMMIT_OBSERVER_H -#include "gc-managed.h" +#include "libgc/gc-managed.h" namespace Inkscape { diff --git a/src/util/list.h b/src/util/list.h index de5a458e9..05a35320d 100644 --- a/src/util/list.h +++ b/src/util/list.h @@ -12,7 +12,7 @@ #include #include -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "util/reference.h" namespace Inkscape { diff --git a/src/util/share.h b/src/util/share.h index 6b5e6a4ef..46685c593 100644 --- a/src/util/share.h +++ b/src/util/share.h @@ -12,7 +12,7 @@ #ifndef SEEN_INKSCAPE_UTIL_SHARE_H #define SEEN_INKSCAPE_UTIL_SHARE_H -#include "gc-core.h" +#include "libgc/gc-core.h" #include #include diff --git a/src/xml/attribute-record.h b/src/xml/attribute-record.h index a61329b83..70691005e 100644 --- a/src/xml/attribute-record.h +++ b/src/xml/attribute-record.h @@ -6,7 +6,7 @@ #define SEEN_XML_SP_REPR_ATTR_H #include -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "util/share.h" #define SP_REPR_ATTRIBUTE_KEY(a) g_quark_to_string((a)->key) diff --git a/src/xml/composite-node-observer.h b/src/xml/composite-node-observer.h index 3e4b1673a..968fe20dd 100644 --- a/src/xml/composite-node-observer.h +++ b/src/xml/composite-node-observer.h @@ -15,7 +15,7 @@ #ifndef SEEN_INKSCAPE_XML_COMPOSITE_NODE_OBSERVER_H #define SEEN_INKSCAPE_XML_COMPOSITE_NODE_OBSERVER_H -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "xml/node-observer.h" #include "util/list-container.h" diff --git a/src/xml/event.h b/src/xml/event.h index d25ea0e07..bc63ca504 100644 --- a/src/xml/event.h +++ b/src/xml/event.h @@ -24,7 +24,7 @@ typedef unsigned int GQuark; #include #include "util/share.h" #include "util/forward-pointer-iterator.h" -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "xml/node.h" namespace Inkscape { diff --git a/src/xml/log-builder.h b/src/xml/log-builder.h index aa8f2c1c6..e27a5e5ac 100644 --- a/src/xml/log-builder.h +++ b/src/xml/log-builder.h @@ -14,7 +14,7 @@ #ifndef SEEN_INKSCAPE_XML_LOG_BUILDER_H #define SEEN_INKSCAPE_XML_LOG_BUILDER_H -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "xml/node-observer.h" namespace Inkscape { diff --git a/src/xml/subtree.h b/src/xml/subtree.h index 11bf515f1..7b154bd65 100644 --- a/src/xml/subtree.h +++ b/src/xml/subtree.h @@ -15,7 +15,7 @@ #ifndef SEEN_INKSCAPE_XML_SUBTREE_H #define SEEN_INKSCAPE_XML_SUBTREE_H -#include "gc-managed.h" +#include "libgc/gc-managed.h" #include "xml/composite-node-observer.h" namespace Inkscape { -- cgit v1.2.3