Author: Armin Rigo <ar...@tunes.org> Branch: static-callback-embedding Changeset: r2501:c3084bd75943 Date: 2015-12-30 22:36 +0100 http://bitbucket.org/cffi/cffi/changeset/c3084bd75943/
Log: more tweaks; tests needed... diff --git a/cffi/_embedding.h b/cffi/_embedding.h --- a/cffi/_embedding.h +++ b/cffi/_embedding.h @@ -195,8 +195,9 @@ f = PySys_GetObject((char *)"stderr"); if (f != NULL && f != Py_None) { - PyFile_WriteString("\ncffi version: 1.3.1", f); - PyFile_WriteString("\n_cffi_backend module: ", f); + PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME + "\ncompiled with cffi version: 1.4.2" + "\n_cffi_backend module: ", f); modules = PyImport_GetModuleDict(); mod = PyDict_GetItemString(modules, "_cffi_backend"); if (mod == NULL) { @@ -218,7 +219,7 @@ PyAPI_DATA(char *) _PyParser_TokenNames[]; /* from CPython */ -static void _cffi_carefully_make_gil(void) +static int _cffi_carefully_make_gil(void) { /* This initializes the GIL. It can be called completely concurrently from unrelated threads. It assumes that we don't @@ -267,6 +268,7 @@ while (!cffi_compare_and_swap(lock, old_value + 1, old_value)) ; #endif + return 0; } /********** end CPython-specific section **********/ @@ -289,10 +291,12 @@ _CFFI_PYTHON_STARTUP_CODE, }; +extern int pypy_carefully_make_gil(const char *); extern int pypy_init_embedded_cffi_module(int, struct _cffi_pypy_init_s *); -static void _cffi_carefully_make_gil(void) +static int _cffi_carefully_make_gil(void) { + return pypy_carefully_make_gil(_CFFI_MODULE_NAME); } static int _cffi_initialize_python(void) @@ -345,14 +349,16 @@ */ static char called = 0; - _cffi_carefully_make_gil(); + if (_cffi_carefully_make_gil() != 0) + return NULL; + _cffi_acquire_reentrant_mutex(); /* Here the GIL exists, but we don't have it. We're only protected from concurrency by the reentrant mutex. */ - /* This file ignores subinterpreters and can only initialize the - embedded module once, in the main interpreter. */ + /* This file only initializes the embedded module once, the first + time this is called, even if there are subinterpreters. */ if (!called) { called = 1; /* invoke _cffi_initialize_python() only once, but don't set '_cffi_call_python' right now, @@ -365,13 +371,13 @@ '_cffi_call_python' without also seeing the rest of the data initialized. However, this is not possible. But the new value of '_cffi_call_python' is the function - 'cffi_call_python()' from _cffi_backend. We can put a - write barrier here, and a corresponding read barrier at - the start of cffi_call_python(). This ensures that - after that read barrier, we see everything done here - before the write barrier. + 'cffi_call_python()' from _cffi_backend. So: */ + cffi_write_barrier(); + /* ^^^ we put a write barrier here, and a corresponding + read barrier at the start of cffi_call_python(). This + ensures that after that read barrier, we see everything + done here before the write barrier. */ - cffi_write_barrier(); assert(_cffi_call_python_org != NULL); _cffi_call_python = (_cffi_call_python_fnptr)_cffi_call_python_org; diff --git a/testing/cffi0/test_version.py b/testing/cffi0/test_version.py --- a/testing/cffi0/test_version.py +++ b/testing/cffi0/test_version.py @@ -53,3 +53,10 @@ content = open(p).read() #v = BACKEND_VERSIONS.get(v, v) assert (('assert __version__ == "%s"' % v) in content) + +def test_embedding_h(): + parent = os.path.dirname(os.path.dirname(cffi.__file__)) + v = cffi.__version__ + p = os.path.join(parent, 'cffi', '_embedding.h') + content = open(p).read() + assert ('cffi version: %s"' % (v,)) in content _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit