X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Finclude%2Flily-guile-macros.hh;h=869a52af327c137a72b634e8ac837630f94acfd8;hb=4051d4410364b9984faa181659a3bfe2763a9736;hp=10520d6dc9cfbc3dfb0fc3501f10ca687e2a9401;hpb=b882256ddb159e7169a30052f0c9fb2999f83b7a;p=lilypond.git diff --git a/lily/include/lily-guile-macros.hh b/lily/include/lily-guile-macros.hh index 10520d6dc9..869a52af32 100644 --- a/lily/include/lily-guile-macros.hh +++ b/lily/include/lily-guile-macros.hh @@ -99,28 +99,6 @@ scm_or_str2symbol (SCM s) inline SCM ly_symbol2scm (char const *x) { return scm_from_utf8_symbol ((x)); } #endif -/* - we don't have to protect the result; it's already part of the - exports list of the module. -*/ - -#define ly_lily_module_constant(x) \ - ({ \ - static SCM cached; \ - /* We store this one locally, since G++ -O2 fucks up else */ \ - SCM value = cached; \ - if (__builtin_constant_p ((x))) \ - { \ - if (!SCM_UNPACK (cached)) \ - value = cached = \ - scm_variable_ref (scm_c_module_lookup (global_lily_module, (x))); \ - } \ - else \ - value = \ - scm_variable_ref (scm_c_module_lookup (global_lily_module, (x))); \ - value; \ - }) - /* Adds the NAME as a Scheme function, and a variable to store the SCM version of the function in the static variable NAME_proc @@ -215,7 +193,7 @@ void ly_check_name (const string &cxx, const string &fname); #define set_object(x, y) internal_set_object (ly_symbol2scm (x), y) #define del_property(x) internal_del_property (ly_symbol2scm (x)) -#ifndef NDEBUG +#ifdef DEBUG /* TODO: include modification callback support here, perhaps through intermediate Grob::instrumented_set_property( .. __LINE__ ). @@ -235,23 +213,28 @@ void ly_check_name (const string &cxx, const string &fname); } \ } +template +T *unsmob (SCM var); + void ly_wrong_smob_arg (bool pred (SCM), SCM var, int number, const char *fun); +// Do not call this directly. +// Use LY_ASSERT_SMOB() which supplies the function name automatically. +template +inline T *ly_assert_smob (SCM var, int number, const char *fun) +{ + T *smob = unsmob (var); + if (smob) + return smob; + + ly_wrong_smob_arg (T::is_smob, var, number, fun); + return 0; +} + // Could be just implemented using LY_ASSERT_TYPE, but this variant // saves a slight amount of code #define LY_ASSERT_SMOB(klass, var, number) \ - { \ - if (!klass::is_smob (var)) \ - ly_wrong_smob_arg (klass::is_smob, var, number, __FUNCTION__); \ - } - -// This variant is for the case where klass::unsmob might actually be -// situated in a base class of klass -#define LY_ASSERT_DERIVED_SMOB(klass, var, number) \ - { \ - if (!derived_unsmob (var)) \ - ly_wrong_smob_arg (klass::is_smob, var, number, __FUNCTION__); \ - } + ly_assert_smob (var, number, __FUNCTION__) #endif /* LILY_GUILE_MACROS_HH */