+static void
+print_destructor(Variable *v)
+{
+ char *root;
+
+ if(v->destructor == NULL)
+ return;
+
+ if(v->scope == PRIVATE_SCOPE)
+ root = "self->_priv";
+ else
+ root = "self";
+
+ if(v->destructor_simple) {
+ if(v->destructor_line > 0)
+ out_addline_infile(out, v->destructor_line);
+
+ out_printf(out, "\tif(%s->%s) { "
+ "((*(void (*)(void *))%s)) (%s->%s); "
+ "%s->%s = NULL; }\n",
+ root, v->id, v->destructor, root, v->id,
+ root, v->id);
+
+ if(v->destructor_line > 0)
+ out_addline_outfile(out);
+ } else {
+ out_printf(out, "#define VAR (%s->%s)\n", root, v->id);
+ out_printf(out, "\t{\n");
+ if(v->destructor_line > 0)
+ out_addline_infile(out, v->destructor_line);
+
+ out_printf(out, "\t%s}\n", v->destructor);
+
+ if(v->destructor_line > 0)
+ out_addline_outfile(out);
+ out_printf(out, "\tmemset(&VAR, 0, sizeof(VAR));\n");
+ out_printf(out, "#undef VAR\n");
+ }
+}
+
+static void
+add_destroy(Class *c)
+{
+ out_printf(out, "\nstatic void\n"
+ "___destroy(GtkObject *obj_self)\n"
+ "{\n");
+
+ if(destructors > 0) {
+ out_printf(out, "\t%s *self G_GNUC_UNUSED = %s (obj_self);\n",
+ typebase, macrobase);
+ }
+
+ if(destroy_handler) {
+ /* so we get possible bad argument warning */
+ if(destroy_handler->line_no > 0)
+ out_addline_infile(out, destroy_handler->line_no);
+ out_printf(out, "\t___%x_%s_destroy(obj_self);\n",
+ (guint)destroy_handler->unique_id, funcbase);
+ if(destroy_handler->line_no > 0)
+ out_addline_outfile(out);
+ }
+
+ if(destructors > 0) {
+ GList *li;
+ for(li = ((Class *)class)->nodes;
+ li != NULL;
+ li = li->next) {
+ Node *n = li->data;
+ Variable *v = (Variable *)n;
+ if(n->type == VARIABLE_NODE &&
+ v->scope != CLASS_SCOPE)
+ print_destructor(v);
+ }
+ }
+
+ out_printf(out, "}\n\n");
+}
+
+static void
+add_finalize(Class *c)
+{
+ out_printf(out, "\nstatic void\n"
+ "___finalize(GtkObject *obj_self)\n"
+ "{\n");
+
+ if(privates > 0) {
+ out_printf(out, "\t%s *self = %s (obj_self);\n",
+ typebase, macrobase);
+ }
+
+ if(finalize_handler) {
+ /* so we get possible bad argument warning */
+ if(finalize_handler->line_no > 0)
+ out_addline_infile(out, finalize_handler->line_no);
+ out_printf(out, "\t___%x_%s_finalize(obj_self);\n",
+ (guint)finalize_handler->unique_id, funcbase);
+ if(finalize_handler->line_no > 0)
+ out_addline_outfile(out);
+ }
+
+ if(privates > 0) {
+ out_printf(out, "\tg_free (self->_priv);\n"
+ "\tself->_priv = NULL;\n");
+ }
+
+ out_printf(out, "}\n\n");
+}
+