[PD-dev] dogensym voodoo
Jonathan Wilkes
jancsika at yahoo.com
Fri Sep 6 22:29:37 CEST 2013
Hi list,
Can someone explain the symhash voodoo in the dogensym function of
m_class.c?
To me it looks like sym1 could be referring to a location in
the symhash array which isn't yet initialized, so I can't
wrap my head around why sym2->s_name doesn't just
crash Pd.
Code below for easy reference:
/* ---------------- the symbol table ------------------------ */
#define HASHSIZE 1024
static t_symbol *symhash[HASHSIZE];
t_symbol *dogensym(const char *s, t_symbol *oldsym)
{
t_symbol **sym1, *sym2;
unsigned int hash1 = 0, hash2 = 0;
int length = 0;
const char *s2 = s;
while (*s2)
{
hash1 += *s2;
hash2 += hash1;
length++;
s2++;
}
sym1 = symhash + (hash2 & (HASHSIZE-1));
while (sym2 = *sym1)
{
if (!strcmp(sym2->s_name, s)) return(sym2);
sym1 = &sym2->s_next;
}
if (oldsym) sym2 = oldsym;
else
{
sym2 = (t_symbol *)t_getbytes(sizeof(*sym2));
sym2->s_name = t_getbytes(length+1);
sym2->s_next = 0;
sym2->s_thing = 0;
strcpy(sym2->s_name, s);
}
*sym1 = sym2;
return (sym2);
}
More information about the Pd-dev
mailing list