[Zodb-checkins] CVS: Zope3/src/zope/interface - _zope_interface_ospec.c:1.8

Jeremy Hylton jeremy at zope.com
Sat Jun 21 18:52:08 EDT 2003


Update of /cvs-repository/Zope3/src/zope/interface
In directory cvs.zope.org:/tmp/cvs-serv7873/src/zope/interface

Modified Files:
	_zope_interface_ospec.c 
Log Message:
Rearrange imports and definitions to avoid circular import problem.

Puzzling case.  I only see the failures on Windows, but looking at the code I don't see how it ever works.  Regardless, the changes allow things to work on Windows and all the tests pass.


=== Zope3/src/zope/interface/_zope_interface_ospec.c 1.7 => 1.8 ===
--- Zope3/src/zope/interface/_zope_interface_ospec.c:1.7	Mon Jun  2 07:07:41 2003
+++ Zope3/src/zope/interface/_zope_interface_ospec.c	Sat Jun 21 17:52:08 2003
@@ -601,88 +601,97 @@
         /* tp_descr_get      */ (descrgetfunc)OSpecDescr_descr_get,
 };
 
-static struct PyMethodDef module_methods[] = {
-	{"getObjectSpecification",  (PyCFunction)getObjectSpecification,
-         METH_O, "internal function to compute an object spec"},
-	{"providedBy",  (PyCFunction)providedBy, METH_O, 
-         "Return a specification for the interfaces of an object"},
-	{NULL,	 (PyCFunction)NULL, 0, NULL}		/* sentinel */
-};
-
-
-static char _zope_interface_ospec_module_documentation[] = 
-"C implementation of parts of zope.interface.declarations"
-;
-
-#ifndef PyMODINIT_FUNC	/* declarations for DLL import/export */
-#define PyMODINIT_FUNC void
-#endif
-PyMODINIT_FUNC
-init_zope_interface_ospec(void)
+int
+init_globals(void)
 {
-  PyObject *module;
-
   str___implements__ = PyString_FromString("__implements__");
   if (str___implements__ == NULL)
-    return;
+    return -1;
   
   str___provides__ = PyString_FromString("__provides__");
   if (str___provides__ == NULL)
-    return;
+    return -1;
   
   str___providedBy__ = PyString_FromString("__providedBy__");
   if (str___providedBy__ == NULL)
-    return;
+    return -1;
   
   str___class__ = PyString_FromString("__class__");
   if (str___class__ == NULL)
-    return;
+    return -1;
   
   str___dict__ = PyString_FromString("__dict__");
   if (str___dict__ == NULL)
-    return;
+    return -1;
   
   str___signature__ = PyString_FromString("__signature__");
   if (str___signature__ == NULL)
-    return;
+    return -1;
   
   str_flattened = PyString_FromString("flattened");
   if (str_flattened == NULL)
-    return;
+    return -1;
   
   str_extends = PyString_FromString("extends");
   if (str_extends == NULL)
-    return;
+    return -1;
   
   str_only = PyString_FromString("only");
   if (str_only == NULL)
-    return;
+    return -1;
   
   _implements_reg = PyDict_New();
   if (_implements_reg == NULL)
-    return;
+    return -1;
+
+  return 0;
+}
 
+int
+init_declarations(void)
+{
   declarations = PyImport_ImportModule("zope.interface.declarations");
-  if (declarations == NULL) 
-    return;
+  if (declarations == NULL)
+    return -1;
 
   classImplements = PyObject_GetAttrString(declarations, "classImplements");
   if (classImplements == NULL)
-    return;
+    return -1;
 
   proxySig = PyObject_GetAttrString(declarations, "proxySig");
   if (proxySig == NULL)
-    return;
+    return -1;
 
   oldSpecSig = PyObject_GetAttrString(declarations, "oldSpecSig");
   if (oldSpecSig == NULL)
-    return;
+    return -1;
 
   combinedSpec = PyObject_GetAttrString(declarations, "combinedSpec");
   if (combinedSpec == NULL)
-    return;
- 
-  
+    return -1;
+  return 0;
+}
+
+static struct PyMethodDef module_methods[] = {
+	{"getObjectSpecification",  (PyCFunction)getObjectSpecification,
+         METH_O, "internal function to compute an object spec"},
+	{"providedBy",  (PyCFunction)providedBy, METH_O, 
+         "Return a specification for the interfaces of an object"},
+	{NULL,	 (PyCFunction)NULL, 0, NULL}		/* sentinel */
+};
+
+static char _zope_interface_ospec_module_documentation[] = 
+"C implementation of parts of zope.interface.declarations"
+;
+
+#ifndef PyMODINIT_FUNC	/* declarations for DLL import/export */
+#define PyMODINIT_FUNC void
+#endif
+PyMODINIT_FUNC
+init_zope_interface_ospec(void)
+{
+  PyObject *module;
+
   /* Initialize types: */  
 
   ISBType.tp_new = PyType_GenericNew;
@@ -701,28 +710,40 @@
 
  
   OSpecDescrType.tp_new = PyType_GenericNew;
-    if (PyType_Ready(&OSpecDescrType) < 0)
+  if (PyType_Ready(&OSpecDescrType) < 0)
     return;
 
-
+  if (init_globals() < 0)
+    return;
+  
   /* Create the module and add the functions */
   module = Py_InitModule3("_zope_interface_ospec", module_methods,
                           _zope_interface_ospec_module_documentation);
   
   if (module == NULL)
     return;
-  
+
   /* Add types: */
   if (PyModule_AddObject(module, "InterfaceSpecificationBase", 
                          (PyObject *)&ISBType) < 0)
     return;
+
   if (PyModule_AddObject(module, "ObjectSpecification", 
                          (PyObject *)&OSpecType) < 0)
     return;
+
   if (PyModule_AddObject(module, "ObjectSpecificationDescriptor", 
                          (PyObject *)&OSpecDescrType) < 0)
     return;
+
   if (PyModule_AddObject(module, "_implements_reg", _implements_reg) < 0)
     return;
+
+  /* init_declarations() loads objects from zope.interface.declarations,
+     which circularly depends on the objects defined in this module.
+     Call init_declarations() last to ensure that the necessary names
+     are bound.
+  */
+  init_declarations();
 }
 




More information about the Zodb-checkins mailing list