Author: Armin Rigo <ar...@tunes.org>
Branch: 
Changeset: r2294:e312e28ae4b2
Date: 2015-09-30 17:06 +0200
http://bitbucket.org/cffi/cffi/changeset/e312e28ae4b2/

Log:    More attempts at fixes for multiple interpreters

diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -6289,6 +6289,7 @@
 {
     PyObject *m, *v;
     int i;
+    static char init_done = 0;
 
     v = PySys_GetObject("version");
     if (v == NULL || !PyText_Check(v) ||
@@ -6331,14 +6332,17 @@
     if (PyType_Ready(&MiniBuffer_Type) < 0)
         INITERROR;
 
-    v = PyText_FromString("_cffi_backend");
-    if (v == NULL || PyDict_SetItemString(CData_Type.tp_dict,
-                                          "__module__", v) < 0)
-        INITERROR;
-    v = PyText_FromString("<cdata>");
-    if (v == NULL || PyDict_SetItemString(CData_Type.tp_dict,
-                                          "__name__", v) < 0)
-        INITERROR;
+    if (!init_done) {
+        v = PyText_FromString("_cffi_backend");
+        if (v == NULL || PyDict_SetItemString(CData_Type.tp_dict,
+                                              "__module__", v) < 0)
+            INITERROR;
+        v = PyText_FromString("<cdata>");
+        if (v == NULL || PyDict_SetItemString(CData_Type.tp_dict,
+                                              "__name__", v) < 0)
+            INITERROR;
+        init_done = 1;
+    }
 
     /* this is for backward compatibility only */
     v = PyCapsule_New((void *)cffi_exports, "cffi", NULL);
@@ -6377,6 +6381,8 @@
     }
 
     init_errno();
+    if (PyErr_Occurred())
+        INITERROR;
 
     if (init_ffi_lib(m) < 0)
         INITERROR;
diff --git a/c/cffi1_module.c b/c/cffi1_module.c
--- a/c/cffi1_module.c
+++ b/c/cffi1_module.c
@@ -21,7 +21,7 @@
 {
     PyObject *x;
     int i;
-    static int init_done = 0;
+    static char init_done = 0;
 
     if (PyType_Ready(&FFI_Type) < 0)
         return -1;
diff --git a/c/file_emulator.h b/c/file_emulator.h
--- a/c/file_emulator.h
+++ b/c/file_emulator.h
@@ -5,12 +5,14 @@
 
 static int init_file_emulator(void)
 {
-    PyObject *io = PyImport_ImportModule("_io");
-    if (io == NULL)
-        return -1;
-    PyIOBase_TypeObj = PyObject_GetAttrString(io, "_IOBase");
-    if (PyIOBase_TypeObj == NULL)
-        return -1;
+    if (PyIOBase_TypeObj == NULL) {
+        PyObject *io = PyImport_ImportModule("_io");
+        if (io == NULL)
+            return -1;
+        PyIOBase_TypeObj = PyObject_GetAttrString(io, "_IOBase");
+        if (PyIOBase_TypeObj == NULL)
+            return -1;
+    }
     return 0;
 }
 
diff --git a/c/misc_win32.h b/c/misc_win32.h
--- a/c/misc_win32.h
+++ b/c/misc_win32.h
@@ -8,13 +8,15 @@
     int saved_lasterror;
 };
 
-static DWORD cffi_tls_index;
+static DWORD cffi_tls_index = TLS_OUT_OF_INDEXES;
 
 static void init_errno(void)
 {
-    cffi_tls_index = TlsAlloc();
-    if (cffi_tls_index == TLS_OUT_OF_INDEXES)
-        PyErr_SetString(PyExc_WindowsError, "TlsAlloc() failed");
+    if (cffi_tls_index == TLS_OUT_OF_INDEXES) {
+        cffi_tls_index = TlsAlloc();
+        if (cffi_tls_index == TLS_OUT_OF_INDEXES)
+            PyErr_SetString(PyExc_WindowsError, "TlsAlloc() failed");
+    }
 }
 
 static struct cffi_errno_s *_geterrno_object(void)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to