From: Florian Ragwitz Date: Thu, 25 Dec 2008 13:39:35 +0000 (+0000) Subject: Avoid macro expansion of 'name' in PREHASH_KEY. X-Git-Tag: 0.74~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=45a46f7b07df98a007f8618d11243080aaa4443b;p=gitmo%2FClass-MOP.git Avoid macro expansion of 'name' in PREHASH_KEY. --- diff --git a/MOP.xs b/MOP.xs index 038f590..4809efb 100644 --- a/MOP.xs +++ b/MOP.xs @@ -21,7 +21,16 @@ This shuts up warnings from gcc -Wall PERL_HASH(hash_##name, value, sizeof(value) - 1); \ } while (0) -#define PREHASH_KEY(name) PREHASH_KEY_WITH_VALUE(name, #name) +/* this is basically the same as the above macro, except that the value will be + * the stringified name. However, we can't just implement this in terms of + * PREHASH_KEY_WITH_VALUE as that'd cause macro expansion on the value of + * 'name' when it's being passed to the other macro. suggestions on how to make + * this more elegant would be much appreciated */ + +#define PREHASH_KEY(name) do { \ + key_##name = newSVpvs(#name); \ + PERL_HASH(hash_##name, #name, sizeof(#name) - 1); \ +} while (0) DECLARE_KEY(name); DECLARE_KEY(package); @@ -310,9 +319,8 @@ BOOT: PREHASH_KEY(package_name); PREHASH_KEY(methods); PREHASH_KEY(ISA); + PREHASH_KEY(VERSION); PREHASH_KEY_WITH_VALUE(package_cache_flag, "_package_cache_flag"); - /* we can't stringify VERSION as it's a define already */ - PREHASH_KEY_WITH_VALUE(VERSION, "VERSION"); method_metaclass = newSVpvs("method_metaclass"); wrap = newSVpvs("wrap");