OLD | NEW |
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 6 LilyPond is free software: you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation, either version 3 of the License, or | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 inline SCM | 69 inline SCM |
70 scm_or_str2symbol (char const *c) { return scm_from_utf8_symbol (c); } | 70 scm_or_str2symbol (char const *c) { return scm_from_utf8_symbol (c); } |
71 | 71 |
72 inline SCM | 72 inline SCM |
73 scm_or_str2symbol (SCM s) | 73 scm_or_str2symbol (SCM s) |
74 { | 74 { |
75 assert (scm_is_symbol (s)); | 75 assert (scm_is_symbol (s)); |
76 return s; | 76 return s; |
77 } | 77 } |
78 | 78 |
79 /* Using this trick we cache the value of scm_from_locale_symbol ("fooo") where | 79 /* Using this trick we cache the value of scm_from_locale_symbol |
80 "fooo" is a constant string. This is done at the cost of one static | 80 ("fooo") where "fooo" is a constant string. This is done at the |
81 variable per ly_symbol2scm() use, and one boolean evaluation for | 81 cost of one static variable per ly_symbol2scm() use, and the cost |
82 every call. | 82 of C++' mechanism to ensure a static variable is only initialized |
| 83 once. |
83 */ | 84 */ |
84 #define ly_symbol2scm(x) \ | 85 #define ly_symbol2scm(x) \ |
85 ({ \ | 86 (__builtin_constant_p (x) \ |
86 static SCM cached; \ | 87 ? ({ \ |
87 /* We store this one locally, since G++ -O2 fucks up else */ \ | 88 static SCM cached = scm_gc_protect_object (scm_or_str2symbol (x)); \ |
88 SCM value = cached; \ | 89 cached; \ |
89 if (__builtin_constant_p ((x))) \ | 90 }) \ |
90 { \ | 91 : scm_or_str2symbol (x)) |
91 if (!SCM_UNPACK (cached)) \ | |
92 value = cached = scm_gc_protect_object (scm_or_str2symbol (x)); \ | |
93 } \ | |
94 else \ | |
95 value = scm_or_str2symbol (x); \ | |
96 value; \ | |
97 }) | |
98 #else | 92 #else |
99 inline SCM ly_symbol2scm (char const *x) { return scm_from_utf8_symbol ((x)); } | 93 inline SCM ly_symbol2scm (char const *x) { return scm_from_utf8_symbol ((x)); } |
100 #endif | 94 #endif |
101 | 95 |
102 /* | 96 /* |
103 Adds the NAME as a Scheme function, and a variable to store the SCM | 97 Adds the NAME as a Scheme function, and a variable to store the SCM |
104 version of the function in the static variable NAME_proc | 98 version of the function in the static variable NAME_proc |
105 */ | 99 */ |
106 #define DECLARE_SCHEME_CALLBACK(NAME, ARGS) \ | 100 #define DECLARE_SCHEME_CALLBACK(NAME, ARGS) \ |
107 static SCM NAME ARGS; \ | 101 static SCM NAME ARGS; \ |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 return 0; | 225 return 0; |
232 } | 226 } |
233 | 227 |
234 // Could be just implemented using LY_ASSERT_TYPE, but this variant | 228 // Could be just implemented using LY_ASSERT_TYPE, but this variant |
235 // saves a slight amount of code | 229 // saves a slight amount of code |
236 | 230 |
237 #define LY_ASSERT_SMOB(klass, var, number) \ | 231 #define LY_ASSERT_SMOB(klass, var, number) \ |
238 ly_assert_smob<klass> (var, number, __FUNCTION__) | 232 ly_assert_smob<klass> (var, number, __FUNCTION__) |
239 | 233 |
240 #endif /* LILY_GUILE_MACROS_HH */ | 234 #endif /* LILY_GUILE_MACROS_HH */ |
OLD | NEW |