[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32764] trunk/blender: use PyImport_ExtendInittab for py module initialization rather then adding to sys .modules directly, no functional change.

Campbell Barton ideasman42 at gmail.com
Sat Oct 30 00:59:39 CEST 2010


Revision: 32764
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32764
Author:   campbellbarton
Date:     2010-10-30 00:59:39 +0200 (Sat, 30 Oct 2010)

Log Message:
-----------
use PyImport_ExtendInittab for py module initialization rather then adding to sys.modules directly, no functional change.

Modified Paths:
--------------
    trunk/blender/intern/audaspace/intern/AUD_C-API.cpp
    trunk/blender/source/blender/python/generic/bgl.c
    trunk/blender/source/blender/python/generic/bgl.h
    trunk/blender/source/blender/python/generic/blf_api.c
    trunk/blender/source/blender/python/generic/blf_api.h
    trunk/blender/source/blender/python/generic/mathutils.c
    trunk/blender/source/blender/python/generic/mathutils.h
    trunk/blender/source/blender/python/generic/mathutils_geometry.c
    trunk/blender/source/blender/python/generic/mathutils_geometry.h
    trunk/blender/source/blender/python/generic/noise.c
    trunk/blender/source/blender/python/intern/bpy.c
    trunk/blender/source/blender/python/intern/bpy_interface.c
    trunk/blender/source/blender/python/intern/bpy_operator.c

Modified: trunk/blender/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- trunk/blender/intern/audaspace/intern/AUD_C-API.cpp	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/intern/audaspace/intern/AUD_C-API.cpp	2010-10-29 22:59:39 UTC (rev 32764)
@@ -197,7 +197,7 @@
 {
 	PyObject* module = PyInit_aud();
 	PyModule_AddObject(module, "device", (PyObject *)PyCFunction_New(meth_getcdevice, NULL));
-	PyDict_SetItemString(PySys_GetObject("modules"), "aud", module);
+	PyDict_SetItemString(PyImport_GetModuleDict(), "aud", module);
 	if(AUD_device)
 	{
 		g_device = (Device*)Device_empty();

Modified: trunk/blender/source/blender/python/generic/bgl.c
===================================================================
--- trunk/blender/source/blender/python/generic/bgl.c	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/generic/bgl.c	2010-10-29 22:59:39 UTC (rev 32764)
@@ -1115,12 +1115,11 @@
 };
 
 
-PyObject *BGL_Init(void)
+PyObject *BPyInit_bgl(void)
 {
-	PyObject *mod, *dict, *item;
-	mod = PyModule_Create(&BGL_module_def);
-	PyDict_SetItemString(PyImport_GetModuleDict(), BGL_module_def.m_name, mod);
-	dict= PyModule_GetDict(mod);
+	PyObject *submodule, *dict, *item;
+	submodule= PyModule_Create(&BGL_module_def);
+	dict= PyModule_GetDict(submodule);
 	
 	if( PyType_Ready( &BGL_bufferType) < 0)
 		return NULL; /* should never happen */
@@ -1612,6 +1611,6 @@
 	EXPP_ADDCONST(GL_TEXTURE_BINDING_1D);
 	EXPP_ADDCONST(GL_TEXTURE_BINDING_2D);
       
-	return mod;
+	return submodule;
 }
 

Modified: trunk/blender/source/blender/python/generic/bgl.h
===================================================================
--- trunk/blender/source/blender/python/generic/bgl.h	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/generic/bgl.h	2010-10-29 22:59:39 UTC (rev 32764)
@@ -38,7 +38,7 @@
 
 #include <Python.h>
 
-PyObject *BGL_Init(void);
+PyObject *BPyInit_bgl(void);
 
 /*@ Create a buffer object */
 /*@ dimensions is an array of ndimensions integers representing the size of each dimension */

Modified: trunk/blender/source/blender/python/generic/blf_api.c
===================================================================
--- trunk/blender/source/blender/python/generic/blf_api.c	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/generic/blf_api.c	2010-10-29 22:59:39 UTC (rev 32764)
@@ -390,17 +390,16 @@
 	0,  /* m_free */
 };
 
-PyObject *BLF_Init(void)
+PyObject *BPyInit_blf(void)
 {
 	PyObject *submodule;
 
 	submodule = PyModule_Create(&BLF_module_def);
-	PyDict_SetItemString(PyImport_GetModuleDict(), BLF_module_def.m_name, submodule);
 
 	PyModule_AddIntConstant(submodule, "ROTATION", BLF_ROTATION);
 	PyModule_AddIntConstant(submodule, "CLIPPING", BLF_CLIPPING);
 	PyModule_AddIntConstant(submodule, "SHADOW", BLF_SHADOW);
 	PyModule_AddIntConstant(submodule, "KERNING_DEFAULT", BLF_KERNING_DEFAULT);
 
-	return (submodule);
+	return submodule;
 }

Modified: trunk/blender/source/blender/python/generic/blf_api.h
===================================================================
--- trunk/blender/source/blender/python/generic/blf_api.h	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/generic/blf_api.h	2010-10-29 22:59:39 UTC (rev 32764)
@@ -22,5 +22,4 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
-
-PyObject *BLF_Init(void);
+PyObject *BPyInit_blf(void);

Modified: trunk/blender/source/blender/python/generic/mathutils.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils.c	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/generic/mathutils.c	2010-10-29 22:59:39 UTC (rev 32764)
@@ -245,12 +245,10 @@
 	0,  /* m_free */
 };
 
-PyObject *Mathutils_Init(void)
+PyMODINIT_FUNC BPyInit_mathutils(void)
 {
 	PyObject *submodule;
-	
-	
-	
+
 	if( PyType_Ready( &vector_Type ) < 0 )
 		return NULL;
 	if( PyType_Ready( &matrix_Type ) < 0 )
@@ -263,7 +261,6 @@
 		return NULL;
 
 	submodule = PyModule_Create(&M_Mathutils_module_def);
-	PyDict_SetItemString(PyImport_GetModuleDict(), M_Mathutils_module_def.m_name, submodule);
 	
 	/* each type has its own new() function */
 	PyModule_AddObject( submodule, "Vector",		(PyObject *)&vector_Type );
@@ -273,9 +270,9 @@
 	PyModule_AddObject( submodule, "Color",			(PyObject *)&color_Type );
 	
 	/* submodule */
-	PyModule_AddObject( submodule, "geometry",			Geometry_Init());
+	PyModule_AddObject( submodule, "geometry",		BPyInit_mathutils_geometry());
 	
 	mathutils_matrix_vector_cb_index= Mathutils_RegisterCallback(&mathutils_matrix_vector_cb);
 
-	return (submodule);
+	return submodule;
 }

Modified: trunk/blender/source/blender/python/generic/mathutils.h
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils.h	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/generic/mathutils.h	2010-10-29 22:59:39 UTC (rev 32764)
@@ -61,8 +61,7 @@
 PyObject *BaseMathObject_getWrapped( BaseMathObject *self, void * );
 void BaseMathObject_dealloc(BaseMathObject * self);
 
-PyObject *Mathutils_Init(void);
-PyObject *Noise_Init(void); /* lazy, saves having own header */
+PyMODINIT_FUNC BPyInit_mathutils(void);
 
 int EXPP_FloatsAreEqual(float A, float B, int floatSteps);
 int EXPP_VectorsAreEqual(float *vecA, float *vecB, int size, int floatSteps);

Modified: trunk/blender/source/blender/python/generic/mathutils_geometry.c
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_geometry.c	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/generic/mathutils_geometry.c	2010-10-29 22:59:39 UTC (rev 32764)
@@ -830,12 +830,8 @@
 };
 
 /*----------------------------MODULE INIT-------------------------*/
-PyObject *Geometry_Init(void)
+PyMODINIT_FUNC BPyInit_mathutils_geometry(void)
 {
-	PyObject *submodule;
-
-	submodule = PyModule_Create(&M_Geometry_module_def);
-	PyDict_SetItemString(PyImport_GetModuleDict(), M_Geometry_module_def.m_name, submodule);
-
-	return (submodule);
+	PyObject *submodule= PyModule_Create(&M_Geometry_module_def);
+	return submodule;
 }

Modified: trunk/blender/source/blender/python/generic/mathutils_geometry.h
===================================================================
--- trunk/blender/source/blender/python/generic/mathutils_geometry.h	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/generic/mathutils_geometry.h	2010-10-29 22:59:39 UTC (rev 32764)
@@ -34,6 +34,6 @@
 #include <Python.h>
 #include "mathutils.h"
 
-PyObject *Geometry_Init(void);
+PyMODINIT_FUNC BPyInit_mathutils_geometry(void);
 
 #endif				/* EXPP_Geometry_H */

Modified: trunk/blender/source/blender/python/generic/noise.c
===================================================================
--- trunk/blender/source/blender/python/generic/noise.c	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/generic/noise.c	2010-10-29 22:59:39 UTC (rev 32764)
@@ -122,8 +122,6 @@
 static int initf = 0;
 static unsigned long *next;
 
-PyObject *Noise_Init(void);
-
 /* initializes state[N] with a seed */
 static void init_genrand(unsigned long s)
 {
@@ -657,10 +655,9 @@
 	0,  /* m_free */
 };
 
-PyObject *Noise_Init(void)
+PyObject *BPyInit_noise(void)
 {
 	PyObject *submodule = PyModule_Create(&noise_module_def);
-	PyDict_SetItemString(PyImport_GetModuleDict(), noise_module_def.m_name, submodule);
 
 	/* use current time as seed for random number generator by default */
 	setRndSeed(0);	

Modified: trunk/blender/source/blender/python/intern/bpy.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy.c	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/intern/bpy.c	2010-10-29 22:59:39 UTC (rev 32764)
@@ -195,12 +195,7 @@
 		printf("bpy: couldnt find 'scripts/modules', blender probably wont start.\n");
 	}
 	/* stand alone utility modules not related to blender directly */
-	Mathutils_Init();
-	Noise_Init();
-	BGL_Init();
-	BLF_Init();
-	IDProp_Init_Types();
-	AUD_initPython();
+	IDProp_Init_Types(); /* not actually a submodule, just types */
 
 	mod = PyModule_New("_bpy");
 

Modified: trunk/blender/source/blender/python/intern/bpy_interface.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_interface.c	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/intern/bpy_interface.c	2010-10-29 22:59:39 UTC (rev 32764)
@@ -196,6 +196,22 @@
 	BPy_SetContext(C);
 }
 
+/* init-tab */
+extern PyObject *BPyInit_noise(void);
+extern PyObject *BPyInit_mathutils(void);
+extern PyObject *BPyInit_bgl(void);
+extern PyObject *BPyInit_blf(void);
+extern PyObject *AUD_initPython(void);
+
+static struct _inittab bpy_internal_modules[]= {
+	{"noise", BPyInit_noise},
+	{"mathutils", BPyInit_mathutils},
+	{"bgl", BPyInit_bgl},
+	{"blf", BPyInit_blf},
+	{"aud", AUD_initPython},
+	{NULL, NULL}
+};
+
 /* call BPY_set_context first */
 void BPY_start_python( int argc, char **argv )
 {
@@ -206,6 +222,9 @@
 	utf8towchar(bprogname_wchar, bprogname);
 	Py_SetProgramName(bprogname_wchar);
 
+	/* builtin modules */
+	PyImport_ExtendInittab(bpy_internal_modules);
+
 	BPY_start_python_path(); /* allow to use our own included python */
 
 	Py_Initialize(  );

Modified: trunk/blender/source/blender/python/intern/bpy_operator.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_operator.c	2010-10-29 19:40:45 UTC (rev 32763)
+++ trunk/blender/source/blender/python/intern/bpy_operator.c	2010-10-29 22:59:39 UTC (rev 32764)
@@ -313,14 +313,8 @@
 PyObject *BPY_operator_module(void)
 {
 	PyObject *submodule;
-	
+
 	submodule= PyModule_Create(&bpy_ops_module);
-	PyDict_SetItemString(PyImport_GetModuleDict(), bpy_ops_module.m_name, submodule);
 
-	/* INCREF since its its assumed that all these functions return the
-	 * module with a new ref like PyDict_New, since they are passed to
-	  * PyModule_AddObject which steals a ref */
-	Py_INCREF(submodule);
-
 	return submodule;
 }





More information about the Bf-blender-cvs mailing list