Skip to content
This repository was archived by the owner on Aug 21, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/c/misc_thread_common.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#ifndef CFFI_MISC_THREAD_COMMON_H
#define CFFI_MISC_THREAD_COMMON_H
#ifndef WITH_THREAD
# error "xxx no-thread configuration not tested, please report if you need that"
#endif
#include "pythread.h"
#include "inttypes.h"


struct cffi_tls_s {
Expand All @@ -22,7 +25,7 @@ struct cffi_tls_s {
#endif
};

static struct cffi_tls_s *get_cffi_tls(void); /* in misc_thread_posix.h
static struct cffi_tls_s *get_cffi_tls(void); /* in misc_thread_posix.h
or misc_win32.h */


Expand Down Expand Up @@ -312,7 +315,7 @@ static void restore_errno_only(void)

/* MESS. We can't use PyThreadState_GET(), because that calls
PyThreadState_Get() which fails an assert if the result is NULL.

* in Python 2.7 and <= 3.4, the variable _PyThreadState_Current
is directly available, so use that.

Expand Down Expand Up @@ -390,3 +393,5 @@ static void gil_release(PyGILState_STATE oldstate)
//fprintf(stderr, "%p: gil_release(%d), tls=%p\n", get_cffi_tls(), (int)oldstate, get_cffi_tls());
PyGILState_Release(oldstate);
}

#endif /* CFFI_MISC_THREAD_COMMON_H */
4 changes: 4 additions & 0 deletions src/c/misc_thread_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
see a given thread, and keep it alive until the thread is really
shut down, using a destructor on the tls key.
*/
#ifndef CFFI_MISC_THREAD_POSIX_H
#define CFFI_MISC_THREAD_POSIX_H

#include <pthread.h>
#include "misc_thread_common.h"
Expand Down Expand Up @@ -64,3 +66,5 @@ static void cffi_atomic_store(void **ptr, void *value)
__atomic_store_n(ptr, value, __ATOMIC_SEQ_CST);
}
#endif

#endif /* CFFI_MISC_THREAD_POSIX_H */
9 changes: 7 additions & 2 deletions src/c/misc_win32.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifndef CFFI_MISC_WIN32_H
#define CFFI_MISC_WIN32_H


#include <malloc.h> /* for alloca() */


Expand Down Expand Up @@ -250,7 +254,7 @@ static int dlclose(void *handle)
static const char *dlerror(void)
{
static char buf[32];
DWORD dw = GetLastError();
DWORD dw = GetLastError();
if (dw == 0)
return NULL;
sprintf(buf, "error 0x%x", (unsigned int)dw);
Expand Down Expand Up @@ -280,8 +284,9 @@ static void *cffi_atomic_load(void **ptr)
#endif
}


static void cffi_atomic_store(void **ptr, void *value)
{
_InterlockedExchangePointer(ptr, value);
}

#endif /* CFFI_MISC_WIN32_H */
Loading