If I declare this inside a PIKECLASS in a .cmod, I need the canonical:
PIKEFUN void setfoo(void|object foo) { if(THIS->foo) free_object(THIS->foo); if((THIS->foo=foo)) { debug_malloc_touch(THIS->foo); Pike_sp--; /* don't decrease references */ } else pop_stack(); }
to set it.
The question is, should I also free_object() it in the destructor, or does Pike already take care of that somewhere?
It depends on whether THIS->foo is a mapped variable (ie PIKEVAR) or not. If it is mapped, then you don't need to (and if you do, you need to set it to NULL). If it isn't then you should free it in the exit callback.
BTW: In the instant case, you can probably use
assign_short_svalue((union anything *)THIS->foo, (union anything *)foo, PIKE_T_OBJECT); pop_stack();