[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [10856] trunk/blender/source/blender/ python/api2_2x: made change to NMesh decrefing suggested by theeth, and added 2 more missing decrefs in new_NMFace

Campbell Barton cbarton at metavr.com
Sat Jun 2 04:02:48 CEST 2007


Revision: 10856
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=10856
Author:   campbellbarton
Date:     2007-06-02 04:02:33 +0200 (Sat, 02 Jun 2007)

Log Message:
-----------
made change to NMesh decrefing suggested by theeth, and added 2 more missing decrefs in new_NMFace

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Mesh.c
    trunk/blender/source/blender/python/api2_2x/NMesh.c

Modified: trunk/blender/source/blender/python/api2_2x/Mesh.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Mesh.c	2007-06-02 00:31:20 UTC (rev 10855)
+++ trunk/blender/source/blender/python/api2_2x/Mesh.c	2007-06-02 02:02:33 UTC (rev 10856)
@@ -6928,7 +6928,6 @@
 {	
 	float z,w1,w2,w3,wtot;
 	
-	/*min,max*/
 	if (!POINT_IN_TRI(vec, v1,v2,v3))
 		return 0;
 	

Modified: trunk/blender/source/blender/python/api2_2x/NMesh.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/NMesh.c	2007-06-02 00:31:20 UTC (rev 10855)
+++ trunk/blender/source/blender/python/api2_2x/NMesh.c	2007-06-02 02:02:33 UTC (rev 10856)
@@ -524,16 +524,18 @@
 
 		vlcopy = PyList_New( len );
 
-		if( !vlcopy )
+		if( !vlcopy ) {
+			Py_DECREF(mf);
 			return EXPP_ReturnPyObjError( PyExc_MemoryError,
 						      "couldn't create PyList" );
-
+		}
 		for( i = 0; i < len; i++ ) {
 			item = PySequence_GetItem( vertexlist, i );	/* PySequence increfs */
 
 			if( item )
 				PyList_SET_ITEM( vlcopy, i, item );
 			else {
+				Py_DECREF(mf);
 				Py_DECREF(vlcopy);
 				return EXPP_ReturnPyObjError
 					( PyExc_RuntimeError,
@@ -582,7 +584,7 @@
 
 	PyList_Append( f->v, vert );
 
-	return EXPP_incr_ret( Py_None );
+	Py_RETURN_NONE;
 }
 
 #undef MethodDef
@@ -616,7 +618,7 @@
 		if( mf->image )
 			return Image_CreatePyObject( mf->image );
 		else
-			return EXPP_incr_ret( Py_None );
+			Py_RETURN_NONE;
 	}
 
 	else if( strcmp( name, "mode" ) == 0 )
@@ -1169,7 +1171,7 @@
 	Py_DECREF( me->materials );
 	me->materials = EXPP_incr_ret( pymats );
 
-	return EXPP_incr_ret( Py_None );
+	Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_addMaterial( PyObject * self, PyObject * args )
@@ -1200,7 +1202,7 @@
 
 	PyList_Append( me->materials, ( PyObject * ) pymat );
 
-	return EXPP_incr_ret( Py_None );
+	Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_getKey( BPy_NMesh * self )
@@ -1269,42 +1271,30 @@
 	if( fra > 0 )
 		G.scene->r.cfra = (int)oldfra;
 
-	return EXPP_incr_ret( Py_None );
+	Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_getSelectedFaces( PyObject * self, PyObject * args )
 {
 	BPy_NMesh *nm = ( BPy_NMesh * ) self;
 	Mesh *me = nm->mesh;
-	int flag = 0;
-	
-	MFace *mf;
-	int i;
-	PyObject *l = PyList_New( 0 ), *pyval;
+	int i, totfaces, flag = 0;
+	PyObject *l, *pyval;
 
-	/* dont allow returning more then the NMesh's number of faces */
-	int totfaces = PySequence_Length(nm->faces);
+	if( !PyArg_ParseTuple( args, "|i", &flag ) )
+		return EXPP_ReturnPyObjError( PyExc_ValueError,
+					      "expected int argument (or nothing)" );
 	
-	if( me == NULL ) {
-		Py_DECREF(l);
-		return NULL;
-	}
-	mf = me->mface;
-	if( mf == NULL )
+	l = PyList_New( 0 );
+	if( me == NULL || me->mface == NULL)
 		return l;
-
-	if( !PyArg_ParseTuple( args, "|i", &flag ) ) {
-		Py_DECREF(l);
-		return NULL;
-	}
 	
 	/* make sure not to write more faces then we have */
-	if (totfaces > me->totface)
-		totfaces= me->totface;
+	totfaces= MIN2(me->totface, PySequence_Length(nm->faces));
 	
 	if( flag ) {
 		for( i = 0; i < totfaces; i++ ) {
-			if( mf[i].flag & ME_FACE_SEL ) {
+			if( me->mface[i].flag & ME_FACE_SEL ) {
 				pyval = PyInt_FromLong( i );
 				PyList_Append( l, pyval );
 				Py_DECREF(pyval);
@@ -1312,7 +1302,7 @@
 		}
 	} else {
 		for( i = 0; i < totfaces; i++ ) {
-			if( mf[i].flag & ME_FACE_SEL )
+			if( me->mface[i].flag & ME_FACE_SEL )
 				PyList_Append( l, PyList_GetItem( nm->faces, i ) );
 		}
 	}
@@ -1322,7 +1312,7 @@
 static PyObject *NMesh_getActiveFace( PyObject * self )
 {
 	if( ( ( BPy_NMesh * ) self )->sel_face < 0 )
-		return EXPP_incr_ret( Py_None );
+		Py_RETURN_NONE;
 
 	return Py_BuildValue( "i", ( ( BPy_NMesh * ) self )->sel_face );
 }
@@ -1586,8 +1576,7 @@
 		( short ) EXPP_ClampInt( value, NMESH_SMOOTHRESH_MIN,
 					 NMESH_SMOOTHRESH_MAX );
 
-	Py_INCREF( Py_None );
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_getSubDivLevels( BPy_NMesh * self )
@@ -1619,8 +1608,7 @@
 		( short ) EXPP_ClampInt( render, NMESH_SUBDIV_MIN,
 					 NMESH_SUBDIV_MAX );
 
-	Py_INCREF( Py_None );
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_getMode( BPy_NMesh * self )
@@ -1672,8 +1660,7 @@
 
 	nmesh->mode = mode;
 
-	Py_INCREF( Py_None );
-	return Py_None;
+	Py_RETURN_NONE;
 }
 
 /* METH_VARARGS: function(PyObject *self, PyObject *args) */
@@ -2837,7 +2824,7 @@
 	ob->colbits = old_matmask;	/*@ HACK */
 
 	ob->actcol = 1;
-	return EXPP_incr_ret( Py_None );
+	Py_RETURN_NONE;
 }
 
 static void fill_medge_from_nmesh(Mesh * mesh, BPy_NMesh * nmesh)
@@ -3203,7 +3190,7 @@
 			EXPP_newMaterialList_fromPyList( nmesh->materials );
 		EXPP_incr_mats_us( mesh->mat,
 				   PyList_Size( nmesh->materials ) );
-		return EXPP_incr_ret( Py_None );
+		Py_RETURN_NONE;
 	}
 
 }
@@ -3431,7 +3418,7 @@
     return newEdge;
   }
   else
-    return EXPP_incr_ret( Py_None );
+    Py_RETURN_NONE;
 }
 
 static void removeEdge( BPy_NMesh *nmesh, BPy_NMVert *v1, BPy_NMVert *v2, int ununsedOnly)
@@ -3536,7 +3523,7 @@
 					      "vertices must be different" );
   removeEdge(bmesh, v1, v2, 0);
 
-  return EXPP_incr_ret( Py_None );
+  Py_RETURN_NONE;
 }
 
 
@@ -3589,7 +3576,7 @@
       return edges;
     }
 
-  return EXPP_incr_ret( Py_None );
+  Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_removeFace( PyObject * self, PyObject * args )
@@ -3636,7 +3623,7 @@
       }
     }
 
-  return EXPP_incr_ret( Py_None );
+  Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_printDebug( PyObject * self )
@@ -3685,7 +3672,7 @@
     }
   }
 
-	return EXPP_incr_ret( Py_None );
+	Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_addVertGroup( PyObject * self, PyObject * args )
@@ -3712,7 +3699,7 @@
 
 	EXPP_allqueue( REDRAWBUTSALL, 1 );
 
-	return EXPP_incr_ret( Py_None );
+	Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_removeVertGroup( PyObject * self, PyObject * args )
@@ -3748,7 +3735,7 @@
 
 	EXPP_allqueue( REDRAWBUTSALL, 1 );
 
-	return EXPP_incr_ret( Py_None );
+	Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_assignVertsToGroup( PyObject * self, PyObject * args )
@@ -3834,7 +3821,7 @@
 		add_vert_defnr( object, nIndex, tempInt, weight, assignmode );
 	}
 
-	return EXPP_incr_ret( Py_None );
+	Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_removeVertsFromGroup( PyObject * self, PyObject * args )
@@ -3920,7 +3907,7 @@
 		}
 	}
 
-	return EXPP_incr_ret( Py_None );
+	Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_getVertsFromGroup( PyObject * self, PyObject * args )
@@ -4108,7 +4095,7 @@
 	PyOS_snprintf( defGroup->name, 32, newGr );
 	unique_vertexgroup_name( defGroup, ( ( BPy_NMesh * ) self )->object );
 
-	return EXPP_incr_ret( Py_None );
+	Py_RETURN_NONE;
 }
 
 static PyObject *NMesh_getVertGroupNames( PyObject * self )
@@ -4201,6 +4188,5 @@
 
 	/* should we alternatively return a list of changed verts (and preserve
 	 * the original ones) ? */
-	Py_INCREF( Py_None );
-	return Py_None;
+	Py_RETURN_NONE;
 }





More information about the Bf-blender-cvs mailing list