Forums > Dev

t_hashtab question

Oct 25 2009 | 1:16 pm

Hello all,
I am a little perplexed as to what I am doing wrong here.

I have this code in one object –
note: tempbuf is a char array made from obj name/patcher name.
eg ::trk1::auxvol[1], and the hashtable being stored to is in another object, with the hashtable pointer stored in the s_thing of gensym("leighsobjecttable").

t_object *b;
b = (t_object *)gensym("#B")->s_thing; // get this object pointer
t_hashtab *tab;
tab = (t_hashtab*)gensym("leighsobjecttable")->s_thing;
hashtab_store(tab, gensym(tempbuf), b); // store pointer in hashtab?

Am I storing correctly the object pointer here?….

In my second object i have –

t_object *t;
t_hashtab *tab;
long n;
t_symbol *test; // is passed name of key – eg ::trk1::auxvol[1])
tab = (t_hashtab*)gensym("leighsobjecttable")->s_thing;
hashtab_lookup(tab, test, &t);
n = object_attr_getlong(t, gensym("param_value")); //valid attribute in first object.

I receive no error message, nor the long value I am trying to retrieve unfortunately. I have simply replaced a symbol->s-thing object pointer system with these hashtable parts, so I discount any other possible sources of the problem, eg incorrectly formatted char arrays/symbols.

When I print out a list of keys from my hashtable object it shows them all as being there, so I’m sure I’m missing something again, either in the storage or the lookup of the object pointer.
Many thanks should anyone get a moment to browse over this. I hope my explanation makes sense!

Oct 26 2009 | 9:52 pm

I fair few attempts later, it appears I wasn’t storing a pointer to the object, I exchanged –

hashtab_store(tab, gensym(tempbuf), b);
which in retrospect, I presume is a pointer to the object’s box…?…
hashtab_store(tab, gensym(tempbuf), (t_object *)x);

and when looking up I exchanged –

hashtab_lookup(tab, test, &t);
hashtab_lookup(tab, test, (t_object **)&t);

Everything seems to work well now. I thought to leave a message should others come across the same brainteaser…

Viewing 2 posts - 1 through 2 (of 2 total)

Forums > Dev