Commits

lorenz  committed 34cbeeb

fix a reference counting bug in initmath which led to a crash
fixed some unit tests for the math module
fixed a C-API bug for the display module

  • Participants
  • Parent commits d31cd03
  • Branches math_module

Comments (0)

Files changed (3)

 
 MODINIT_DEFINE (math)
 {
-    fprintf(stdout, "init\n"); fflush(stdout);
     PyObject *module, *apiobj;
     static void *c_api[PYGAMEAPI_MATH_NUMSLOTS];
 
     }
 
     if (PyModule_AddObject(module, PYGAMEAPI_LOCAL_ENTRY, apiobj) != 0) {
-        Py_DECREF (apiobj);
         DECREF_MOD (module);
         MODINIT_ERROR;
     }
-    Py_DECREF (apiobj);
 
     MODINIT_RETURN (module);
 }

File src/pygame.h

      PyGAME_C_API[PYGAMEAPI_DISPLAY_FIRSTSLOT + 0])
 
 #define PyVidInfo_Type                                                  \
-    (*(PyTypeObject*)PyGAME_C_API[PYGAMEAPI_SURFACE_FIRSTSLOT + 0])
+    (*(PyTypeObject*)PyGAME_C_API[PYGAMEAPI_DISPLAY_FIRSTSLOT + 0])
 #define PyVidInfo_New                                   \
     (*(PyObject*(*)(SDL_VideoInfo*))                    \
      PyGAME_C_API[PYGAMEAPI_DISPLAY_FIRSTSLOT + 1])

File test/math_test.py

         v2 = Vector2(5.6, 7.8)
         v3 = v1 + v2
         self.assert_(isinstance(v3, Vector2))
-        self.assertEquacl(v3.x, 6.8)
-        self.assertEquacl(v3.y, 11.2)
+        self.assertEqual(v3.x, 6.8)
+        self.assertEqual(v3.y, 11.2)
         v3 = v1 + (5.6, 7.8)
         self.assert_(isinstance(v3, Vector2))
-        self.assertEquacl(v3.x, 6.8)
-        self.assertEquacl(v3.y, 11.2)
+        self.assertEqual(v3.x, 6.8)
+        self.assertEqual(v3.y, 11.2)
         v3 = v1 + [5.6, 7.8]
         self.assert_(isinstance(v3, Vector2))
-        self.assertEquacl(v3.x, 6.8)
-        self.assertEquacl(v3.y, 11.2)
+        self.assertEqual(v3.x, 6.8)
+        self.assertEqual(v3.y, 11.2)
         v3 = (1.2, 3.4) + v2
         self.assert_(isinstance(v3, Vector2))
-        self.assertEquacl(v3.x, 6.8)
-        self.assertEquacl(v3.y, 11.2)
+        self.assertEqual(v3.x, 6.8)
+        self.assertEqual(v3.y, 11.2)
         v3 = [1.2, 3.4] + v2
         self.assert_(isinstance(v3, Vector2))
-        self.assertEquacl(v3.x, 6.8)
-        self.assertEquacl(v3.y, 11.2)
+        self.assertEqual(v3.x, 6.8)
+        self.assertEqual(v3.y, 11.2)
 
     def testSub(self):
         v1 = Vector2(1.2, 3.4)
         v2 = Vector2(5.6, 7.9)
         v3 = v1 - v2
         self.assert_(isinstance(v3, Vector2))
-        self.assertEquacl(v3.x, -4.4)
-        self.assertEquacl(v3.y, -4.5)
-        v3 = v1 + (5.6, 7.9)
+        self.assertEqual(v3.x, 1.2 - 5.6)
+        self.assertEqual(v3.y, 3.4 - 7.9)
+        v3 = v1 - (5.6, 7.9)
         self.assert_(isinstance(v3, Vector2))
-        self.assertEquacl(v3.x, -4.4)
-        self.assertEquacl(v3.y, -4.5)
-        v3 = v1 + [5.6, 7.9]
+        self.assertEqual(v3.x, 1.2 - 5.6)
+        self.assertEqual(v3.y, 3.4 - 7.9)
+        v3 = v1 - [5.6, 7.9]
         self.assert_(isinstance(v3, Vector2))
-        self.assertEquacl(v3.x, -4.4)
-        self.assertEquacl(v3.y, -4.5)
-        v3 = (1.2, 3.4) + v2
+        self.assertEqual(v3.x, 1.2 - 5.6)
+        self.assertEqual(v3.y, 3.4 - 7.9)
+        v3 = (1.2, 3.4) - v2
         self.assert_(isinstance(v3, Vector2))
-        self.assertEquacl(v3.x, -4.4)
-        self.assertEquacl(v3.y, -4.5)
-        v3 = [1.2, 3.4] + v2
+        self.assertEqual(v3.x, 1.2 - 5.6)
+        self.assertEqual(v3.y, 3.4 - 7.9)
+        v3 = [1.2, 3.4] - v2
         self.assert_(isinstance(v3, Vector2))
-        self.assertEquacl(v3.x, -4.4)
-        self.assertEquacl(v3.y, -4.5)
+        self.assertEqual(v3.x, 1.2 - 5.6)
+        self.assertEqual(v3.y, 3.4 - 7.9)
 
     def testScalarMultiplication(self):
         v1 = Vector2(1.2, 3.4)
     def testScalarDivision(self):
         v1 = Vector2(1.2, 3.4)
         v2 = v1 / 5.6
-        self.assertEqual(v2.x, 1.2 / 5.6)
-        self.assertEqual(v2.y, 3.4 / 5.6)
+        self.assertAlmostEqual(v2.x, 1.2 / 5.6)
+        self.assertAlmostEqual(v2.y, 3.4 / 5.6)
         v2 = v1 // -1.2
         self.assertEqual(v2.x, 1.2 // -1.2)
         self.assertEqual(v2.y, 3.4 // -1.2)
         self.assertEqual(v2.y, 3.4)
         self.assertNotEqual(id(v1), id(v2))
         v3 = -v1
-        self.assertEqual(v2.x, -1.2)
-        self.assertEqual(v2.y, -3.4)
+        self.assertEqual(v3.x, -1.2)
+        self.assertEqual(v3.y, -3.4)
         self.assertNotEqual(id(v1), id(v3))
         
     def testCompare(self):