X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Finclude%2Fsmobs.tcc;h=c0a62535f5e4f830200c8b4a249ae955032d414f;hb=47db9a3883d726ca53e2133a3b2298f78dd6a32e;hp=f7b6fe3e4b0a9a55a1746670092863afa312dc45;hpb=bf090c279f6f8e0ebbffc72d7ee435172dfaddc8;p=lilypond.git diff --git a/lily/include/smobs.tcc b/lily/include/smobs.tcc index f7b6fe3e4b..c0a62535f5 100644 --- a/lily/include/smobs.tcc +++ b/lily/include/smobs.tcc @@ -1,7 +1,7 @@ /* -*- C++ -*- This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 2005--2014 Han-Wen Nienhuys + Copyright (C) 2005--2015 Han-Wen Nienhuys LilyPond is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,6 +28,20 @@ #include "smobs.hh" #include +template +SCM +Smob_base::mark_trampoline (SCM arg) +{ + return (Super::unsmob (arg))->mark_smob (); +} + +template +int +Smob_base::print_trampoline (SCM arg, SCM port, scm_print_state *p) +{ + return (Super::unsmob (arg))->print_smob (port, p); +} + template SCM Smob_base::register_ptr (Super *p) @@ -42,9 +56,33 @@ Smob_base::register_ptr (Super *p) return s; } +// Defaults, should not actually get called +template +SCM +Smob_base::mark_smob () +{ + return SCM_UNSPECIFIED; +} + +template +size_t +Smob_base::free_smob (SCM) +{ + return 0; +} + +template +SCM +Smob_base::equal_p (SCM, SCM) +{ + return SCM_BOOL_F; +} + +// Default, will often get called + template int -Smob_base::print_smob (SCM, SCM p, scm_print_state *) +Smob_base::print_smob (SCM p, scm_print_state *) { scm_puts ("#<", p); scm_puts (smob_name_.c_str (), p); @@ -88,13 +126,18 @@ void Smob_base::init () // While that's not a consideration for type_p_name_, it's easier // doing it like the rest. - if (Super::free_smob != 0) + if (&Super::free_smob != &Smob_base::free_smob) scm_set_smob_free (smob_tag_, Super::free_smob); - if (Super::mark_smob != 0) - scm_set_smob_mark (smob_tag_, Super::mark_smob); - if (Super::print_smob != 0) - scm_set_smob_print (smob_tag_, Super::print_smob); - if (Super::equal_p != 0) + // 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(&Super::mark_smob) != + static_cast(&Smob_base::mark_smob)) + scm_set_smob_mark (smob_tag_, Super::mark_trampoline); + scm_set_smob_print (smob_tag_, Super::print_trampoline); + if (&Super::equal_p != &Smob_base::equal_p) scm_set_smob_equalp (smob_tag_, Super::equal_p); if (Super::type_p_name_ != 0) { @@ -106,7 +149,12 @@ void Smob_base::init () fundoc); scm_c_export (Super::type_p_name_, NULL); } - ly_add_type_predicate ((void *) unsmob, smob_name_.c_str ()); + ly_add_type_predicate ((void *) is_smob, smob_name_.c_str ()); + if (Super::smob_proc_signature_ >= 0) + scm_set_smob_apply (smob_tag_, + (scm_t_subr)Super::smob_proc, + Super::smob_proc_signature_ >> 8, + (Super::smob_proc_signature_ >> 4)&0xf, + Super::smob_proc_signature_ & 0xf); } - #endif