Mon Mar 13 00:52:07 EST 2006  David M. Cooke <cookedm@physics.mcmaster.ca>
  * [01-fix-unused-variables] Fix unused variable warnings in some type helper functions
diff -rN -u Pyrex/Compiler/Nodes.py Pyrex/Compiler/Nodes.py
--- Pyrex/Compiler/Nodes.py	2006-03-13 03:33:49.000000000 -0500
+++ Pyrex/Compiler/Nodes.py	2006-03-13 03:33:50.000000000 -0500
@@ -510,7 +510,12 @@
         code.putln(
             "static void %s(PyObject *o) {"
                 % scope.mangle_internal("tp_dealloc"))
-        self.generate_self_cast(scope, code)
+        # only need the object cast to the type if we need to decref
+        # some instance attributes
+        for entry in scope.var_entries:
+            if entry.type.is_pyobject:
+                self.generate_self_cast(scope, code)
+                break
         self.generate_usr_dealloc_call(scope, code)
         for entry in scope.var_entries:
             if entry.type.is_pyobject:
@@ -554,9 +559,13 @@
         code.putln(
             "static int %s(PyObject *o, visitproc v, void *a) {"
                 % scope.mangle_internal("tp_traverse"))
-        code.putln(
-                "int e;")
-        self.generate_self_cast(scope, code)
+        # only need e, p if we have object attributes
+        for entry in scope.var_entries:
+            if entry.type.is_pyobject:
+                code.putln(
+                    "int e;")
+                self.generate_self_cast(scope, code)
+                break
         if base_type:
             code.putln(
                     "%s->tp_traverse(o, v, a);" %
@@ -585,7 +594,11 @@
         code.putln(
             "static int %s(PyObject *o) {"
                 % scope.mangle_internal("tp_clear"))
-        self.generate_self_cast(scope, code)
+        # only need cast to self type if have object attributes to dereference
+        for entry in scope.var_entries:
+            if entry.type.is_pyobject:
+                self.generate_self_cast(scope, code)
+                break
         if base_type:
             code.putln(
                 "%s->tp_clear(o);" %

