t_hashtab question

Oct 25, 2009 at 1:16pm

t_hashtab question

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!
Cheers,
Leigh

#46058
Oct 26, 2009 at 9:52pm

ahaaaa…
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…?…
for
hashtab_store(tab, gensym(tempbuf), (t_object *)x);

and when looking up I exchanged -

hashtab_lookup(tab, test, &t);
for
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…
Leigh

#165904

You must be logged in to reply to this topic.