]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/include/lily-guile-macros.hh
Release: bump Welcome versions.
[lilypond.git] / lily / include / lily-guile-macros.hh
index 002cbc0a8ec72e896d80d5dcaaedd1c402794d2e..869a52af327c137a72b634e8ac837630f94acfd8 100644 (file)
@@ -1,7 +1,7 @@
 /*
   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
 
 #include "config.hh"
 
+#if GUILEV2
+// if Guile's internal representation switches to utf8, this should be
+// changed accordingly for efficiency's sake.  This is used for
+// strings known to be in ASCII entirely, including any string
+// constants in the C code.
+#define scm_from_ascii_string scm_from_latin1_string
+#define scm_from_ascii_stringn scm_from_latin1_stringn
+#define scm_from_ascii_symbol scm_from_latin1_symbol
+#else
+#define scm_from_ascii_string scm_from_locale_string
+#define scm_from_ascii_stringn scm_from_locale_stringn
+#define scm_from_ascii_symbol scm_from_locale_symbol
+#define scm_from_latin1_string scm_from_locale_string
+#define scm_from_latin1_stringn scm_from_locale_stringn
+#define scm_from_utf8_string scm_from_locale_string
+#define scm_from_utf8_symbol scm_from_locale_symbol
+#define scm_to_utf8_string scm_to_locale_string
+#endif
+
 #ifndef SMOB_FREE_RETURN_VAL
 #define SMOB_FREE_RETURN_VAL(CL) 0
 #endif
@@ -48,7 +67,7 @@ typedef SCM (*scm_t_subr) (GUILE_ELLIPSIS);
 /* this lets us "overload" macros such as get_property to take
    symbols as well as strings */
 inline SCM
-scm_or_str2symbol (char const *c) { return scm_from_locale_symbol (c); }
+scm_or_str2symbol (char const *c) { return scm_from_utf8_symbol (c); }
 
 inline SCM
 scm_or_str2symbol (SCM s)
@@ -69,7 +88,7 @@ scm_or_str2symbol (SCM s)
     SCM value = cached;                                                 \
     if (__builtin_constant_p ((x)))                                     \
       {                                                                 \
-        if (!cached)                                                    \
+        if (!SCM_UNPACK (cached))                                       \
           value = cached = scm_gc_protect_object (scm_or_str2symbol (x)); \
       }                                                                 \
     else                                                                \
@@ -77,32 +96,9 @@ scm_or_str2symbol (SCM s)
     value;                                                              \
   })
 #else
-inline SCM ly_symbol2scm (char const *x) { return scm_from_locale_symbol ((x)); }
+inline SCM ly_symbol2scm (char const *x) { return scm_from_utf8_symbol ((x)); }
 #endif
 
-/*
-  TODO: rename me to ly_c_lily_module_eval
-
-  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 (!cached)                                                    \
-          value = cached = scm_eval (scm_from_locale_symbol (x),                \
-                                    global_lily_module);                \
-      }                                                                 \
-    else                                                                \
-      value = scm_eval (scm_from_locale_symbol (x), global_lily_module);        \
-    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
@@ -110,22 +106,6 @@ inline SCM ly_symbol2scm (char const *x) { return scm_from_locale_symbol ((x));
 #define DECLARE_SCHEME_CALLBACK(NAME, ARGS)     \
   static SCM NAME ARGS;                         \
   static SCM NAME ## _proc
-#define ADD_TYPE_PREDICATE(func, type_name) \
-  void \
-  func ## _type_adder ()                        \
-  {\
-    ly_add_type_predicate ((Type_predicate_ptr)func, type_name);        \
-  }\
-  ADD_SCM_INIT_FUNC(func ## _type_adder_ctor, \
-                    func ## _type_adder);
-#define ADD_TYPE_PREDICATE(func, type_name) \
-  void \
-  func ## _type_adder ()                        \
-  {\
-    ly_add_type_predicate ((Type_predicate_ptr)func, type_name);        \
-  }\
-  ADD_SCM_INIT_FUNC(func ## _type_adder_ctor, \
-                    func ## _type_adder);
 
 string mangle_cxx_identifier (string);
 
@@ -213,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__ ).
@@ -233,6 +213,28 @@ void ly_check_name (const string &cxx, const string &fname);
       }                                                                 \
   }
 
-#define LY_ASSERT_SMOB(klass, var, number) LY_ASSERT_TYPE(klass::unsmob, var, number)
+template <class T>
+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 <class T>
+inline T *ly_assert_smob (SCM var, int number, const char *fun)
+{
+  T *smob = unsmob<T> (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)                              \
+  ly_assert_smob<klass> (var, number, __FUNCTION__)
 
 #endif /* LILY_GUILE_MACROS_HH */