Patch #661760: Cygwin auto-import module patch

The attached patch enables shared extension
modules to build cleanly under Cygwin without
moving the static initialization of certain function
pointers (i.e., ones exported from the Python
DLL core) to a module initialization function.

Additionally, this patch fixes the modules that
have been changed in the past to accommodate
Cygwin.
diff --git a/Include/pyport.h b/Include/pyport.h
index 6a9b7e6..09fc693 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -429,7 +429,11 @@
 #		else /* Py_BUILD_CORE */
 			/* Building an extension module, or an embedded situation */
 			/* public Python functions and data are imported */
-#			define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
+			/* Under Cygwin, auto-import functions to prevent compilation */
+			/* failures similar to http://python.org/doc/FAQ.html#3.24 */
+#			if !defined(__CYGWIN__)
+#				define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
+#			endif /* !__CYGWIN__ */
 #			define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
 			/* module init functions outside the core must be exported */
 #			if defined(__cplusplus)
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
index 53130d6..83222ce 100644
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -1258,7 +1258,7 @@
     0,					/* tp_hash		*/
     0,					/* tp_call		*/
     0,					/* tp_str		*/
-    0,					/* tp_getattro		*/
+    PyObject_GenericGetAttr,		/* tp_getattro		*/
     0,					/* tp_setattro		*/
     0,					/* tp_as_buffer		*/
     Py_TPFLAGS_DEFAULT,			/* tp_flags		*/
@@ -1343,7 +1343,7 @@
     0,					/* tp_hash		*/
     0,					/* tp_call		*/
     0,					/* tp_str		*/
-    0,					/* tp_getattro		*/
+    PyObject_GenericGetAttr,		/* tp_getattro		*/
     0,					/* tp_setattro		*/
     0,					/* tp_as_buffer		*/
     Py_TPFLAGS_DEFAULT,			/* tp_flags		*/
@@ -1634,9 +1634,7 @@
     PyObject *module;
 
     LogReaderType.ob_type = &PyType_Type;
-    LogReaderType.tp_getattro = PyObject_GenericGetAttr;
     ProfilerType.ob_type = &PyType_Type;
-    ProfilerType.tp_getattro = PyObject_GenericGetAttr;
     module = Py_InitModule("_hotshot", functions);
     if (module != NULL) {
         char *s = get_version_string();
diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c
index 1b96dc8..35f10a5 100644
--- a/Modules/_randommodule.c
+++ b/Modules/_randommodule.c
@@ -486,7 +486,7 @@
 	0,				/*tp_hash*/
 	0,				/*tp_call*/
 	0,				/*tp_str*/
-	0,				/*tp_getattro*/
+	PyObject_GenericGetAttr,	/*tp_getattro*/
 	0,				/*tp_setattro*/
 	0,				/*tp_as_buffer*/
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,	/*tp_flags*/
@@ -506,9 +506,9 @@
 	0,				/*tp_descr_set*/
 	0,				/*tp_dictoffset*/
 	0,				/*tp_init*/
-	0,				/*tp_alloc*/
+	PyType_GenericAlloc,		/*tp_alloc*/
 	random_new,			/*tp_new*/
-	0,				/*tp_free*/
+	_PyObject_Del,			/*tp_free*/
 	0,				/*tp_is_gc*/
 };
 
@@ -520,9 +520,6 @@
 {
 	PyObject *m;
 
-	Random_Type.tp_getattro = PyObject_GenericGetAttr;
-	Random_Type.tp_alloc = PyType_GenericAlloc;
-	Random_Type.tp_free = _PyObject_Del;
 	if (PyType_Ready(&Random_Type) < 0)
 		return;
 	m = Py_InitModule3("_random", NULL, module_doc);
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 21d62b1..1bb2d82 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -834,7 +834,7 @@
 	0,			/*tp_hash*/
         0,                      /*tp_call*/
         (reprfunc)PyTclObject_str,        /*tp_str*/
-        0,                      /*tp_getattro*/
+        PyObject_GenericGetAttr,/*tp_getattro*/
         0,                      /*tp_setattro*/
         0,                      /*tp_as_buffer*/
         Py_TPFLAGS_DEFAULT,     /*tp_flags*/
@@ -2931,7 +2931,6 @@
 	PyDict_SetItemString(d, "TkttType", (PyObject *)&Tktt_Type);
 
 	PyTclObject_Type.ob_type = &PyType_Type;
-	PyTclObject_Type.tp_getattro = &PyObject_GenericGetAttr;
 	PyDict_SetItemString(d, "Tcl_Obj", (PyObject *)&PyTclObject_Type);
 
 #ifdef TK_AQUA
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 933eae0..03447cb 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -13,8 +13,6 @@
 #endif /* DONT_HAVE_SYS_TYPES_H */
 #endif /* !STDC_HEADERS */
 
-#define DELAYED(X)	0
-
 struct arrayobject; /* Forward */
 
 /* All possible arraydescr values are defined in the vector "descriptors"
@@ -1842,7 +1840,7 @@
 	0, 					/* tp_hash */
 	0,					/* tp_call */
 	0,					/* tp_str */
-	DELAYED(PyObject_GenericGetAttr),	/* tp_getattro */
+	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,					/* tp_setattro */
 	&array_as_buffer,			/* tp_as_buffer*/
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,  /* tp_flags */
@@ -1862,9 +1860,9 @@
 	0,					/* tp_descr_set */
 	0,					/* tp_dictoffset */
 	0,					/* tp_init */
-	DELAYED(PyType_GenericAlloc),		/* tp_alloc */
+	PyType_GenericAlloc,			/* tp_alloc */
 	array_new,				/* tp_new */
-	DELAYED(PyObject_Del),			/* tp_free */
+	PyObject_Del,				/* tp_free */
 };
 
 /* No functions in array module. */
@@ -1879,9 +1877,6 @@
 	PyObject *m;
 
 	Arraytype.ob_type = &PyType_Type;
-	Arraytype.tp_getattro = PyObject_GenericGetAttr;
-	Arraytype.tp_alloc = PyType_GenericAlloc;
-	Arraytype.tp_free = PyObject_Del;
 	m = Py_InitModule3("array", a_methods, module_doc);
 
         Py_INCREF((PyObject *)&Arraytype);
diff --git a/Modules/bz2module.c b/Modules/bz2module.c
index d0383ac..f358de7 100644
--- a/Modules/bz2module.c
+++ b/Modules/bz2module.c
@@ -1387,8 +1387,8 @@
 	0,			/*tp_hash*/
         0,                      /*tp_call*/
         0,                      /*tp_str*/
-        0,                      /*tp_getattro*/
-        0,                      /*tp_setattro*/
+        PyObject_GenericGetAttr,/*tp_getattro*/
+        PyObject_GenericSetAttr,/*tp_setattro*/
         0,                      /*tp_as_buffer*/
         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
         BZ2File__doc__,         /*tp_doc*/
@@ -1407,9 +1407,9 @@
         0,                      /*tp_descr_set*/
         0,                      /*tp_dictoffset*/
         (initproc)BZ2File_init, /*tp_init*/
-        0,                      /*tp_alloc*/
+        PyType_GenericAlloc,    /*tp_alloc*/
         0,                      /*tp_new*/
-      	0,                      /*tp_free*/
+      	_PyObject_Del,          /*tp_free*/
         0,                      /*tp_is_gc*/
 };
 
@@ -1652,8 +1652,8 @@
 	0,			/*tp_hash*/
         0,                      /*tp_call*/
         0,                      /*tp_str*/
-        0,                      /*tp_getattro*/
-        0,                      /*tp_setattro*/
+        PyObject_GenericGetAttr,/*tp_getattro*/
+        PyObject_GenericSetAttr,/*tp_setattro*/
         0,                      /*tp_as_buffer*/
         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
         BZ2Comp__doc__,         /*tp_doc*/
@@ -1672,9 +1672,9 @@
         0,                      /*tp_descr_set*/
         0,                      /*tp_dictoffset*/
         (initproc)BZ2Comp_init, /*tp_init*/
-        0,                      /*tp_alloc*/
-        0,                      /*tp_new*/
-      	0,                      /*tp_free*/
+        PyType_GenericAlloc,    /*tp_alloc*/
+        PyType_GenericNew,      /*tp_new*/
+      	_PyObject_Del,          /*tp_free*/
         0,                      /*tp_is_gc*/
 };
 
@@ -1869,8 +1869,8 @@
 	0,			/*tp_hash*/
         0,                      /*tp_call*/
         0,                      /*tp_str*/
-        0,                      /*tp_getattro*/
-        0,                      /*tp_setattro*/
+        PyObject_GenericGetAttr,/*tp_getattro*/
+        PyObject_GenericSetAttr,/*tp_setattro*/
         0,                      /*tp_as_buffer*/
         Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, /*tp_flags*/
         BZ2Decomp__doc__,       /*tp_doc*/
@@ -1889,9 +1889,9 @@
         0,                      /*tp_descr_set*/
         0,                      /*tp_dictoffset*/
         (initproc)BZ2Decomp_init, /*tp_init*/
-        0,                      /*tp_alloc*/
-        0,                      /*tp_new*/
-      	0,                      /*tp_free*/
+        PyType_GenericAlloc,    /*tp_alloc*/
+        PyType_GenericNew,      /*tp_new*/
+      	_PyObject_Del,          /*tp_free*/
         0,                      /*tp_is_gc*/
 };
 
@@ -2089,24 +2089,9 @@
 	BZ2File_Type.ob_type = &PyType_Type;
 	BZ2File_Type.tp_base = &PyFile_Type;
 	BZ2File_Type.tp_new = PyFile_Type.tp_new;
-	BZ2File_Type.tp_getattro = PyObject_GenericGetAttr;
-	BZ2File_Type.tp_setattro = PyObject_GenericSetAttr;
-	BZ2File_Type.tp_alloc = PyType_GenericAlloc;
-	BZ2File_Type.tp_free = _PyObject_Del;
 
 	BZ2Comp_Type.ob_type = &PyType_Type;
-	BZ2Comp_Type.tp_getattro = PyObject_GenericGetAttr;
-	BZ2Comp_Type.tp_setattro = PyObject_GenericSetAttr;
-	BZ2Comp_Type.tp_alloc = PyType_GenericAlloc;
-	BZ2Comp_Type.tp_new = PyType_GenericNew;
-	BZ2Comp_Type.tp_free = _PyObject_Del;
-
 	BZ2Decomp_Type.ob_type = &PyType_Type;
-	BZ2Decomp_Type.tp_getattro = PyObject_GenericGetAttr;
-	BZ2Decomp_Type.tp_setattro = PyObject_GenericSetAttr;
-	BZ2Decomp_Type.tp_alloc = PyType_GenericAlloc;
-	BZ2Decomp_Type.tp_new = PyType_GenericNew;
-	BZ2Decomp_Type.tp_free = _PyObject_Del;
 
 	m = Py_InitModule3("bz2", bz2_methods, bz2__doc__);
 
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 9412ad9..24a9f13 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -2543,8 +2543,8 @@
     0,					/* tp_hash */
     0,					/* tp_call */
     0,					/* tp_str */
-    0,	/* set below */			/* tp_getattro */
-    0,	/* set below */			/* tp_setattro */
+    PyObject_GenericGetAttr,		/* tp_getattro */
+    PyObject_GenericSetAttr,		/* tp_setattro */
     0,					/* tp_as_buffer */
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
     Picklertype__doc__,			/* tp_doc */
@@ -4808,8 +4808,6 @@
 	PyObject *compatible_formats;
 
 	Picklertype.ob_type = &PyType_Type;
-	Picklertype.tp_getattro = PyObject_GenericGetAttr;
-	Picklertype.tp_setattro = PyObject_GenericSetAttr;
 	Unpicklertype.ob_type = &PyType_Type;
 	PdataType.ob_type = &PyType_Type;
 
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 1bbd941..2b0b796 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2115,7 +2115,7 @@
 	0,					/* tp_hash */
 	0,					/* tp_call */
 	0,					/* tp_str */
-	0,	/* set below */			/* tp_getattro */
+	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
@@ -2135,9 +2135,9 @@
 	0,					/* tp_descr_set */
 	0,					/* tp_dictoffset */
 	sock_initobj,				/* tp_init */
-	0,	/* set below */			/* tp_alloc */
+	PyType_GenericAlloc,			/* tp_alloc */
 	sock_new,				/* tp_new */
-	0,	/* set below */			/* tp_free */
+	PyObject_Del,				/* tp_free */
 };
 
 
@@ -3147,9 +3147,6 @@
 		return;
 
 	sock_type.ob_type = &PyType_Type;
-	sock_type.tp_getattro = PyObject_GenericGetAttr;
-	sock_type.tp_alloc = PyType_GenericAlloc;
-	sock_type.tp_free = PyObject_Del;
 	m = Py_InitModule3(PySocket_MODULE_NAME,
 			   socket_methods,
 			   socket_doc);