diff options
author | Armin Rigo <arigo@tunes.org> | 2015-12-07 18:19:00 +0100 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2015-12-07 18:19:00 +0100 |
commit | f470f443a621025b589a2b15df6729aff199e537 (patch) | |
tree | e3cb9a3fa9c9d82fd26b33669a4672a2f8f8e691 /c | |
parent | 82ced8ccd0bc33ef60449cdce989c3308abe7757 (diff) | |
download | cffi-f470f443a621025b589a2b15df6729aff199e537.tar.gz |
py3k compat
Diffstat (limited to 'c')
-rw-r--r-- | c/call_python.c | 5 | ||||
-rw-r--r-- | c/misc_thread_posix.h | 13 | ||||
-rw-r--r-- | c/misc_win32.h | 2 |
3 files changed, 13 insertions, 7 deletions
diff --git a/c/call_python.c b/c/call_python.c index 4fd60c1..b6cfa82 100644 --- a/c/call_python.c +++ b/c/call_python.c @@ -24,9 +24,6 @@ static PyObject *_get_interpstate_dict(void) static PyObject *_ffi_def_extern_decorator(PyObject *outer_args, PyObject *fn) { -#if PY_MAJOR_VERSION >= 3 -# error review! -#endif char *s; PyObject *error, *onerror, *infotuple, *old1; int index, err; @@ -46,7 +43,7 @@ static PyObject *_ffi_def_extern_decorator(PyObject *outer_args, PyObject *fn) name = PyObject_GetAttrString(fn, "__name__"); if (name == NULL) return NULL; - s = PyString_AsString(name); + s = PyText_AsUTF8(name); if (s == NULL) { Py_DECREF(name); return NULL; diff --git a/c/misc_thread_posix.h b/c/misc_thread_posix.h index 1e74682..adf7f25 100644 --- a/c/misc_thread_posix.h +++ b/c/misc_thread_posix.h @@ -100,6 +100,15 @@ static void restore_errno(void) #endif +static PyThreadState *get_current_ts(void) +{ +#if PY_MAJOR_VERSION >= 3 + return (PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current); +#else + return _PyThreadState_Current; +#endif +} + static PyGILState_STATE gil_ensure(void) { /* Called at the start of a callback. Replacement for @@ -111,7 +120,7 @@ static PyGILState_STATE gil_ensure(void) if (ts != NULL) { ts->gilstate_counter++; - if (ts != _PyThreadState_Current) { + if (ts != get_current_ts()) { /* common case: 'ts' is our non-current thread state and we have to make it current and acquire the GIL */ PyEval_RestoreThread(ts); @@ -128,7 +137,7 @@ static PyGILState_STATE gil_ensure(void) ts = PyGILState_GetThisThreadState(); assert(ts != NULL); - assert(ts == _PyThreadState_Current); + assert(ts == get_current_ts()); assert(ts->gilstate_counter >= 1); /* Save the now-current thread state inside our 'local_thread_state' diff --git a/c/misc_win32.h b/c/misc_win32.h index d6e46e3..9d17252 100644 --- a/c/misc_win32.h +++ b/c/misc_win32.h @@ -10,7 +10,7 @@ struct cffi_errno_s { static DWORD cffi_tls_index = TLS_OUT_OF_INDEXES; -static void init_errno(void) +static void init_cffi_tls(void) { if (cffi_tls_index == TLS_OUT_OF_INDEXES) { cffi_tls_index = TlsAlloc(); |