[Bf-committers] pyc and pyo loading

Kester Maddock bf-committers@blender.org
Sat, 28 Jun 2003 01:35:52 +1200


--Boundary-00=_4gE/+RWazhLHlHX
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


Python will only load .pyo files in optimise mode and .pyc files in normal 
mode.
Python embedded in Blender can be set to optimise by setting the environment 
variable PYTHONOPTIMIZE=1
There are two ways to fix this:
1. Make developers aware that if they are distributing python scripts 
compiled, they need to include both .pyc & .pyo.  If they want to be lazy, 
just cp script.pyc script.pyo
2. Make python fall back to .pyc in optimised mode and vice versa.  This 
doesn't look too hard (looking at webcvs...)

PovAnim still isn't working because Blender.sys.dirname and Blender.sys.dirsep 
haven't been implemented in EXPPYTHON yet. :)

Also, Object.getInverseMatrix is broken.  It allocates the inverse matrix on 
the stack, and passes a pointer which is invalid when the function goes out 
of scope.  Patch (in api2_2x/) and test case attached.
This was pointed out by jmerrit in
http://www.blender.org/modules.php?op=modload&name=phpBB2&file=viewtopic&t=1377

Kester

On Fri, 27 Jun 2003 10:55, Douglas Bischoff wrote:
> On Friday, June 27, 2003, at 06:34 AM, Jacques Guignot wrote:
> > povanim loads when the extension is changed to *pyc.
> > I'll investigate further on that.
>
> Yes, this does work on OS X as well.
>
> Still have problems with povanim, error is:
>
>    File "lanc_povanim226_14h.p", line 77, in ?
> AttributeError: 'module' object has no attribute 'sys'
>
> -Bish
>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers@blender.org
> http://www.blender.org/mailman/listinfo/bf-committers

--Boundary-00=_4gE/+RWazhLHlHX
Content-Type: text/x-python;
  charset="iso-8859-1";
  name="imatrix.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="imatrix.py"

from Blender import * 
 
scene = Scene.getCurrent() 
camera = scene.getCurrentCamera() 
imatrix = camera.getInverseMatrix() 
 
print imatrix 
print imatrix[0] 
print imatrix[1] 
print imatrix[2] 
print imatrix[3] 
 

--Boundary-00=_4gE/+RWazhLHlHX
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="blpy-mem.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="blpy-mem.patch"

? Makefile.in
? blpy-mem.patch
Index: Object.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/Object.c,v
retrieving revision 1.18
diff -u -u -3 -r1.18 Object.c
--- Object.c	22 Jun 2003 20:14:11 -0000	1.18
+++ Object.c	27 Jun 2003 13:14:31 -0000
@@ -1,4 +1,4 @@
-/* 
+/*
  *
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
  *
@@ -31,6 +31,8 @@
 
 #include "Object.h"
 
+#include "vector.h"
+#include "MEM_guardedalloc.h"
 /*****************************************************************************/
 /* Python API function prototypes for the Blender module.                    */
 /*****************************************************************************/
@@ -670,12 +672,12 @@
 static PyObject *Object_getInverseMatrix (C_Object *self)
 {
     Object  * ob;
-    float     inverse[4][4];
+    MatrixObject *inverse = newMatrixObject(NULL);
 
     ob = self->object->data;
-    Mat4Invert (inverse, ob->obmat);
+    Mat4Invert (inverse->mem, ob->obmat);
 
-    return (newMatrixObject (inverse));
+    return inverse;
 }
 
 static PyObject *Object_getLocation (C_Object *self, PyObject *args)
Index: matrix.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/matrix.c,v
retrieving revision 1.1
diff -u -u -3 -r1.1 matrix.c
--- matrix.c	22 Jun 2003 20:14:11 -0000	1.1
+++ matrix.c	27 Jun 2003 13:14:32 -0000
@@ -39,6 +39,8 @@
     Py_DECREF (self->rows[2]);
     Py_DECREF (self->rows[3]);
 
+    if (self->mem)
+    	PyMem_Free(self->mem);
     PyMem_DEL (self);
 }
 
@@ -130,7 +132,14 @@
     MatrixObject    * self;
 
     self = PyObject_NEW (MatrixObject, &Matrix_Type);
-    self->mat = mat;
+    if (mat)
+    {
+	self->mem = NULL;
+	self->mat = mat;
+    } else {
+    	self->mem = PyMem_Malloc(4*4*sizeof(float));
+	self->mat = self->mem;
+    }
 
     self->rows[0] = newVectorObject ((float *)(self->mat[0]), 4);
     self->rows[1] = newVectorObject ((float *)(self->mat[1]), 4);
Index: vector.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/python/api2_2x/vector.h,v
retrieving revision 1.2
diff -u -u -3 -r1.2 vector.h
--- vector.h	21 May 2003 19:58:31 -0000	1.2
+++ vector.h	27 Jun 2003 13:14:32 -0000
@@ -66,6 +66,7 @@
 	PyObject_VAR_HEAD
 	PyObject *rows[4];
 	Matrix4Ptr mat;
+	Matrix4Ptr mem;
 
 } MatrixObject;
 

--Boundary-00=_4gE/+RWazhLHlHX--