]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4156: Define Smob<> constructors
authorDavid Kastrup <dak@gnu.org>
Wed, 8 Oct 2014 14:46:52 +0000 (16:46 +0200)
committerDavid Kastrup <dak@gnu.org>
Wed, 15 Oct 2014 05:45:45 +0000 (07:45 +0200)
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.

27 files changed:
lily/book.cc
lily/context-def.cc
lily/context.cc
lily/font-metric.cc
lily/grob.cc
lily/include/context.hh
lily/include/dispatcher.hh
lily/include/engraver-group.hh
lily/include/music-iterator.hh
lily/include/paper-score.hh
lily/include/performer-group.hh
lily/include/score-performer.hh
lily/include/small-smobs.hh
lily/include/smobs.hh
lily/include/sources.hh
lily/include/translator-group.hh
lily/lily-parser.cc
lily/music-iterator.cc
lily/output-def.cc
lily/page-marker.cc
lily/paper-score.cc
lily/prob.cc
lily/scale.cc
lily/scm-hash.cc
lily/score.cc
lily/sources.cc
lily/translator.cc

index a6750d78cbf7ac3e43c17bb0b26c8777341de437..671c26993c2950918d3074692b51341d47bfe2eb 100644 (file)
@@ -47,6 +47,7 @@ Book::Book ()
 }
 
 Book::Book (Book const &s)
+  : Smob<Book> ()
 {
   paper_ = 0;
   header_ = SCM_EOL;
index ec80878b2d9ae1e07a0c86d36192e8c9e1721d0e..5433337f502027701cc63917384991a84403dc14 100644 (file)
@@ -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;
index 8397875fdf93dc8a37a042e7c8c09dfd3bf31aa1..4a1381ae1bb8830970be3a927eaf73f7ed2b2f8c 100644 (file)
@@ -56,11 +56,6 @@ Context::check_removal ()
     }
 }
 
-Context::Context (Context const & /* src */)
-{
-  assert (false);
-}
-
 Scheme_hash_table *
 Context::properties_dict () const
 {
index a7f934143e0707b5d077d4f743b2dde3d7740520..47bdc513d2bf8fc20d104291047ea074bf82aec8 100644 (file)
@@ -63,6 +63,7 @@ Font_metric::Font_metric ()
 }
 
 Font_metric::Font_metric (Font_metric const &)
+  : Smob<Font_metric> ()
 {
 }
 
index a41ac5d006bd4873fbb3d1eb887e9e0139c12132..faca5077b5173b97b7b2e0b14722c556a9ca6853 100644 (file)
@@ -92,6 +92,7 @@ Grob::Grob (SCM basicprops)
 }
 
 Grob::Grob (Grob const &s)
+  : Smob<Grob> ()
 {
   original_ = (Grob *) & s;
 
index 06d0cf10d20888fce617cc8a170d4aa278e94a01..e929a90f83273c5730c15988603e46004cb54141 100644 (file)
@@ -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 ();
index 1f5f41243b395be1677f3d526cfd6195f670143d..f4fe9156bcde77d5fe72a58029c6db17dc052468 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "listener.hh"
 #include "stream-event.hh"
+#include "smobs.hh"
 
 class Dispatcher : public Smob<Dispatcher>
 {
index 8f02c20594e69ec3696e220c82e0e1b511220bb3..be0757acd2a7d74cdd5f1226916d78a7d21aeb71 100644 (file)
@@ -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 ();
index 01bff5d59d774a4c6a81fc4726f6ff73d80da221..4abf1d270afd9042c50b963509091cba80a63afd 100644 (file)
@@ -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;
index a919cebce0973b5173af1b91e1eb1dc835b84a7c..383887f4550da373d891e837f629514ecf0ae399 100644 (file)
@@ -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 */
index deaa33efcb66b4cec6011239c3d998d635f64bd1..479272acecad352ef4c042175c3e02e1dd67cefb 100644 (file)
@@ -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);
index 7a1cb628a68ee2c1bf6dc4e4643894ff5fd3d14b..ef8683db066281c14b1fe127922f7331b8cdc60d 100644 (file)
@@ -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 ();
index fa63af9a90057672fb18c86df2c17c55dcad7919..dcff3596a81e9b190fca972dfef33db2f6b8c5c4 100644 (file)
@@ -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 ()); }
index 2d1cbd4d892ac91857118d4fcfda1c887bc88e80..eaf041312f9ae3a734816018366382c0ad6789e8 100644 (file)
@@ -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 ();
   }
index 165b59038df137ec5c234c05b6be148ba5ab80e1..5f14e384eb6743db81662138c910cf68d03960a8 100644 (file)
@@ -25,7 +25,7 @@
 
 class Sources
 {
-  Sources (Sources const &);
+  Sources (Sources const &);  // Do not define!  Not copyable!
   vector<Source_file *> sourcefiles_;
 
 public:
index 40152b320bb135248d1156600f117613515d1cac..737308915770cbaa56f1bc152a14c860a0eca875 100644 (file)
@@ -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 ();
index 8d0b180e77697e5328651afea94f5662b2642953..fe8a1d2d87c62e89e318e26e87d9356c29198c38 100644 (file)
@@ -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_;
index 372a33ba1c8f7747b037b01c7b052d135f9e5012..171d5ae73f1ef837493e63a10423de3ccf3260a6 100644 (file)
@@ -37,11 +37,6 @@ Music_iterator::Music_iterator ()
   smobify_self ();
 }
 
-Music_iterator::Music_iterator (Music_iterator const &)
-{
-  assert (false);
-}
-
 Music_iterator::~Music_iterator ()
 {
 }
index efbe2b937a90cda559d8c5ea904b41923e8f5f47..72b3f8f1720eef3a12ff76233594e0997432f367 100644 (file)
@@ -45,6 +45,7 @@ Output_def::Output_def ()
 }
 
 Output_def::Output_def (Output_def const &s)
+  : Smob<Output_def> ()
 {
   scope_ = SCM_EOL;
   parent_ = 0;
index 78b1b2cefe59cd0113398367213458b866d126e3..f488b20bb50dac0f0cb31eaf96cefb26088561cd 100644 (file)
@@ -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_;
index 38f108f3c425bda821f93e0a4adc3269228e7fab..6a2816a1613324389b16f1d6fb05da4698551bd3 100644 (file)
@@ -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
 {
index 918c4d8d70546afb1987a96f42dc598d70d3d2f9..be4816eece997a0b8af3c8312d430e7f788f4fdb 100644 (file)
@@ -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;
index 8bdf02bdf002f185dbb29189dc271320101447bb..2eee24ba51c7a304c01bc9d33f31b7b8ebf53daf 100644 (file)
@@ -143,6 +143,7 @@ Scale::Scale (vector<Rational> const &tones)
 }
 
 Scale::Scale (Scale const &src)
+  : Smob<Scale> ()
 {
   step_tones_ = src.step_tones_;
   smobify_self ();
index 91958477eb45636ea81209ed9835eca99fbb4b92..2f3a808c8d9798945a0c5decc101c789efa0fabe 100644 (file)
@@ -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 ();
index 6ebad7db9dc1a7e822abc53016d6d1f732d9f6a1..b313b1abeee830878b13aa6a9263563e86afa9a4 100644 (file)
@@ -73,6 +73,7 @@ Score::mark_smob ()
 }
 
 Score::Score (Score const &s)
+  : Smob<Score> ()
 {
   header_ = SCM_EOL;
   music_ = SCM_EOL;
index dc784d2bdb5f20c17058f2219309d2e6e44c08b2..7b7401b330cc1a44f31983517824dcd619e67ca4 100644 (file)
@@ -29,11 +29,6 @@ Sources::Sources ()
   path_ = 0;
 }
 
-Sources::Sources (Sources const &)
-{
-  assert (false);
-}
-
 void
 Sources::set_path (File_path *f)
 {
index b2ba4d8768129acf73fa6f6241a7e1550f8fa965..d37bf954c680f4ca342b9c3c30a0026f5c02c0a6 100644 (file)
@@ -54,9 +54,9 @@ Translator::Translator ()
   init ();
 }
 
-Translator::Translator (Translator const &src)
+Translator::Translator (Translator const &)
+  : Smob<Translator> ()
 {
-  (void) src;
   init ();
 }