[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39986] trunk/blender/source: use Py_ssize_t rather than int when dealing with list sizes ( original patch from Fedora but applied changes elsewhere too), also replace PyList_Size with PyList_GET_SIZE where typechecking is already done .

Campbell Barton ideasman42 at gmail.com
Wed Sep 7 01:46:21 CEST 2011


Revision: 39986
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39986
Author:   campbellbarton
Date:     2011-09-06 23:46:20 +0000 (Tue, 06 Sep 2011)
Log Message:
-----------
use Py_ssize_t rather than int when dealing with list sizes (original patch from Fedora but applied changes elsewhere too), also replace PyList_Size with PyList_GET_SIZE where typechecking is already done.

Modified Paths:
--------------
    trunk/blender/source/blender/python/generic/bpy_internal_import.c
    trunk/blender/source/blender/python/intern/bpy_rna.c
    trunk/blender/source/blender/python/mathutils/mathutils_geometry.c
    trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
    trunk/blender/source/gameengine/Expressions/ListValue.cpp
    trunk/blender/source/gameengine/Expressions/Value.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp

Modified: trunk/blender/source/blender/python/generic/bpy_internal_import.c
===================================================================
--- trunk/blender/source/blender/python/generic/bpy_internal_import.c	2011-09-06 22:18:12 UTC (rev 39985)
+++ trunk/blender/source/blender/python/generic/bpy_internal_import.c	2011-09-06 23:46:20 UTC (rev 39986)
@@ -344,7 +344,7 @@
 	
 	/* looping over the dict */
 	PyObject *key, *value;
-	int pos= 0;
+	Py_ssize_t pos= 0;
 	
 	/* new list */
 	PyObject *list;
@@ -374,7 +374,7 @@
 	}
 	
 	/* remove all our modules */
-	for(pos=0; pos < PyList_Size(list); pos++) {
+	for(pos=0; pos < PyList_GET_SIZE(list); pos++) {
 		/* PyObject_Print(key, stderr, 0); */
 		key= PyList_GET_ITEM(list, pos);
 		PyDict_DelItem(modules, key);

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2011-09-06 22:18:12 UTC (rev 39985)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2011-09-06 23:46:20 UTC (rev 39986)
@@ -4608,7 +4608,7 @@
 
 
 #ifdef DEBUG_STRING_FREE
-	// if(PyList_Size(string_free_ls)) printf("%.200s.%.200s():  has %d strings\n", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), (int)PyList_Size(string_free_ls));
+	// if(PyList_GET_SIZE(string_free_ls)) printf("%.200s.%.200s():  has %d strings\n", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), (int)PyList_GET_SIZE(string_free_ls));
 	Py_DECREF(string_free_ls);
 #undef DEBUG_STRING_FREE
 #endif

Modified: trunk/blender/source/blender/python/mathutils/mathutils_geometry.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_geometry.c	2011-09-06 22:18:12 UTC (rev 39985)
+++ trunk/blender/source/blender/python/mathutils/mathutils_geometry.c	2011-09-06 23:46:20 UTC (rev 39986)
@@ -983,7 +983,7 @@
 
 static int boxPack_FromPyObject(PyObject *value, boxPack **boxarray)
 {
-	int len, i;
+	Py_ssize_t len, i;
 	PyObject *list_item, *item_1, *item_2;
 	boxPack *box;
 
@@ -995,14 +995,14 @@
 		return -1;
 	}
 
-	len= PyList_Size(value);
+	len= PyList_GET_SIZE(value);
 
 	(*boxarray)= MEM_mallocN(len*sizeof(boxPack), "boxPack box");
 
 
 	for(i= 0; i < len; i++) {
 		list_item= PyList_GET_ITEM(value, i);
-		if(!PyList_Check(list_item) || PyList_Size(list_item) < 4) {
+		if(!PyList_Check(list_item) || PyList_GET_SIZE(list_item) < 4) {
 			MEM_freeN(*boxarray);
 			PyErr_SetString(PyExc_TypeError,
 			                "can only pack a list of [x, y, w, h]");
@@ -1034,11 +1034,11 @@
 
 static void boxPack_ToPyObject(PyObject *value, boxPack **boxarray)
 {
-	int len, i;
+	Py_ssize_t len, i;
 	PyObject *list_item;
 	boxPack *box;
 
-	len= PyList_Size(value);
+	len= PyList_GET_SIZE(value);
 
 	for(i= 0; i < len; i++) {
 		box= (*boxarray)+i;
@@ -1062,7 +1062,7 @@
 static PyObject *M_Geometry_box_pack_2d(PyObject *UNUSED(self), PyObject *boxlist)
 {
 	float tot_width= 0.0f, tot_height= 0.0f;
-	int len;
+	Py_ssize_t len;
 
 	PyObject *ret;
 

Modified: trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
===================================================================
--- trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp	2011-09-06 22:18:12 UTC (rev 39985)
+++ trunk/blender/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp	2011-09-06 23:46:20 UTC (rev 39986)
@@ -507,9 +507,10 @@
 				//PyDict_Clear(PyModule_GetDict(gameLogic));
 				
 				// Keep original items, means python plugins will autocomplete members
-				int listIndex;
 				PyObject *gameLogic_keys_new = PyDict_Keys(PyModule_GetDict(gameLogic));
-				for (listIndex=0; listIndex < PyList_Size(gameLogic_keys_new); listIndex++)  {
+				const Py_ssize_t numitems= PyList_GET_SIZE(gameLogic_keys_new);
+				Py_ssize_t listIndex;
+				for (listIndex=0; listIndex < numitems; listIndex++)  {
 					PyObject* item = PyList_GET_ITEM(gameLogic_keys_new, listIndex);
 					if (!PySequence_Contains(gameLogic_keys, item)) {
 						PyDict_DelItem(	PyModule_GetDict(gameLogic), item);

Modified: trunk/blender/source/gameengine/Expressions/ListValue.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/ListValue.cpp	2011-09-06 22:18:12 UTC (rev 39985)
+++ trunk/blender/source/gameengine/Expressions/ListValue.cpp	2011-09-06 23:46:20 UTC (rev 39986)
@@ -387,7 +387,7 @@
 static PyObject *listvalue_buffer_concat(PyObject * self, PyObject * other)
 {
 	CListValue *listval= static_cast<CListValue *>(BGE_PROXY_REF(self));
-	int i, numitems, numitems_orig;
+	Py_ssize_t i, numitems, numitems_orig;
 	
 	if (listval==NULL) {
 		PyErr_SetString(PyExc_SystemError, "CList+other, "BGE_PROXY_ERROR_MSG);
@@ -408,7 +408,7 @@
 		CValue* listitemval;
 		bool error = false;
 		
-		numitems = PyList_Size(other);
+		numitems = PyList_GET_SIZE(other);
 		
 		/* copy the first part of the list */
 		listval_new->Resize(numitems_orig + numitems);

Modified: trunk/blender/source/gameengine/Expressions/Value.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/Value.cpp	2011-09-06 22:18:12 UTC (rev 39985)
+++ trunk/blender/source/gameengine/Expressions/Value.cpp	2011-09-06 23:46:20 UTC (rev 39986)
@@ -546,8 +546,8 @@
 		CListValue* listval = new CListValue();
 		bool error = false;
 
-		int i;
-		int numitems = PyList_Size(pyobj);
+		Py_ssize_t i;
+		Py_ssize_t numitems = PyList_GET_SIZE(pyobj);
 		for (i=0;i<numitems;i++)
 		{
 			PyObject* listitem = PyList_GetItem(pyobj,i); /* borrowed ref */

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2011-09-06 22:18:12 UTC (rev 39985)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2011-09-06 23:46:20 UTC (rev 39986)
@@ -725,7 +725,7 @@
 	if(idcode==ID_ME) {
 		PyObject *ret= PyList_New(0);
 		PyObject *item;
-		for(int i= 0; i < PyList_GET_SIZE(names); i++) {
+		for(Py_ssize_t i= 0; i < PyList_GET_SIZE(names); i++) {
 			name= _PyUnicode_AsString(PyList_GET_ITEM(names, i));
 			if(name) {
 				RAS_MeshObject *meshobj= kx_scene->GetSceneConverter()->ConvertMeshSpecial(kx_scene, maggie, name);
@@ -1751,7 +1751,7 @@
 	
 	initPySysObjects__append(sys_path, gp_GamePythonPath);
 	
-//	fprintf(stderr, "\nNew Path: %d ", PyList_Size(sys_path));
+//	fprintf(stderr, "\nNew Path: %d ", PyList_GET_SIZE(sys_path));
 //	PyObject_Print(sys_path, stderr, 0);
 }
 
@@ -1775,7 +1775,7 @@
 	gp_OrigPythonSysModules= NULL;	
 	
 	
-//	fprintf(stderr, "\nRestore Path: %d ", PyList_Size(sys_path));
+//	fprintf(stderr, "\nRestore Path: %d ", PyList_GET_SIZE(sys_path));
 //	PyObject_Print(sys_path, stderr, 0);
 }
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp	2011-09-06 22:18:12 UTC (rev 39985)
+++ trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp	2011-09-06 23:46:20 UTC (rev 39986)
@@ -1916,7 +1916,7 @@
 
 void KX_Scene::RunDrawingCallbacks(PyObject* cb_list)
 {
-	int len;
+	Py_ssize_t len;
 
 	if (cb_list && (len=PyList_GET_SIZE(cb_list)))
 	{
@@ -1925,7 +1925,7 @@
 		PyObject* ret;
 
 		// Iterate the list and run the callbacks
-		for (int pos=0; pos < len; pos++)
+		for (Py_ssize_t pos=0; pos < len; pos++)
 		{
 			func= PyList_GET_ITEM(cb_list, pos);
 			ret= PyObject_Call(func, args, NULL);




More information about the Bf-blender-cvs mailing list