[Python-checkins] CVS: python/dist/src/Modules xxsubtype.c,2.9,2.10

Tim Peters tim_one@users.sourceforge.net
Sun, 16 Dec 2001 17:27:03 -0800


Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv31430/python/Modules

Modified Files:
	xxsubtype.c 
Log Message:
David Abrahams tried to compile this as a separate DLL under MSVC, and
got a barrage of compile errors that didn't make sense to the C++ brain:
MSVC does not allow C (but does allow C++) initializers to contain
data addresses supplied by other DLLs.  So changed the initializers here
to use dummy nulls, and changed module init to plug in the foreign
addresses at runtime (manually simulating what C++ does by magic).  Tested
on Windows, and Guido tested on Linux (thanks!).  BTW, the *point* is that
people are going to use this module as a template for writing their own
subtypes, and it's unusual for extension authors to build their extensions
into Python directly (separate DLLs are the norm on Windows); so it's
better if we give them a template that works <wink>.


Index: xxsubtype.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/xxsubtype.c,v
retrieving revision 2.9
retrieving revision 2.10
diff -C2 -d -r2.9 -r2.10
*** xxsubtype.c	2001/12/10 22:53:30	2.9
--- xxsubtype.c	2001/12/17 01:27:01	2.10
***************
*** 8,11 ****
--- 8,20 ----
  "test suite, you can recompile Python without Modules/xxsubtype.c.";
  
+ /* We link this module statically for convenience.  If compiled as a shared
+    library instead, some compilers don't allow addresses of Python objects
+    defined in other libraries to be used in static initializers here.  The
+    DEFERRED_ADDRESS macro is used to tag the slots where such addresses
+    appear; the module init function must fill in the tagged slots at runtime.
+    The argument is for documentation -- the macro ignores it.
+ */
+ #define DEFERRED_ADDRESS(ADDR) 0
+ 
  /* spamlist -- a list subtype */
  
***************
*** 67,71 ****
  
  static PyTypeObject spamlist_type = {
! 	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"xxsubtype.spamlist",
--- 76,80 ----
  
  static PyTypeObject spamlist_type = {
! 	PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
  	0,
  	"xxsubtype.spamlist",
***************
*** 98,102 ****
  	0,					/* tp_members */
  	spamlist_getsets,			/* tp_getset */
! 	&PyList_Type,				/* tp_base */
  	0,					/* tp_dict */
  	0,					/* tp_descr_get */
--- 107,111 ----
  	0,					/* tp_members */
  	spamlist_getsets,			/* tp_getset */
! 	DEFERRED_ADDRESS(&PyList_Type),		/* tp_base */
  	0,					/* tp_dict */
  	0,					/* tp_descr_get */
***************
*** 161,165 ****
  
  static PyTypeObject spamdict_type = {
! 	PyObject_HEAD_INIT(&PyType_Type)
  	0,
  	"xxsubtype.spamdict",
--- 170,174 ----
  
  static PyTypeObject spamdict_type = {
! 	PyObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type))
  	0,
  	"xxsubtype.spamdict",
***************
*** 192,196 ****
  	spamdict_members,			/* tp_members */
  	0,					/* tp_getset */
! 	&PyDict_Type,				/* tp_base */
  	0,					/* tp_dict */
  	0,					/* tp_descr_get */
--- 201,205 ----
  	spamdict_members,			/* tp_members */
  	0,					/* tp_getset */
! 	DEFERRED_ADDRESS(&PyDict_Type),		/* tp_base */
  	0,					/* tp_dict */
  	0,					/* tp_descr_get */
***************
*** 231,234 ****
--- 240,251 ----
  {
  	PyObject *m, *d;
+ 
+ 	/* Fill in the deferred data addresses.  This must be done before
+ 	   PyType_Ready() is called. */
+ 	spamdict_type.ob_type = &PyType_Type;
+ 	spamdict_type.tp_base = &PyDict_Type;
+ 
+ 	spamlist_type.ob_type = &PyType_Type;
+ 	spamlist_type.tp_base = &PyList_Type;
  
  	m = Py_InitModule3("xxsubtype",