/** registered item identifier */
.string registered_id;
+void _regCheck(int i, int _max)
+{
+ // this is inside a function to avoid expanding it on compilation everytime
+ // (this very long line would be repeated literally thousands times!)
+ if (i >= _max)
+ LOG_FATALF("Registry capacity exceeded (%d)", _max);
+}
+
/**
* Register a new entity with a registry.
* Must be followed by a semicolon or a function body with a `this` parameter.
{ \
entity this = id; \
if (this == NULL) { \
- if (registry##_COUNT >= registry##_MAX) LOG_FATALF("Registry capacity exceeded (%d)", registry##_MAX); \
+ _regCheck(registry##_COUNT, registry##_MAX); \
this = id = inst; \
this.registered_id = #id; \
REGISTRY_PUSH(registry, fld, this); \
#define REGISTRY_HASH(id) Registry_hash_##id
ERASEABLE
-ACCUMULATE void Registry_check(string r, string server) { }
+ACCUMULATE void Registry_check(string r, string sv) { }
ERASEABLE
ACCUMULATE void Registry_send_all() { }
STATIC_INIT(Registry_check_##id) \
{ \
/* Note: SHA256 isn't always available, use MD4 instead */ \
- string s = "", join = ":"; \
- FOREACH(id, true, s = strcat(s, join, it.registered_id)); \
- s = substring(s, strlen(join), -1); \
+ string s = ""; \
+ FOREACH(id, true, s = strcat(s, ":", it.registered_id)); \
+ s = substring(s, 1, -1); /* remove initial ":" */ \
string h = REGISTRY_HASH(id) = strzone(digest_hex("MD4", s)); \
LOG_DEBUGF(#id ": %s\n[%s]", h, s); \
} \