]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/include/smobs.tcc
Merge remote branch 'origin/master' into release/unstable
[lilypond.git] / lily / include / smobs.tcc
index 7b5179256709db8570a1137109a6b1f9f14bfa4b..b4dacacaa325ec8759bf321e368b4c8e138cc0ff 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- C++ -*-
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2005--2014 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
 
   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -32,14 +32,20 @@ template <class Super>
 SCM
 Smob_base<Super>::mark_trampoline (SCM arg)
 {
-  return (Super::unsmob (arg))->mark_smob ();
+  Super *ptr = Super::unsmob (arg);
+  if (ptr)
+    return ptr->mark_smob ();
+  return SCM_UNDEFINED;
 }
 
 template <class Super>
 int
 Smob_base<Super>::print_trampoline (SCM arg, SCM port, scm_print_state *p)
 {
-  return (Super::unsmob (arg))->print_smob (port, p);
+  Super *ptr = Super::unsmob (arg);
+  if (ptr)
+    return ptr->print_smob (port, p);
+  return 0;
 }
 
 template <class Super>
@@ -96,6 +102,7 @@ Smob_base<Super>::unregister_ptr (SCM obj)
 {
   Super *p = Super::unchecked_unsmob (obj);
   scm_gc_unregister_collectable_memory (p, sizeof (*p), smob_name_.c_str ());
+  SCM_SET_SMOB_DATA (obj, static_cast<Super *> (0));
   return p;
 }
 
@@ -128,9 +135,12 @@ void Smob_base<Super>::init ()
 
   if (&Super::free_smob != &Smob_base<Super>::free_smob)
     scm_set_smob_free (smob_tag_, Super::free_smob);
-  // Old GCC versions refuse comparing pointers-to-member-function of
-  // covariant types, so we recast here.
-  if (&Super::mark_smob !=
+  // Old GCC versions get their type lattice for pointers-to-members
+  // tangled up to a degree where we need to typecast _both_ covariant
+  // types in order to be able to compare them.  The other comparisons
+  // are for static member functions and thus are ordinary function
+  // pointers which work without those contortions.
+  if (static_cast<SCM (Super::*)()>(&Super::mark_smob) !=
       static_cast<SCM (Super::*)()>(&Smob_base<Super>::mark_smob))
     scm_set_smob_mark (smob_tag_, Super::mark_trampoline);
   scm_set_smob_print (smob_tag_, Super::print_trampoline);