Exppython:
authorWillian Padovani Germano <wpgermano@gmail.com>
Sat, 5 Jul 2003 01:18:41 +0000 (01:18 +0000)
committerWillian Padovani Germano <wpgermano@gmail.com>
Sat, 5 Jul 2003 01:18:41 +0000 (01:18 +0000)
- Continued getting rid of print methods and updating repr ones:
    Needed to fix crashes on Windows >= 98 systems.
- Found and fixed a few small memory leaks in EXPP_interface, related to
  execution of script links.

19 files changed:
source/blender/python/BPY_interface.c
source/blender/python/api2_2x/Armature.c
source/blender/python/api2_2x/Armature.h
source/blender/python/api2_2x/Bone.c
source/blender/python/api2_2x/Camera.c
source/blender/python/api2_2x/Camera.h
source/blender/python/api2_2x/EXPP_interface.c
source/blender/python/api2_2x/EXPP_interface.h
source/blender/python/api2_2x/Image.c
source/blender/python/api2_2x/Image.h
source/blender/python/api2_2x/Lamp.c
source/blender/python/api2_2x/Lamp.h
source/blender/python/api2_2x/Material.c
source/blender/python/api2_2x/NMesh.c
source/blender/python/api2_2x/Scene.c
source/blender/python/api2_2x/Text.c
source/blender/python/api2_2x/Text.h
source/blender/python/api2_2x/rgbTuple.c
source/blender/python/api2_2x/vector.c

index 510dc52085e1878f0ae57b1f523712a57e12e6ce..43b9e0a910f4be554b860216da7d927fb834a80b 100644 (file)
@@ -572,36 +572,6 @@ PyObject * RunPython(Text *text, PyObject *globaldict)
  * to speed-up execution if the user executes the script multiple times */
 
   if (!text->compiled) { /* if it wasn't already compiled, do it now */
-
-/*#ifdef BLENDER_SANDBOX_MODE
-
-// IGNORE THIS ALL FOR A WHILE, IT'S VERY INCOMPLETE AND WILL CHANGE
-// CONSIDERABLY, SOON.  The #ifdef won't stay, either.
-
-// The import statement is a security risk, so we don't allow it in
-// SANDBOX MODE.  Instead, we import all needed modules ourselves and
-// substitute all 'import' and '__import__' statements in the code by
-// '#mport' and '#_import__', resp., making their lines become comments
-// in Python (to let scripts run without import errors).
-
-// Disable importing only for the safest sandbox mode 
-
-    txt_move_bof(text, 0); // move to the beginning of the script
-
-// Search all occurrences of 'import' in the script
-// XXX Also check for from ... import ...
-    while (txt_find_string (text, "import")) {
-      char *line = text->sell->line;
-
-      if (text->curc > 1) // is it '__import__' ?
-        if (strncmp (&line[text->curc - 2],
-                     "__import__", 10) == 0) text->curc -= 2;
-
-      line[text->curc] = '#'; // change them to '#mport' or '#_import__'
-    }
-
-#endif */
-
     buf = txt_to_buf(text);
 
     text->compiled = Py_CompileString(buf, GetName(text), Py_file_input);
@@ -615,12 +585,6 @@ PyObject * RunPython(Text *text, PyObject *globaldict)
 
   }
 
-/*#ifdef BLENDER_SANDBOX_MODE
-  //save the script as a dict entry and call the eval code for it
-  //then return
-  PyDict_SetItemString(globaldict, "_SB_code", text->compiled);
-#endif */
-
   return PyEval_EvalCode(text->compiled, globaldict, globaldict);
 }
 
index 998a36bb11e86a07fcbb0fbacaf3f8a68772becd..03322d678dbba6a868e80ad9d1ebb160d5fe4171 100644 (file)
@@ -311,17 +311,6 @@ static int Armature_setAttr (BPy_Armature *self, char *name, PyObject *value)
   return 0; /* normal exit */
 }
 
-/*****************************************************************************/
-/* Function:    Armature_print                                               */
-/* Description: This is a callback function for the BPy_Armature type. It    */
-/*              builds a meaninful string to 'print' armature objects.       */
-/*****************************************************************************/
-static int Armature_print(BPy_Armature *self, FILE *fp, int flags)
-{ 
-  fprintf(fp, "[Armature \"%s\"]", self->armature->id.name+2);
-  return 0;
-}
-
 /*****************************************************************************/
 /* Function:    Armature_repr                                                */
 /* Description: This is a callback function for the BPy_Armature type. It    */
@@ -329,7 +318,7 @@ static int Armature_print(BPy_Armature *self, FILE *fp, int flags)
 /*****************************************************************************/
 static PyObject *Armature_repr (BPy_Armature *self)
 {
-  return PyString_FromString(self->armature->id.name+2);
+  return PyString_FromFormat("[Armature \"%s\"]", self->armature->id.name+2);
 }
 
 /*****************************************************************************/
index b2fa9611dafcf806c434aa827978937ce819db3a..32c4f3648ace5a1e0a3acdea9e8bdb529f19331c 100644 (file)
@@ -132,7 +132,6 @@ static PyObject *Armature_getAttr (BPy_Armature *armature, char *name);
 static int Armature_setAttr (BPy_Armature *armature, char *name, PyObject *v);
 static int Armature_compare (BPy_Armature *a1, BPy_Armature *a2);
 static PyObject *Armature_repr (BPy_Armature *armature);
-static int Armature_print (BPy_Armature *armature, FILE *fp, int flags);
 
 /*****************************************************************************/
 /* Python TypeArmature structure definition:                                 */
@@ -146,7 +145,7 @@ PyTypeObject Armature_Type =
   0,                                      /* tp_itemsize */
   /* methods */
   (destructor)Armature_dealloc,           /* tp_dealloc */
-  (printfunc)Armature_print,              /* tp_print */
+  0,                                      /* tp_print */
   (getattrfunc)Armature_getAttr,          /* tp_getattr */
   (setattrfunc)Armature_setAttr,          /* tp_setattr */
   (cmpfunc)Armature_compare,              /* tp_compare */
index 56390b99386afa05a6e812142e5bac3a9dd9aeeb..c088662b75026e562019fb4970145b3896e3119e 100644 (file)
@@ -141,7 +141,6 @@ static PyObject *Bone_getAttr (BPy_Bone *bone, char *name);
 static int Bone_setAttr (BPy_Bone *bone, char *name, PyObject *v);
 static int Bone_compare (BPy_Bone *a1, BPy_Bone *a2);
 static PyObject *Bone_repr (BPy_Bone *bone);
-static int Bone_print (BPy_Bone *bone, FILE *fp, int flags);
 
 /*****************************************************************************/
 /* Python TypeBone structure definition:                                     */
@@ -155,7 +154,7 @@ PyTypeObject Bone_Type =
   0,                                    /* tp_itemsize */
   /* methods */
   (destructor)Bone_dealloc,             /* tp_dealloc */
-  (printfunc)Bone_print,                /* tp_print */
+  0,                                    /* tp_print */
   (getattrfunc)Bone_getAttr,            /* tp_getattr */
   (setattrfunc)Bone_setAttr,            /* tp_setattr */
   (cmpfunc)Bone_compare,                /* tp_compare */
@@ -645,18 +644,6 @@ static int Bone_setAttr (BPy_Bone *self, char *name, PyObject *value)
   return 0; /* normal exit */
 }
 
-/*****************************************************************************/
-/* Function:    Bone_print                                                   */
-/* Description: This is a callback function for the BPy_Bone type. It        */
-/*              builds a meaninful string to 'print' bone objects.           */
-/*****************************************************************************/
-static int Bone_print(BPy_Bone *self, FILE *fp, int flags)
-{
-  if (self->bone) fprintf(fp, "[Bone \"%s\"]", self->bone->name);
-  else fprintf(fp, "[Bone NULL]");
-  return 0;
-}
-
 /*****************************************************************************/
 /* Function:    Bone_repr                                                    */
 /* Description: This is a callback function for the BPy_Bone type. It        */
@@ -664,7 +651,8 @@ static int Bone_print(BPy_Bone *self, FILE *fp, int flags)
 /*****************************************************************************/
 static PyObject *Bone_repr (BPy_Bone *self)
 {
-  if (self->bone) return PyString_FromString(self->bone->name);
+  if (self->bone)
+               return PyString_FromFormat("[Bone \"%s\"]", self->bone->name);
   else return PyString_FromString("NULL");
 }
 
index 913949789d4b4c76b197ac5a27824f7df669a1ef..f1317c876e5f6ec2e16977b5777de1af8379a111 100644 (file)
@@ -50,7 +50,6 @@ PyTypeObject Camera_Type =
   0,                             /* tp_itemsize */
   /* methods */
   (destructor)Camera_dealloc,    /* tp_dealloc */
-//  (printfunc)Camera_print,       /* tp_print */
   0,                             /* tp_print */
        (getattrfunc)Camera_getAttr,   /* tp_getattr */
   (setattrfunc)Camera_setAttr,   /* tp_setattr */
@@ -76,7 +75,6 @@ static PyObject *M_Camera_New(PyObject *self, PyObject *args, PyObject *kwords)
   Camera      *blcam; /* for actual Camera Data we create in Blender */
   char        buf[21];
 
-  printf ("In Camera_New()\n");
   /* Parse the arguments passed in by the Python interpreter */
   if (!PyArg_ParseTupleAndKeywords(args, kwords, "|ss", kwlist,
                                    &type_str, &name_str))
@@ -583,13 +581,7 @@ static int Camera_compare (BPy_Camera *a, BPy_Camera *b)
   Camera *pa = a->camera, *pb = b->camera;
   return (pa == pb) ? 0:-1;
 }
-/*
-static int Camera_print(BPy_Camera *self, FILE *fp, int flags)
-{ 
-  fprintf(fp, "[Camera \"%s\"]", self->camera->id.name+2);
-  return 0;
-}
-*/
+
 static PyObject *Camera_repr (BPy_Camera *self)
 {
   return PyString_FromFormat("[Camera \"%s\"]", self->camera->id.name+2);
index b0a2a643c43096837a1ac6b9ddc0f4994090beea..da9f6d9fd14c6c609ad9bac810c3206cf3527359 100644 (file)
@@ -174,7 +174,6 @@ static PyMethodDef BPy_Camera_methods[] = {
 /* Python Camera_Type callback function prototypes:                          */
 /*****************************************************************************/
 static void Camera_dealloc (BPy_Camera *self);
-//static int Camera_print (BPy_Camera *self, FILE *fp, int flags);
 static int Camera_setAttr (BPy_Camera *self, char *name, PyObject *v);
 static int Camera_compare (BPy_Camera *a, BPy_Camera *b);
 static PyObject *Camera_getAttr (BPy_Camera *self, char *name);
index d386bffcd48d235fd6fd764701788fe9265a1e70..56a71112c62cac40bc0299e2a5ef807c3a5f5dec 100644 (file)
@@ -44,6 +44,7 @@
 #include <DNA_scriptlink_types.h>
 #include <DNA_world_types.h>
 
+#include "EXPP_interface.h"
 #include "gen_utils.h"
 #include "modules.h"
 
@@ -54,13 +55,21 @@ void initBlenderApi2_2x (void)
   M_Blender_Init ();
 }
 
+void discardFromBDict (char *key)
+{
+  PyObject *oldval = PyDict_GetItemString(g_blenderdict, key);
+  if (oldval) { Py_DECREF(oldval); }
+}
+
 void clearScriptLinks (void)
 {
+    discardFromBDict ("bylink");
     Py_INCREF (Py_False);
     PyDict_SetItemString (g_blenderdict, "bylink", Py_False);
     /* Old API meant link could be unset. Or even valid when bylink is false.
      * This way, you can import it and check its value afterwards, ignoring
      * bylink. */
+    discardFromBDict ("link");
     Py_INCREF (Py_None);
     PyDict_SetItemString (g_blenderdict, "link", Py_None);
 }
@@ -112,11 +121,13 @@ ScriptLink * setScriptLinks(ID *id, short event)
       link = Py_None;
       break;
     default:
-      Py_INCREF(Py_None);
-      link = Py_None;
+      //Py_INCREF(Py_None);
+      //link = Py_None;
       return NULL;
   }
 
+  discardFromBDict ("bylink");
+
   if (scriptlink == NULL)
   {
     /* This is probably not an internal error anymore :)
@@ -133,7 +144,10 @@ TODO: Check this
     PyDict_SetItemString(g_blenderdict, "bylink", Py_True);
   }
 
+  discardFromBDict ("link");
   PyDict_SetItemString(g_blenderdict, "link", link);
+
+  discardFromBDict ("event");
   PyDict_SetItemString(g_blenderdict, "event",
       Py_BuildValue("s", event_to_name(event)));
 
index 6e4ef1f2687fb92369533f3b40430fd4fc06a282..c9e77b96704f5479bf1001ff8f3d387c4d48224b 100644 (file)
@@ -34,3 +34,4 @@
 void initBlenderApi2_2x (void);
 void clearScriptLinks (void);
 ScriptLink * setScriptLinks(ID *id, short event);
+void discardFromBDict (char *key);
index 6a73e655624ce57355c1ae06f5abdc367fd40772..72c6df7cf1565f9b9e650fc4d52ef1262b5bdfb5 100644 (file)
@@ -146,7 +146,7 @@ static PyObject *M_Image_Get(PyObject *self, PyObject *args)
 
        else { /* () - return a list of all images in the scene */
     int index = 0;
-    PyObject *img_list, *pystr;
+    PyObject *img_list, *pyobj;
 
     img_list = PyList_New (BLI_countlist (&(G.main->image)));
 
@@ -155,13 +155,13 @@ static PyObject *M_Image_Get(PyObject *self, PyObject *args)
               "couldn't create PyList"));
 
                while (img_iter) {
-      pystr = PyString_FromString (img_iter->id.name+2);
+      pyobj = Image_CreatePyObject (img_iter);
 
-                       if (!pystr)
+                       if (!pyobj)
                                return (PythonReturnErrorObject (PyExc_MemoryError,
-                                                                       "couldn't create PyString"));
+                                                                       "couldn't create PyObject"));
 
-                       PyList_SET_ITEM (img_list, index, pystr);
+                       PyList_SET_ITEM (img_list, index, pyobj);
 
       img_iter = img_iter->id.next;
       index++;
@@ -251,12 +251,11 @@ static PyMethodDef BPy_Image_methods[] = {
 /*****************************************************************************/
 /* Python Image_Type callback function prototypes:                           */
 /*****************************************************************************/
-static void Image_Dealloc (BPy_Image *self);
-static int Image_SetAttr (BPy_Image *self, char *name, PyObject *v);
-static int Image_Compare (BPy_Image *a, BPy_Image *b);
-static int Image_Print (BPy_Image *self, FILE *fp, int flags);
-static PyObject *Image_GetAttr (BPy_Image *self, char *name);
-static PyObject *Image_Repr (BPy_Image *self);
+static void Image_dealloc (BPy_Image *self);
+static int Image_setAttr (BPy_Image *self, char *name, PyObject *v);
+static int Image_compare (BPy_Image *a, BPy_Image *b);
+static PyObject *Image_getAttr (BPy_Image *self, char *name);
+static PyObject *Image_repr (BPy_Image *self);
 
 /*****************************************************************************/
 /* Python Image_Type structure definition:                                   */
@@ -269,12 +268,12 @@ PyTypeObject Image_Type =
   sizeof (BPy_Image),                    /* tp_basicsize */
   0,                                     /* tp_itemsize */
   /* methods */
-  (destructor)Image_Dealloc,             /* tp_dealloc */
-  (printfunc)Image_Print,                /* tp_print */
-  (getattrfunc)Image_GetAttr,            /* tp_getattr */
-  (setattrfunc)Image_SetAttr,            /* tp_setattr */
-  (cmpfunc)Image_Compare,                /* tp_compare */
-  (reprfunc)Image_Repr,                  /* tp_repr */
+  (destructor)Image_dealloc,             /* tp_dealloc */
+  0,                                     /* tp_print */
+  (getattrfunc)Image_getAttr,            /* tp_getattr */
+  (setattrfunc)Image_setAttr,            /* tp_setattr */
+  (cmpfunc)Image_compare,                /* tp_compare */
+  (reprfunc)Image_repr,                  /* tp_repr */
   0,                                     /* tp_as_number */
   0,                                     /* tp_as_sequence */
   0,                                     /* tp_as_mapping */
@@ -287,11 +286,11 @@ PyTypeObject Image_Type =
 };
 
 /*****************************************************************************/
-/* Function:    ImageDealloc                                                 */
+/* Function:    Image_dealloc                                                */
 /* Description: This is a callback function for the BPy_Image type. It is    */
 /*              the destructor function.                                     */
 /*****************************************************************************/
-static void Image_Dealloc (BPy_Image *self)
+static void Image_dealloc (BPy_Image *self)
 {
   PyObject_DEL (self);
 }
@@ -403,12 +402,12 @@ static PyObject *Image_setYRep(BPy_Image *self, PyObject *args)
 }
 
 /*****************************************************************************/
-/* Function:    Image_GetAttr                                                */
+/* Function:    Image_getAttr                                                */
 /* Description: This is a callback function for the BPy_Image type. It is    */
 /*              the function that accesses BPy_Image member variables and    */
 /*              methods.                                                     */
 /*****************************************************************************/
-static PyObject *Image_GetAttr (BPy_Image *self, char *name)
+static PyObject *Image_getAttr (BPy_Image *self, char *name)
 {
   PyObject *attr = Py_None;
 
@@ -436,12 +435,12 @@ static PyObject *Image_GetAttr (BPy_Image *self, char *name)
 }
 
 /*****************************************************************************/
-/* Function:    Image_SetAttr                                                */
+/* Function:    Image_setAttr                                                */
 /* Description: This is a callback function for the BPy_Image type. It is the*/
 /*              function that changes Image Data members values. If this     */
 /*              data is linked to a Blender Image, it also gets updated.     */
 /*****************************************************************************/
-static int Image_SetAttr (BPy_Image *self, char *name, PyObject *value)
+static int Image_setAttr (BPy_Image *self, char *name, PyObject *value)
 {
   PyObject *valtuple; 
   PyObject *error = NULL;
@@ -479,36 +478,25 @@ static int Image_SetAttr (BPy_Image *self, char *name, PyObject *value)
 }
 
 /*****************************************************************************/
-/* Function:    Image_Compare                                                */
+/* Function:    Image_compare                                                */
 /* Description: This is a callback function for the BPy_Image type. It       */
 /*              compares two Image_Type objects. Only the "==" and "!="      */
 /*              comparisons are meaninful. Returns 0 for equality and -1 if  */
 /*              they don't point to the same Blender Image struct.           */
 /*              In Python it becomes 1 if they are equal, 0 otherwise.       */
 /*****************************************************************************/
-static int Image_Compare (BPy_Image *a, BPy_Image *b)
+static int Image_compare (BPy_Image *a, BPy_Image *b)
 {
        Image *pa = a->image, *pb = b->image;
        return (pa == pb) ? 0:-1;
 }
 
 /*****************************************************************************/
-/* Function:    Image_Print                                                  */
-/* Description: This is a callback function for the BPy_Image type. It       */
-/*              builds a meaninful string to 'print' image objects.          */
-/*****************************************************************************/
-static int Image_Print(BPy_Image *self, FILE *fp, int flags)
-{ 
-  fprintf(fp, "[Image \"%s\"]", self->image->id.name+2);
-  return 0;
-}
-
-/*****************************************************************************/
-/* Function:    Image_Repr                                                   */
+/* Function:    Image_repr                                                   */
 /* Description: This is a callback function for the BPy_Image type. It       */
 /*              builds a meaninful string to represent image objects.        */
 /*****************************************************************************/
-static PyObject *Image_Repr (BPy_Image *self)
+static PyObject *Image_repr (BPy_Image *self)
 {
-  return PyString_FromString(self->image->id.name+2);
+  return PyString_FromFormat("[Image \"%s\"]", self->image->id.name+2);
 }
index 163eba90eb126366ca5423ebb443c2466289776e..4a62d22bf34be60c38e5161df4b9e8e5ff89f033 100644 (file)
@@ -52,7 +52,7 @@ extern PyTypeObject Image_Type; /* The Image PyType Object */
 /*****************************************************************************/
 /* Module Blender.Image - public functions                                   */
 /*****************************************************************************/
-PyObject *M_Image_Init (void);
+PyObject *Image_Init (void);
 PyObject *Image_CreatePyObject (Image *image);
 int       Image_CheckPyObject (PyObject *pyobj);
 
index a5abfb5ebd3f1293d052491f371f9f5c27960a43..5b9086fd6806c7e33398a530ffa728cf20427e4c 100644 (file)
@@ -42,12 +42,12 @@ PyTypeObject Lamp_Type =
   sizeof (BPy_Lamp),                    /* tp_basicsize */
   0,                                    /* tp_itemsize */
   /* methods */
-  (destructor)Lamp_dealloc,              /* tp_dealloc */
-  (printfunc)Lamp_print,                 /* tp_print */
-  (getattrfunc)Lamp_getAttr,             /* tp_getattr */
-  (setattrfunc)Lamp_setAttr,             /* tp_setattr */
-  (cmpfunc)Lamp_compare,                 /* tp_compare */
-  (reprfunc)Lamp_repr,                   /* tp_repr */
+  (destructor)Lamp_dealloc,             /* tp_dealloc */
+  0,                                    /* tp_print */
+  (getattrfunc)Lamp_getAttr,            /* tp_getattr */
+  (setattrfunc)Lamp_setAttr,            /* tp_setattr */
+  (cmpfunc)Lamp_compare,                /* tp_compare */
+  (reprfunc)Lamp_repr,                  /* tp_repr */
   0,                                    /* tp_as_number */
   0,                                    /* tp_as_sequence */
   0,                                    /* tp_as_mapping */
@@ -1024,17 +1024,6 @@ static int Lamp_compare (BPy_Lamp *a, BPy_Lamp *b)
   return (pa == pb) ? 0:-1;
 }
 
-/*****************************************************************************/
-/* Function:    Lamp_print                                                   */
-/* Description: This is a callback function for the BPy_Lamp type. It        */
-/*              builds a meaninful string to 'print' lamp objects.           */
-/*****************************************************************************/
-static int Lamp_print(BPy_Lamp *self, FILE *fp, int flags)
-{ 
-  fprintf(fp, "[Lamp \"%s\"]", self->lamp->id.name+2);
-  return 0;
-}
-
 /*****************************************************************************/
 /* Function:    Lamp_repr                                                    */
 /* Description: This is a callback function for the BPy_Lamp type. It        */
@@ -1042,5 +1031,5 @@ static int Lamp_print(BPy_Lamp *self, FILE *fp, int flags)
 /*****************************************************************************/
 static PyObject *Lamp_repr (BPy_Lamp *self)
 {
-  return PyString_FromString(self->lamp->id.name+2);
+  return PyString_FromFormat("[Lamp \"%s\"]", self->lamp->id.name+2);
 }
index 50451ed7bb72c13b55bb3cd0dfbc860a35ecc38d..c584d5b7ca0abfbe9422bcc490f8dbcfba36f307 100644 (file)
@@ -279,7 +279,6 @@ static PyObject *Lamp_getAttr (BPy_Lamp *lamp, char *name);
 static int Lamp_setAttr (BPy_Lamp *lamp, char *name, PyObject *v);
 static int Lamp_compare (BPy_Lamp *a, BPy_Lamp *b);
 static PyObject *Lamp_repr (BPy_Lamp *lamp);
-static int Lamp_print (BPy_Lamp *lamp, FILE *fp, int flags);
 
 
 #endif /* EXPP_LAMP_H */
index c4cd3e190913a0a4da4218f8b0f8255ab6f1771b..30b3d61ea81669fe34a29c598cc8b0216baa8745 100644 (file)
@@ -422,11 +422,10 @@ static PyMethodDef BPy_Material_methods[] = {
 /*****************************************************************************/
 /* Python Material_Type callback function prototypes:                        */
 /*****************************************************************************/
-static void Material_Dealloc (BPy_Material *self);
-static int Material_Print (BPy_Material *self, FILE *fp, int flags);
-static int Material_SetAttr (BPy_Material *self, char *name, PyObject *v);
-static PyObject *Material_GetAttr (BPy_Material *self, char *name);
-static PyObject *Material_Repr (BPy_Material *self);
+static void Material_dealloc (BPy_Material *self);
+static int Material_setAttr (BPy_Material *self, char *name, PyObject *v);
+static PyObject *Material_getAttr (BPy_Material *self, char *name);
+static PyObject *Material_repr (BPy_Material *self);
 
 /*****************************************************************************/
 /* Python Material_Type structure definition:                                */
@@ -439,12 +438,12 @@ PyTypeObject Material_Type =
   sizeof (BPy_Material),                  /* tp_basicsize */
   0,                                      /* tp_itemsize */
   /* methods */
-  (destructor)Material_Dealloc,           /* tp_dealloc */
-  (printfunc)Material_Print,              /* tp_print */
-  (getattrfunc)Material_GetAttr,          /* tp_getattr */
-  (setattrfunc)Material_SetAttr,          /* tp_setattr */
+  (destructor)Material_dealloc,           /* tp_dealloc */
+  0,                                      /* tp_print */
+  (getattrfunc)Material_getAttr,          /* tp_getattr */
+  (setattrfunc)Material_setAttr,          /* tp_setattr */
   0,                                      /* tp_compare */
-  (reprfunc)Material_Repr,                /* tp_repr */
+  (reprfunc)Material_repr,                /* tp_repr */
   0,                                      /* tp_as_number */
   0,                                      /* tp_as_sequence */
   0,                                      /* tp_as_mapping */
@@ -457,11 +456,11 @@ PyTypeObject Material_Type =
 };
 
 /*****************************************************************************/
-/* Function:    Material_Dealloc                                             */
+/* Function:    Material_dealloc                                             */
 /* Description: This is a callback function for the BPy_Material type. It is */
 /*              the destructor function.                                     */
 /*****************************************************************************/
-static void Material_Dealloc (BPy_Material *self)
+static void Material_dealloc (BPy_Material *self)
 {
   Py_DECREF (self->col);
   Py_DECREF (self->amb);
@@ -1124,12 +1123,12 @@ static PyObject *Material_setNRings(BPy_Material *self, PyObject *args)
 }
 
 /*****************************************************************************/
-/* Function:    Material_GetAttr                                             */
+/* Function:    Material_getAttr                                             */
 /* Description: This is a callback function for the BPy_Material type. It is */
 /*              the function that accesses BPy_Material "member variables"   */
 /*              and methods.                                                 */
 /*****************************************************************************/
-static PyObject *Material_GetAttr (BPy_Material *self, char *name)
+static PyObject *Material_getAttr (BPy_Material *self, char *name)
 {
   PyObject *attr = Py_None;
 
@@ -1207,12 +1206,12 @@ static PyObject *Material_GetAttr (BPy_Material *self, char *name)
 }
 
 /****************************************************************************/
-/* Function:    Material_SetAttr                                            */
+/* Function:    Material_setAttr                                            */
 /* Description: This is a callback function for the BPy_Material type.      */
 /*              It is the function that sets Material attributes (member    */
 /*              variables).                                                 */
 /****************************************************************************/
-static int Material_SetAttr (BPy_Material *self, char *name, PyObject *value)
+static int Material_setAttr (BPy_Material *self, char *name, PyObject *value)
 {
   PyObject *valtuple; 
   PyObject *error = NULL;
@@ -1302,34 +1301,18 @@ static int Material_SetAttr (BPy_Material *self, char *name, PyObject *value)
 }
 
 /*****************************************************************************/
-/* Function:    Material_Print                                               */
-/* Description: This is a callback function for the BPy_Material type. It    */
-/*              builds a meaninful string to 'print' material objects.       */
-/*****************************************************************************/
-static int Material_Print(BPy_Material *self, FILE *fp, int flags)
-{ 
-  fprintf(fp, "[Material \"%s\"]", self->material->id.name+2);
-  return 0;
-}
-
-/*****************************************************************************/
-/* Function:    Material_Repr                                                */
+/* Function:    Material_repr                                                */
 /* Description: This is a callback function for the BPy_Material type. It    */
 /*              builds a meaninful string to represent material objects.     */
 /*****************************************************************************/
-static PyObject *Material_Repr (BPy_Material *self)
+static PyObject *Material_repr (BPy_Material *self)
 {
-  char buf[40];
-
-  PyOS_snprintf(buf, sizeof(buf), "[Material \"%s\"]",
-                                  self->material->id.name+2);
-
-  return PyString_FromString(buf);
+  return PyString_FromFormat ("[Material \"%s\"]", self->material->id.name+2);
 }
 
 
 /*****************************************************************************/
-/* These three functions are used in NMesh.c                                 */
+/* These functions are used in NMesh.c and Object.c                          */
 /*****************************************************************************/
 PyObject *EXPP_PyList_fromMaterialList (Material **matlist, int len)
 {
index b61be7d8b9143139e6242afd50817b5ba378654d..fdfd6d6714fe9f5961aba8ab90b51188900b1906 100644 (file)
@@ -670,9 +670,6 @@ static PyObject *NMesh_update(PyObject *self, PyObject *args)
     nmesh->mesh = Mesh_fromNMesh(nmesh);
   }
 
-  mesh->mat = EXPP_newMaterialList_fromPyList(nmesh->materials);
-  EXPP_incr_mats_us(mesh->mat, PyList_Size (nmesh->materials));
-
   nmesh_updateMaterials(nmesh);
 /**@ This is another ugly fix due to the weird material handling of blender.
   * it makes sure that object material lists get updated (by their length)
@@ -1336,7 +1333,7 @@ Material **nmesh_updateMaterials(BPy_NMesh *nmesh)
 {
   Material **matlist;
   Mesh *mesh = nmesh->mesh;
-  int len = PySequence_Length(nmesh->materials);
+  int len = PyList_Size(nmesh->materials);
 
   if (!mesh) {
     printf("FATAL INTERNAL ERROR: illegal call to updateMaterials()\n");
@@ -1345,9 +1342,12 @@ Material **nmesh_updateMaterials(BPy_NMesh *nmesh)
 
   if (len > 0) {
     matlist = EXPP_newMaterialList_fromPyList(nmesh->materials);
-    if (mesh->mat)
-      MEM_freeN(mesh->mat);
-    mesh->mat = matlist;
+    EXPP_incr_mats_us(matlist, len);
+
+    if (mesh->mat) MEM_freeN(mesh->mat);
+
+               mesh->mat = matlist;
+
   } else {
     matlist = 0;
   }
@@ -1369,11 +1369,13 @@ PyObject *NMesh_assignMaterials_toObject(BPy_NMesh *nmesh, Object *ob)
 
        nmats = PyList_Size(nmesh->materials);
 
-       if (nmats > 0 && !mesh->mat) { /* explain ... */
+       if (nmats > 0 && !mesh->mat) {
                ob->totcol = nmats;
                mesh->totcol = nmats;
                mesh->mat = MEM_callocN(sizeof(void *)*nmats, "bpy_memats");
-               ob->mat   = MEM_callocN(sizeof(void *)*nmats, "bpy_obmats");
+
+               if (ob->mat) MEM_freeN(ob->mat);
+               ob->mat = MEM_callocN(sizeof(void *)*nmats, "bpy_obmats");
        }
 
   for (i = 0; i < nmats; i++) {
index 72516fc02a3d6a9eaedfd8abde40915aa730ab6a..11b2db24c755ea94095aedf362b8ae508d9f74b1 100644 (file)
@@ -163,7 +163,6 @@ static PyMethodDef BPy_Scene_methods[] = {
 /* Python Scene_Type callback function prototypes:                           */
 /*****************************************************************************/
 static void Scene_dealloc (BPy_Scene *self);
-static int Scene_print (BPy_Scene *self, FILE *fp, int flags);
 static int Scene_setAttr (BPy_Scene *self, char *name, PyObject *v);
 static int Scene_compare (BPy_Scene *a, BPy_Scene *b);
 static PyObject *Scene_getAttr (BPy_Scene *self, char *name);
@@ -181,7 +180,7 @@ PyTypeObject Scene_Type =
   0,                                      /* tp_itemsize */
   /* methods */
   (destructor)Scene_dealloc,              /* tp_dealloc */
-  (printfunc)Scene_print,                 /* tp_print */
+  0,                                      /* tp_print */
   (getattrfunc)Scene_getAttr,             /* tp_getattr */
   (setattrfunc)Scene_setAttr,             /* tp_setattr */
   (cmpfunc)Scene_compare,                 /* tp_compare */
@@ -730,15 +729,9 @@ static int Scene_compare (BPy_Scene *a, BPy_Scene *b)
   return (pa == pb) ? 0:-1;
 }
 
-static int Scene_print(BPy_Scene *self, FILE *fp, int flags)
-{ 
-  fprintf(fp, "[Scene \"%s\"]", self->scene->id.name+2);
-  return 0;
-}
-
 static PyObject *Scene_repr (BPy_Scene *self)
 {
-  return PyString_FromString(self->scene->id.name+2);
+  return PyString_FromFormat("[Scene \"%s\"]", self->scene->id.name+2);
 }
 
 Base *EXPP_Scene_getObjectBase(Scene *scene, Object *object)
index b08da585c2ea79716d2aa468057f08f5806e34c4..e9343cb2a7bbc01a047c55985a91a9a19cc8d6a6 100644 (file)
@@ -485,21 +485,6 @@ static int Text_compare (BPy_Text *a, BPy_Text *b)
   return (pa == pb) ? 0:-1;
 }
 
-/*****************************************************************************/
-/* Function:    Text_print                                                   */
-/* Description: This is a callback function for the BPy_Text type. It        */
-/*              builds a meaninful string to 'print' text objects.           */
-/*****************************************************************************/
-static int Text_print(BPy_Text *self, FILE *fp, int flags)
-{ 
-  if (self->text && Text_IsLinked(self))
-    fprintf(fp, "[Text \"%s\"]", self->text->id.name+2);
-  else
-    fprintf(fp, "[Text <deleted>]");
-
-  return 0;
-}
-
 /*****************************************************************************/
 /* Function:    Text_repr                                                    */
 /* Description: This is a callback function for the BPy_Text type. It        */
@@ -508,9 +493,9 @@ static int Text_print(BPy_Text *self, FILE *fp, int flags)
 static PyObject *Text_repr (BPy_Text *self)
 {
   if (self->text && Text_IsLinked(self))
-    return PyString_FromString(self->text->id.name+2);
+    return PyString_FromFormat("[Text \"%s\"]", self->text->id.name+2);
   else
-    return PyString_FromString("<deleted>");
+    return PyString_FromString("[Text <deleted>]");
 }
 
 /* Internal function to confirm if a Text wasn't unlinked.
index b2ce00c125347bef0e5daaf9066b259b06c09bc5..68819c641dd3ec413ced3cb59bc0adce2c613447 100644 (file)
@@ -144,7 +144,6 @@ static PyMethodDef BPy_Text_methods[] = {
 /* Python Text_Type callback function prototypes:                            */
 /*****************************************************************************/
 static void Text_dealloc (BPy_Text *self);
-static int Text_print (BPy_Text *self, FILE *fp, int flags);
 static int Text_setAttr (BPy_Text *self, char *name, PyObject *v);
 static PyObject *Text_getAttr (BPy_Text *self, char *name);
 static int Text_compare (BPy_Text *a, BPy_Text *b);
@@ -162,7 +161,7 @@ PyTypeObject Text_Type =
   0,                                    /* tp_itemsize */
   /* methods */
   (destructor)Text_dealloc,             /* tp_dealloc */
-  (printfunc)Text_print,                /* tp_print */
+  0,                                    /* tp_print */
   (getattrfunc)Text_getAttr,            /* tp_getattr */
   (setattrfunc)Text_setAttr,            /* tp_setattr */
   (cmpfunc)Text_compare,                /* tp_compare */
index 356ca4145ed2ab8d20155d8e8efae4bd56df9135..2e33525fa9e3476460e91989c441964c9e774f1a 100644 (file)
 /*****************************************************************************/
 /* Python rgbTuple_Type callback function prototypes:                        */
 /*****************************************************************************/
-static void rgbTupleDeAlloc (BPy_rgbTuple *self);
-static PyObject *rgbTupleGetAttr (BPy_rgbTuple *self, char *name);
-static int rgbTupleSetAttr (BPy_rgbTuple *self, char *name, PyObject *v);
-static int rgbTuplePrint(BPy_rgbTuple *self, FILE *fp, int flags);
-static PyObject *rgbTupleRepr (BPy_rgbTuple *self);
+static void rgbTuple_dealloc (BPy_rgbTuple *self);
+static PyObject *rgbTuple_getAttr (BPy_rgbTuple *self, char *name);
+static int rgbTuple_setAttr (BPy_rgbTuple *self, char *name, PyObject *v);
+static PyObject *rgbTuple_repr (BPy_rgbTuple *self);
 
 static int rgbTupleLength(BPy_rgbTuple *self);
 
@@ -86,15 +85,15 @@ PyTypeObject rgbTuple_Type =
   PyObject_HEAD_INIT(NULL)
   0,                                      /* ob_size */
   "rgbTuple",                             /* tp_name */
-  sizeof (BPy_rgbTuple),                    /* tp_basicsize */
+  sizeof (BPy_rgbTuple),                  /* tp_basicsize */
   0,                                      /* tp_itemsize */
   /* methods */
-  (destructor)rgbTupleDeAlloc,            /* tp_dealloc */
-  (printfunc)rgbTuplePrint,               /* tp_print */
-  (getattrfunc)rgbTupleGetAttr,           /* tp_getattr */
-  (setattrfunc)rgbTupleSetAttr,           /* tp_setattr */
+  (destructor)rgbTuple_deAlloc,           /* tp_dealloc */
+  0,                                      /* tp_print */
+  (getattrfunc)rgbTuple_getAttr,          /* tp_getattr */
+  (setattrfunc)rgbTuple_setAttr,          /* tp_setattr */
   0,                                      /* tp_compare */
-  (reprfunc)rgbTupleRepr,                 /* tp_repr */
+  (reprfunc)rgbTuple_repr,                /* tp_repr */
   0,                                      /* tp_as_number */
   &rgbTupleAsSequence,                    /* tp_as_sequence */
   &rgbTupleAsMapping,                     /* tp_as_mapping */
@@ -170,22 +169,22 @@ PyObject *rgbTuple_setCol (BPy_rgbTuple *self, PyObject *args)
 }
 
 /*****************************************************************************/
-/* Function:    rgbTupleDeAlloc                                              */
+/* Function:    rgbTuple_deAlloc                                             */
 /* Description: This is a callback function for the BPy_rgbTuple type. It is */
 /*              the destructor function.                                     */
 /*****************************************************************************/
-static void rgbTupleDeAlloc (BPy_rgbTuple *self)
+static void rgbTuple_deAlloc (BPy_rgbTuple *self)
 {
   PyObject_DEL (self);
 }
 
 /*****************************************************************************/
-/* Function:    rgbTupleGetAttr                                              */
+/* Function:    rgbTuple_getAttr                                             */
 /* Description: This is a callback function for the BPy_rgbTuple type. It is */
 /*              the function that accesses BPy_rgbTuple member variables and */
 /*              methods.                                                     */
 /*****************************************************************************/
-static PyObject* rgbTupleGetAttr (BPy_rgbTuple *self, char *name)
+static PyObject* rgbTuple_getAttr (BPy_rgbTuple *self, char *name)
 {
        int i;
 
@@ -203,11 +202,11 @@ static PyObject* rgbTupleGetAttr (BPy_rgbTuple *self, char *name)
 }
 
 /*****************************************************************************/
-/* Function:    rgbTupleSetAttr                                              */
+/* Function:    rgbTuple_setAttr                                             */
 /* Description: This is a callback function for the BPy_rgbTuple type. It is */
 /*              the function that changes BPy_rgbTuple member variables.     */
 /*****************************************************************************/
-static int rgbTupleSetAttr (BPy_rgbTuple *self, char *name, PyObject *v)
+static int rgbTuple_setAttr (BPy_rgbTuple *self, char *name, PyObject *v)
 {
        float value;
 
@@ -370,32 +369,17 @@ static int rgbTupleAssSlice(BPy_rgbTuple *self, int begin, int end,
 }
 
 /*****************************************************************************/
-/* Function:    rgbTuplePrint                                                */
-/* Description: This is a callback function for the BPy_rgbTuple type. It    */
-/*              builds a meaninful string to 'print' rgbTuple objects.       */
-/*****************************************************************************/
-static int rgbTuplePrint(BPy_rgbTuple *self, FILE *fp, int flags)
-{ 
-  fprintf(fp, "[%f, %f, %f]",
-                                       *(self->rgb[0]), *(self->rgb[1]), *(self->rgb[2]));
-  return 0;
-}
-
-/*****************************************************************************/
-/* Function:    rgbTupleRepr                                                 */
+/* Function:    rgbTuple_repr                                                */
 /* Description: This is a callback function for the BPy_rgbTuple type. It    */
 /*              builds a meaninful string to represent rgbTuple objects.     */
 /*****************************************************************************/
-static PyObject *rgbTupleRepr (BPy_rgbTuple *self)
+static PyObject *rgbTuple_repr (BPy_rgbTuple *self)
 {
        float r, g, b;
-       char buf[64];
 
        r = *(self->rgb[0]);
        g = *(self->rgb[1]);
        b = *(self->rgb[2]);
 
-       PyOS_snprintf(buf, sizeof(buf), "[%f, %f, %f]", r, g, b);
-
-       return PyString_FromString(buf);
+       return PyString_FromFormat("[%f, %f, %f]", r, g, b);
 }
index fac409ab92f48de4e29b7b6012c5221ada7032df..69b32716a2cc77b63a67c6ab9ce85f488f5b926a 100644 (file)
 /*****************************/
 /*    Vector Python Object   */
 /*****************************/
-#define VectorObject_Check(v)  ((v)->ob_type == &vector_Type)
+#define VectorObject_Check(v) ((v)->ob_type == &vector_Type)
 
 static void Vector_dealloc(VectorObject *self)
 {
-       PyObject_DEL (self);
+  PyObject_DEL (self);
 }
 
 static PyObject *Vector_getattr(VectorObject *self, char *name)
 {
-       if (self->size==3 && ELEM3(name[0], 'x', 'y', 'z') && name[1]==0)
-               return PyFloat_FromDouble(self->vec[ name[0]-'x' ]);
+  if (self->size==3 && ELEM3(name[0], 'x', 'y', 'z') && name[1]==0)
+    return PyFloat_FromDouble(self->vec[ name[0]-'x' ]);
 
-       return EXPP_ReturnPyObjError(PyExc_AttributeError, "attribute not found");
+  return EXPP_ReturnPyObjError(PyExc_AttributeError, "attribute not found");
 }
 
 static int Vector_setattr(VectorObject *self, char *name, PyObject *v)
 {
-       float val;
-       
-       if (!PyArg_Parse(v, "f", &val))
-                       return EXPP_ReturnIntError(PyExc_TypeError,
-                                                               "expected float argument");
-
-       if (self->size==3 && ELEM3(name[0], 'x', 'y', 'z') && name[1]==0)
-               self->vec[ name[0]-'x' ]= val;
-       else
-               return -1;
-               
-       return 0;
+  float val;
+  
+  if (!PyArg_Parse(v, "f", &val))
+      return EXPP_ReturnIntError(PyExc_TypeError,
+                "expected float argument");
+
+  if (self->size==3 && ELEM3(name[0], 'x', 'y', 'z') && name[1]==0)
+    self->vec[ name[0]-'x' ]= val;
+  else
+    return -1;
+    
+  return 0;
 }
 
 /* Vectors Sequence methods */
 
 static int Vector_len(VectorObject *self) 
 {
-       return self->size;
+  return self->size;
 }
 
 static PyObject *Vector_item(VectorObject *self, int i)
 {
-       if (i < 0 || i >= self->size)
-                       return EXPP_ReturnPyObjError (PyExc_IndexError,
-                                                                                       "array index out of range");
+  if (i < 0 || i >= self->size)
+      return EXPP_ReturnPyObjError (PyExc_IndexError,
+                      "array index out of range");
 
-       return Py_BuildValue("f", self->vec[i]);
+  return Py_BuildValue("f", self->vec[i]);
 }
 
 static PyObject *Vector_slice(VectorObject *self, int begin, int end)
 {
-       PyObject *list;
-       int count;
-       
-       if (begin < 0) begin= 0;
-       if (end > self->size) end= self->size;
-       if (begin > end) begin= end;
+  PyObject *list;
+  int count;
+  
+  if (begin < 0) begin= 0;
+  if (end > self->size) end= self->size;
+  if (begin > end) begin= end;
 
-       list= PyList_New(end-begin);
+  list= PyList_New(end-begin);
 
-       for (count = begin; count < end; count++)
-               PyList_SetItem(list, count-begin, PyFloat_FromDouble(self->vec[count]));
+  for (count = begin; count < end; count++)
+    PyList_SetItem(list, count-begin, PyFloat_FromDouble(self->vec[count]));
 
-       return list;
+  return list;
 }
 
 static int Vector_ass_item(VectorObject *self, int i, PyObject *ob)
 {
-       if (i < 0 || i >= self->size)
-               return EXPP_ReturnIntError(PyExc_IndexError,
-                                                                               "array assignment index out of range");
+  if (i < 0 || i >= self->size)
+    return EXPP_ReturnIntError(PyExc_IndexError,
+                    "array assignment index out of range");
 
-       if (!PyNumber_Check(ob))
-               return EXPP_ReturnIntError(PyExc_IndexError,
-                                                                               "vector member must be a number");
+  if (!PyNumber_Check(ob))
+    return EXPP_ReturnIntError(PyExc_IndexError,
+                    "vector member must be a number");
 
-       self->vec[i]= PyFloat_AsDouble(ob);
+  self->vec[i]= PyFloat_AsDouble(ob);
 
-       return 0;
+  return 0;
 }
 
 static int Vector_ass_slice(VectorObject *self, int begin, int end, PyObject *seq)
 {
-       int count;
-       
-       if (begin < 0) begin= 0;
-       if (end > self->size) end= self->size;
-       if (begin > end) begin= end;
-
-       if (!PySequence_Check(seq))
-               return EXPP_ReturnIntError(PyExc_TypeError,
-                                                                               "illegal argument type for built-in operation");
-
-       if (PySequence_Length(seq) != (end - begin))
-               return EXPP_ReturnIntError(PyExc_TypeError,
-                                                                               "size mismatch in slice assignment");
-
-       for (count = begin; count < end; count++) {
-               PyObject *ob = PySequence_GetItem(seq, count);
-               
-               if (!PyArg_Parse(ob, "f", &self->vec[count])) {
-                       Py_DECREF(ob);
-                       return -1;
-               }
-               
-               Py_DECREF(ob);
-       }
-
-       return 0;
+  int count;
+  
+  if (begin < 0) begin= 0;
+  if (end > self->size) end= self->size;
+  if (begin > end) begin= end;
+
+  if (!PySequence_Check(seq))
+    return EXPP_ReturnIntError(PyExc_TypeError,
+                    "illegal argument type for built-in operation");
+
+  if (PySequence_Length(seq) != (end - begin))
+    return EXPP_ReturnIntError(PyExc_TypeError,
+                    "size mismatch in slice assignment");
+
+  for (count = begin; count < end; count++) {
+    PyObject *ob = PySequence_GetItem(seq, count);
+    
+    if (!PyArg_Parse(ob, "f", &self->vec[count])) {
+      Py_DECREF(ob);
+      return -1;
+    }
+    
+    Py_DECREF(ob);
+  }
+
+  return 0;
 }
 
 static PyObject *Vector_repr (VectorObject *self)
 {
-       return EXPP_tuple_repr((PyObject *) self, self->size);
+  return EXPP_tuple_repr((PyObject *) self, self->size);
 }
 
 static PySequenceMethods Vector_SeqMethods =
 {
-       (inquiry)                       Vector_len,                               /* sq_length */
-       (binaryfunc)            0,                                              /* sq_concat */
-       (intargfunc)            0,                                                  /* sq_repeat */
-       (intargfunc)            Vector_item,                    /* sq_item */
-       (intintargfunc)         Vector_slice,           /* sq_slice */
-       (intobjargproc)         Vector_ass_item,            /* sq_ass_item */
-       (intintobjargproc)      Vector_ass_slice,         /* sq_ass_slice       */
+  (inquiry)     Vector_len,               /* sq_length */
+  (binaryfunc)    0,                      /* sq_concat */
+  (intargfunc)    0,                      /* sq_repeat */
+  (intargfunc)    Vector_item,            /* sq_item */
+  (intintargfunc)   Vector_slice,         /* sq_slice */
+  (intobjargproc)   Vector_ass_item,      /* sq_ass_item */
+  (intintobjargproc)  Vector_ass_slice,   /* sq_ass_slice */
 };
 
 PyTypeObject vector_Type =
 {
-       PyObject_HEAD_INIT(NULL)
-       0,                                                                         /*ob_size*/
-       "vector",                                                        /*tp_name*/
-       sizeof(VectorObject),                      /*tp_basicsize*/
-       0,                                                                         /*tp_itemsize*/
-       /* methods */
-       (destructor)    Vector_dealloc, /*tp_dealloc*/
-       (printfunc)             0,                                    /*tp_print*/
-       (getattrfunc)   Vector_getattr, /*tp_getattr*/
-       (setattrfunc)   Vector_setattr, /*tp_setattr*/
-       0,                                                                          /*tp_compare*/
-       (reprfunc)              Vector_repr,      /*tp_repr*/
-       0,                                                                          /*tp_as_number*/
-       &Vector_SeqMethods,                             /*tp_as_sequence*/
+  PyObject_HEAD_INIT(NULL)
+  0,                           /*ob_size*/
+  "vector",                    /*tp_name*/
+  sizeof(VectorObject),        /*tp_basicsize*/
+  0,                           /*tp_itemsize*/
+  /* methods */
+  (destructor)  Vector_dealloc, /*tp_dealloc*/
+  (printfunc)   0,              /*tp_print*/
+  (getattrfunc) Vector_getattr, /*tp_getattr*/
+  (setattrfunc) Vector_setattr, /*tp_setattr*/
+  0,                            /*tp_compare*/
+  (reprfunc)    Vector_repr,    /*tp_repr*/
+  0,                            /*tp_as_number*/
+  &Vector_SeqMethods,           /*tp_as_sequence*/
 };
 
 PyObject *newVectorObject(float *vec, int size)
 {
-       VectorObject *self;
+  VectorObject *self;
 
   vector_Type.ob_type = &PyType_Type;
 
-       self= PyObject_NEW(VectorObject, &vector_Type);
-       
-       self->vec= vec;
-       self->size= size;
-       
-       return (PyObject*) self;
+  self= PyObject_NEW(VectorObject, &vector_Type);
+  
+  self->vec= vec;
+  self->size= size;
+  
+  return (PyObject*) self;
 }