diff options
author | David Kastrup <dak@gnu.org> | 2014-10-08 16:46:52 +0200 |
---|---|---|
committer | David Kastrup <dak@gnu.org> | 2014-10-15 07:45:45 +0200 |
commit | 7f309e69558db5225b92ae003c0818c68988013d (patch) | |
tree | 4ad83b6db8b0c9c82c9e23089de4e7f8b9d7ef42 | |
parent | 6d391dc04f0faa3248d64aa36faf38cf9e4e5fa2 (diff) |
Issue 4156: Define Smob<> constructors
The purpose of this patch is to stop the previous implicit copying of
Smob<> data members in derived copy constructors.
To that purpose, Smob<> has received a private copy constructor (which
gcc unfortunately only considers worth a warning rather than an error
when implicitly used in a default copy constructor) and an inline
default constructor.
Several classes contained virtual copy constructors without being
actually copyable have had their copy constructor removed.
Several copy constructors just containing a failing assertion were
instead removed and left (privately) declared but not defined. This
standard C++ practice leads to link time rather than run time errors in
case an instance of such a class is copied.
Other smob-defining base classes (Simple_smob and Smob{1,2,3}) do not
actually have non-static data members that could be initialized.
Prohibiting the copying of Simple_smob as a base class seems rather
pointless as all of the data members of a derived class are under the
control of the derived class. However, Smob{1,2,3} "misuse" the this
pointer to contain an SCM value. Creating a copy would change the
associated address, a very undesirable operation. So Smob{1,2,3} have
its constructors private and/or disabled.
-rw-r--r-- | lily/book.cc | 1 | ||||
-rw-r--r-- | lily/context-def.cc | 1 | ||||
-rw-r--r-- | lily/context.cc | 5 | ||||
-rw-r--r-- | lily/font-metric.cc | 1 | ||||
-rw-r--r-- | lily/grob.cc | 1 | ||||
-rw-r--r-- | lily/include/context.hh | 2 | ||||
-rw-r--r-- | lily/include/dispatcher.hh | 1 | ||||
-rw-r--r-- | lily/include/engraver-group.hh | 3 | ||||
-rw-r--r-- | lily/include/music-iterator.hh | 3 | ||||
-rw-r--r-- | lily/include/paper-score.hh | 2 | ||||
-rw-r--r-- | lily/include/performer-group.hh | 2 | ||||
-rw-r--r-- | lily/include/score-performer.hh | 2 | ||||
-rw-r--r-- | lily/include/small-smobs.hh | 12 | ||||
-rw-r--r-- | lily/include/smobs.hh | 5 | ||||
-rw-r--r-- | lily/include/sources.hh | 2 | ||||
-rw-r--r-- | lily/include/translator-group.hh | 2 | ||||
-rw-r--r-- | lily/lily-parser.cc | 1 | ||||
-rw-r--r-- | lily/music-iterator.cc | 5 | ||||
-rw-r--r-- | lily/output-def.cc | 1 | ||||
-rw-r--r-- | lily/page-marker.cc | 1 | ||||
-rw-r--r-- | lily/paper-score.cc | 6 | ||||
-rw-r--r-- | lily/prob.cc | 3 | ||||
-rw-r--r-- | lily/scale.cc | 1 | ||||
-rw-r--r-- | lily/scm-hash.cc | 1 | ||||
-rw-r--r-- | lily/score.cc | 1 | ||||
-rw-r--r-- | lily/sources.cc | 5 | ||||
-rw-r--r-- | lily/translator.cc | 4 |
27 files changed, 33 insertions, 41 deletions
diff --git a/lily/book.cc b/lily/book.cc index a6750d78cb..671c26993c 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -47,6 +47,7 @@ Book::Book () } Book::Book (Book const &s) + : Smob<Book> () { paper_ = 0; header_ = SCM_EOL; diff --git a/lily/context-def.cc b/lily/context-def.cc index ec80878b2d..5433337f50 100644 --- a/lily/context-def.cc +++ b/lily/context-def.cc @@ -54,6 +54,7 @@ Context_def::origin () const } Context_def::Context_def (Context_def const &s) + : Smob<Context_def> () { context_aliases_ = SCM_EOL; translator_group_type_ = SCM_EOL; diff --git a/lily/context.cc b/lily/context.cc index 8397875fdf..4a1381ae1b 100644 --- a/lily/context.cc +++ b/lily/context.cc @@ -56,11 +56,6 @@ Context::check_removal () } } -Context::Context (Context const & /* src */) -{ - assert (false); -} - Scheme_hash_table * Context::properties_dict () const { diff --git a/lily/font-metric.cc b/lily/font-metric.cc index a7f934143e..47bdc513d2 100644 --- a/lily/font-metric.cc +++ b/lily/font-metric.cc @@ -63,6 +63,7 @@ Font_metric::Font_metric () } Font_metric::Font_metric (Font_metric const &) + : Smob<Font_metric> () { } diff --git a/lily/grob.cc b/lily/grob.cc index a41ac5d006..faca5077b5 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -92,6 +92,7 @@ Grob::Grob (SCM basicprops) } Grob::Grob (Grob const &s) + : Smob<Grob> () { original_ = (Grob *) & s; diff --git a/lily/include/context.hh b/lily/include/context.hh index 06d0cf10d2..e929a90f83 100644 --- a/lily/include/context.hh +++ b/lily/include/context.hh @@ -37,7 +37,7 @@ public: virtual ~Context (); private: Scheme_hash_table *properties_dict () const; - Context (Context const &src); + Context (Context const &src); // Do not define! Not copyable! DECLARE_CLASSNAME (Context); void terminate (); diff --git a/lily/include/dispatcher.hh b/lily/include/dispatcher.hh index 1f5f41243b..f4fe9156bc 100644 --- a/lily/include/dispatcher.hh +++ b/lily/include/dispatcher.hh @@ -22,6 +22,7 @@ #include "listener.hh" #include "stream-event.hh" +#include "smobs.hh" class Dispatcher : public Smob<Dispatcher> { diff --git a/lily/include/engraver-group.hh b/lily/include/engraver-group.hh index 8f02c20594..be0757acd2 100644 --- a/lily/include/engraver-group.hh +++ b/lily/include/engraver-group.hh @@ -31,8 +31,7 @@ protected: DECLARE_LISTENER (override); DECLARE_LISTENER (revert); public: - VIRTUAL_COPY_CONSTRUCTOR (Translator_group, Engraver_group); - + DECLARE_CLASSNAME (Engraver_group); Engraver_group (); virtual void derived_mark () const; void do_announces (); diff --git a/lily/include/music-iterator.hh b/lily/include/music-iterator.hh index 01bff5d59d..4abf1d270a 100644 --- a/lily/include/music-iterator.hh +++ b/lily/include/music-iterator.hh @@ -70,7 +70,8 @@ protected: Moment start_mom_; DECLARE_CLASSNAME (Music_iterator); - Music_iterator (Music_iterator const &); +private: + Music_iterator (Music_iterator const &); // Do not define! Not copyable! public: Moment music_get_length () const; diff --git a/lily/include/paper-score.hh b/lily/include/paper-score.hh index a919cebce0..383887f455 100644 --- a/lily/include/paper-score.hh +++ b/lily/include/paper-score.hh @@ -61,7 +61,7 @@ protected: virtual void derived_mark () const; private: - Paper_score (Paper_score const &); + Paper_score (Paper_score const &); // Do not define! Not copyable! }; #endif /* PAPER_SCORE_HH */ diff --git a/lily/include/performer-group.hh b/lily/include/performer-group.hh index deaa33efcb..479272acec 100644 --- a/lily/include/performer-group.hh +++ b/lily/include/performer-group.hh @@ -29,7 +29,7 @@ typedef void (Performer:: *Performer_method) (void); class Performer_group : public Translator_group { public: - VIRTUAL_COPY_CONSTRUCTOR (Translator_group, Performer_group); + DECLARE_CLASSNAME (Performer_group); void do_announces (); virtual void announce_element (Audio_element_info); diff --git a/lily/include/score-performer.hh b/lily/include/score-performer.hh index 7a1cb628a6..ef8683db06 100644 --- a/lily/include/score-performer.hh +++ b/lily/include/score-performer.hh @@ -30,7 +30,7 @@ class Score_performer : public Performer_group { public: - VIRTUAL_COPY_CONSTRUCTOR (Translator_group, Score_performer); + DECLARE_CLASSNAME (Score_performer); Performance *performance_; ~Score_performer (); diff --git a/lily/include/small-smobs.hh b/lily/include/small-smobs.hh index fa63af9a90..dcff3596a8 100644 --- a/lily/include/small-smobs.hh +++ b/lily/include/small-smobs.hh @@ -24,8 +24,8 @@ template <class Super> class Smob1 : public Smob_base<Super> { - Smob1 () { } // private constructor: objects don't exist, only - // "pointers" to them + Smob1 (); // Do not define! Not constructible! + Smob1 (const Smob1 &); // Do not define! Not copyable! public: SCM self_scm () const { return SCM_PACK (this); } SCM & scm1 () const { return *SCM_SMOB_OBJECT_LOC (self_scm ()); } @@ -41,8 +41,8 @@ public: template <class Super> class Smob2 : public Smob_base<Super> { - Smob2 () { } // private constructor: objects don't exist, only - // "pointers" to them + Smob2 (); // Do not define! Not constructible! + Smob2 (const Smob2 &); // Do not define! Not copyable! public: SCM self_scm () const { return SCM_PACK (this); } SCM & scm1 () const { return *SCM_SMOB_OBJECT_LOC (self_scm ()); } @@ -65,8 +65,8 @@ public: template <class Super> class Smob3 : public Smob_base<Super> { - Smob3 () { } // private constructor: objects don't exist, only - // "pointers" to them + Smob3 (); // Do not define! Not constructible! + Smob3 (const Smob3 &); // Do not define! Not copyable! public: SCM self_scm () const { return SCM_PACK (this); } SCM & scm1 () const { return *SCM_SMOB_OBJECT_LOC (self_scm ()); } diff --git a/lily/include/smobs.hh b/lily/include/smobs.hh index 2d1cbd4d89..eaf041312f 100644 --- a/lily/include/smobs.hh +++ b/lily/include/smobs.hh @@ -255,6 +255,9 @@ class Smob : public Smob_base<Super> { private: SCM self_scm_; SCM protection_cons_; + Smob (const Smob<Super> &); // Do not define! Not copyable! +protected: + Smob () : self_scm_ (SCM_UNDEFINED), protection_cons_ (SCM_EOL) { }; public: static size_t free_smob (SCM obj) { @@ -263,7 +266,6 @@ public: } SCM unprotected_smobify_self () { - self_scm_ = SCM_UNDEFINED; self_scm_ = Smob_base<Super>::register_ptr (static_cast<Super *> (this)); return self_scm_; } @@ -277,7 +279,6 @@ public: return self_scm_; } void smobify_self () { - protection_cons_ = SCM_EOL; self_scm_ = unprotected_smobify_self (); protect (); } diff --git a/lily/include/sources.hh b/lily/include/sources.hh index 165b59038d..5f14e384eb 100644 --- a/lily/include/sources.hh +++ b/lily/include/sources.hh @@ -25,7 +25,7 @@ class Sources { - Sources (Sources const &); + Sources (Sources const &); // Do not define! Not copyable! vector<Source_file *> sourcefiles_; public: diff --git a/lily/include/translator-group.hh b/lily/include/translator-group.hh index 40152b320b..7373089157 100644 --- a/lily/include/translator-group.hh +++ b/lily/include/translator-group.hh @@ -67,7 +67,7 @@ private: DECLARE_LISTENER (create_child_translator); public: - VIRTUAL_COPY_CONSTRUCTOR (Translator_group, Translator_group); + DECLARE_CLASSNAME (Translator_group); virtual void connect_to_context (Context *c); virtual void disconnect_from_context (); diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 8d0b180e77..fe8a1d2d87 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -54,6 +54,7 @@ Lily_parser::Lily_parser (Sources *sources) } Lily_parser::Lily_parser (Lily_parser const &src, SCM closures, SCM location) + : Smob<Lily_parser> () { lexer_ = 0; sources_ = src.sources_; diff --git a/lily/music-iterator.cc b/lily/music-iterator.cc index 372a33ba1c..171d5ae73f 100644 --- a/lily/music-iterator.cc +++ b/lily/music-iterator.cc @@ -37,11 +37,6 @@ Music_iterator::Music_iterator () smobify_self (); } -Music_iterator::Music_iterator (Music_iterator const &) -{ - assert (false); -} - Music_iterator::~Music_iterator () { } diff --git a/lily/output-def.cc b/lily/output-def.cc index efbe2b937a..72b3f8f172 100644 --- a/lily/output-def.cc +++ b/lily/output-def.cc @@ -45,6 +45,7 @@ Output_def::Output_def () } Output_def::Output_def (Output_def const &s) + : Smob<Output_def> () { scope_ = SCM_EOL; parent_ = 0; diff --git a/lily/page-marker.cc b/lily/page-marker.cc index 78b1b2cefe..f488b20bb5 100644 --- a/lily/page-marker.cc +++ b/lily/page-marker.cc @@ -28,6 +28,7 @@ Page_marker::Page_marker () } Page_marker::Page_marker (Page_marker const &src) + : Smob<Page_marker> () { symbol_ = src.symbol_; permission_ = src.permission_; diff --git a/lily/paper-score.cc b/lily/paper-score.cc index 38f108f3c4..6a2816a161 100644 --- a/lily/paper-score.cc +++ b/lily/paper-score.cc @@ -42,12 +42,6 @@ Paper_score::Paper_score (Output_def *layout) paper_systems_ = SCM_BOOL_F; } -Paper_score::Paper_score (Paper_score const &s) - : Music_output (s) -{ - assert (false); -} - void Paper_score::derived_mark () const { diff --git a/lily/prob.cc b/lily/prob.cc index 918c4d8d70..be4816eece 100644 --- a/lily/prob.cc +++ b/lily/prob.cc @@ -76,7 +76,7 @@ Prob::equal_p (SCM sa, SCM sb) return SCM_BOOL_T; } -Prob::Prob (SCM type, SCM immutable_init) +Prob::Prob (SCM type, SCM immutable_init) : Smob<Prob> () { mutable_property_alist_ = SCM_EOL; immutable_property_alist_ = immutable_init; @@ -89,6 +89,7 @@ Prob::~Prob () } Prob::Prob (Prob const &src) + : Smob<Prob> () { immutable_property_alist_ = src.immutable_property_alist_; mutable_property_alist_ = SCM_EOL; diff --git a/lily/scale.cc b/lily/scale.cc index 8bdf02bdf0..2eee24ba51 100644 --- a/lily/scale.cc +++ b/lily/scale.cc @@ -143,6 +143,7 @@ Scale::Scale (vector<Rational> const &tones) } Scale::Scale (Scale const &src) + : Smob<Scale> () { step_tones_ = src.step_tones_; smobify_self (); diff --git a/lily/scm-hash.cc b/lily/scm-hash.cc index 91958477eb..2f3a808c8d 100644 --- a/lily/scm-hash.cc +++ b/lily/scm-hash.cc @@ -50,6 +50,7 @@ Scheme_hash_table::Scheme_hash_table () } Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src) + : Smob<Scheme_hash_table> () { hash_tab_ = SCM_EOL; smobify_self (); diff --git a/lily/score.cc b/lily/score.cc index 6ebad7db9d..b313b1abee 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -73,6 +73,7 @@ Score::mark_smob () } Score::Score (Score const &s) + : Smob<Score> () { header_ = SCM_EOL; music_ = SCM_EOL; diff --git a/lily/sources.cc b/lily/sources.cc index dc784d2bdb..7b7401b330 100644 --- a/lily/sources.cc +++ b/lily/sources.cc @@ -29,11 +29,6 @@ Sources::Sources () path_ = 0; } -Sources::Sources (Sources const &) -{ - assert (false); -} - void Sources::set_path (File_path *f) { diff --git a/lily/translator.cc b/lily/translator.cc index b2ba4d8768..d37bf954c6 100644 --- a/lily/translator.cc +++ b/lily/translator.cc @@ -54,9 +54,9 @@ Translator::Translator () init (); } -Translator::Translator (Translator const &src) +Translator::Translator (Translator const &) + : Smob<Translator> () { - (void) src; init (); } |