simplify the thread implementation, use feature 'nothread' to disable threads instead of 'thread' to enable them, plus other fixes around threads
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7933 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d35515351b
commit
2eeef5275d
6 changed files with 62 additions and 101 deletions
|
|
@ -643,7 +643,6 @@ SWIG_Python_GetSwigThis(PyObject *pyobj)
|
|||
if (pyobj && PySwigObject_Check(pyobj)) {
|
||||
return (PySwigObject *) pyobj;
|
||||
} else {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
PyObject *obj = 0;
|
||||
#ifndef SWIG_PYTHON_SLOW_GETSET_THIS
|
||||
if (PyInstance_Check(pyobj)) {
|
||||
|
|
@ -664,13 +663,11 @@ SWIG_Python_GetSwigThis(PyObject *pyobj)
|
|||
#endif
|
||||
if (!obj || PyErr_Occurred()) {
|
||||
PyErr_Clear();
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
return 0;
|
||||
}
|
||||
if (!PySwigObject_Check(obj)) {
|
||||
obj = 0;
|
||||
}
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
return (PySwigObject *)obj;
|
||||
}
|
||||
}
|
||||
|
|
@ -828,11 +825,9 @@ SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
|
|||
if (!ptr) {
|
||||
return SWIG_Py_Void();
|
||||
} else if (!type) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, "Swig: null type passed to NewPointerObj");
|
||||
}
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
return NULL;
|
||||
} else {
|
||||
int own = (flags & SWIG_POINTER_OWN) ? SWIG_POINTER_OWN : 0;
|
||||
|
|
@ -872,7 +867,6 @@ void *SWIG_ReturnGlobalTypeList(void *);
|
|||
SWIGRUNTIME swig_module_info *
|
||||
SWIG_Python_GetModule(void) {
|
||||
static void *type_pointer = (void *)0;
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
/* first check if module already created */
|
||||
if (!type_pointer) {
|
||||
#ifdef SWIG_LINK_RUNTIME
|
||||
|
|
@ -886,7 +880,6 @@ SWIG_Python_GetModule(void) {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
return (swig_module_info *) type_pointer;
|
||||
}
|
||||
|
||||
|
|
@ -898,27 +891,21 @@ PyModule_AddObject(PyObject *m, char *name, PyObject *o)
|
|||
{
|
||||
PyObject *dict;
|
||||
if (!PyModule_Check(m)) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"PyModule_AddObject() needs module as first arg");
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
if (!o) {
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"PyModule_AddObject() needs non-NULL value");
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
dict = PyModule_GetDict(m);
|
||||
if (dict == NULL) {
|
||||
/* Internal error -- modules must have a dict! */
|
||||
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
|
||||
PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__",
|
||||
PyModule_GetName(m));
|
||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
if (PyDict_SetItemString(dict, name, o))
|
||||
|
|
|
|||
|
|
@ -1,24 +1,22 @@
|
|||
#if defined(SWIG_PYTHON_NO_THREADING)
|
||||
# if defined(SWIG_PYTHON_THREADING)
|
||||
# undef SWIG_PYTHON_THREADING
|
||||
#if defined(SWIG_PYTHON_NO_THREADS)
|
||||
# if defined(SWIG_PYTHON_THREADS)
|
||||
# undef SWIG_PYTHON_THREADS
|
||||
# endif
|
||||
#endif
|
||||
#if defined(SWIG_PYTHON_THREADING) /* Threading support is enabled */
|
||||
#if defined(SWIG_PYTHON_THREADS) /* Threading support is enabled */
|
||||
# if !defined(SWIG_PYTHON_USE_GIL) && !defined(SWIG_PYTHON_NO_USE_GIL)
|
||||
# if (PY_VERSION_HEX >= 0x02030000) /* For 2.3 or later, use the PyGILState calls */
|
||||
# define SWIG_PYTHON_USE_GIL
|
||||
# endif
|
||||
# endif
|
||||
# if defined(SWIG_PYTHON_USE_GIL) /* Use PyGILState threads calls */
|
||||
# if !defined(SWIG_PYTHON_INITIALIZE_THREADING)
|
||||
# define SWIG_PYTHON_INITIALIZE_THREADING PyEval_InitThreads()
|
||||
# endif
|
||||
# ifdef __cplusplus
|
||||
# define SWIG_PYTHON_INITIALIZE_THREADS PyEval_InitThreads()
|
||||
# ifdef __cplusplus /* C++ code */
|
||||
class SWIG_Python_Thread_Block {
|
||||
bool status;
|
||||
PyGILState_STATE state;
|
||||
public:
|
||||
void begin() { if (!status) { state = PyGILState_Ensure(); status = true;} }
|
||||
public:
|
||||
void end() { if (status) { PyGILState_Release(state); status = false;} }
|
||||
SWIG_Python_Thread_Block() : status(false) { begin(); }
|
||||
~SWIG_Python_Thread_Block() { end(); }
|
||||
|
|
@ -26,8 +24,8 @@
|
|||
class SWIG_Python_Thread_Allow {
|
||||
bool status;
|
||||
PyThreadState *save;
|
||||
void begin() { if (!status) { status = true; save = PyEval_SaveThread(); } }
|
||||
public:
|
||||
void begin() { if (!status) { status = true; save = PyEval_SaveThread(); }}
|
||||
void end() { if (status) { PyEval_RestoreThread(save); status = false; }}
|
||||
SWIG_Python_Thread_Allow() : status(false) { begin(); }
|
||||
~SWIG_Python_Thread_Allow() { end(); }
|
||||
|
|
@ -36,15 +34,15 @@
|
|||
# define SWIG_PYTHON_THREAD_END_BLOCK _swig_thread_block.end()
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW SWIG_Python_Thread_Allow _swig_thread_allow
|
||||
# define SWIG_PYTHON_THREAD_END_ALLOW _swig_thread_allow.end()
|
||||
# else /* C++ */
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_allow = PyGILState_Ensure()
|
||||
# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_allow)
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW Py_BEGIN_ALLOW_THREADS
|
||||
# define SWIG_PYTHON_THREAD_END_ALLOW Py_END_ALLOW_THREADS
|
||||
# else /* C code */
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_BLOCK PyGILState_STATE _swig_thread_block = PyGILState_Ensure()
|
||||
# define SWIG_PYTHON_THREAD_END_BLOCK PyGILState_Release(_swig_thread_block)
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW PyThreadState *_swig_thread_allow = PyEval_SaveThread()
|
||||
# define SWIG_PYTHON_THREAD_END_ALLOW PyEval_RestoreThread(_swig_thread_allow)
|
||||
# endif
|
||||
# else /* Old thread way, not implemented, user must provide it */
|
||||
# if !defined(SWIG_PYTHON_INITIALIZE_THREADING)
|
||||
# define SWIG_PYTHON_INITIALIZE_THREADING
|
||||
# if !defined(SWIG_PYTHON_INITIALIZE_THREADS)
|
||||
# define SWIG_PYTHON_INITIALIZE_THREADS
|
||||
# endif
|
||||
# if !defined(SWIG_PYTHON_THREAD_BEGIN_BLOCK)
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_BLOCK
|
||||
|
|
@ -60,7 +58,7 @@
|
|||
# endif
|
||||
# endif
|
||||
#else /* No thread support */
|
||||
# define SWIG_PYTHON_INITIALIZE_THREADING
|
||||
# define SWIG_PYTHON_INITIALIZE_THREADS
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_BLOCK
|
||||
# define SWIG_PYTHON_THREAD_END_BLOCK
|
||||
# define SWIG_PYTHON_THREAD_BEGIN_ALLOW
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
/* -------------------------------------------------------------------------
|
||||
* Special user directives
|
||||
* ----------------------------------------------------------------------------- */
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
/* shadow code */
|
||||
#define %shadow %insert("shadow")
|
||||
#define %pythoncode %insert("python")
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/*
|
||||
Use the "nondynamic" feature to make a wrapped class behaves as a "nondynamic"
|
||||
one, ie, a python class that doesn't dynamically add new attributes.
|
||||
|
|
@ -51,7 +51,7 @@ so, it works with old python versions.
|
|||
#define %pythondynamic %nopythonnondynamic
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/*
|
||||
|
||||
Use %pythonmaybecall to flag a method like __add__ or __radd__, which
|
||||
|
|
@ -65,7 +65,7 @@ These methods "may be called" if needed.
|
|||
#define %nopythonmaybecall %feature("python:maybecall", "0")
|
||||
#define %clearpythonmaybecall %feature("python:maybecall", "")
|
||||
|
||||
/* ----------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/*
|
||||
The %pythoncallback feature produce a more natural callback wrap
|
||||
than the %callback mechanism, ie, it use the original name for
|
||||
|
|
@ -111,7 +111,7 @@ These methods "may be called" if needed.
|
|||
#define %nopythoncallback %feature("python:callback","0")
|
||||
#define %clearpythoncallback %feature("python:callback","")
|
||||
|
||||
/* ----------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/*
|
||||
Support for the old %callback directive name
|
||||
*/
|
||||
|
|
@ -131,14 +131,15 @@ These methods "may be called" if needed.
|
|||
#define %nocallback %nopythoncallback
|
||||
#define %clearcallback %clearpythoncallback
|
||||
|
||||
/* ----------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/*
|
||||
Thread support
|
||||
Thread support - Advance control
|
||||
|
||||
*/
|
||||
|
||||
#define %threads %feature("threads")
|
||||
#define %nothreads %feature("threads","0")
|
||||
#define %clearthreads %feature("threads","")
|
||||
#define %nothread %feature("nothread")
|
||||
#define %thread %feature("nothread","0")
|
||||
#define %clearnothread %feature("nothread","")
|
||||
|
||||
#define %nothreadblock %feature("nothreadblock")
|
||||
#define %threadblock %feature("nothreadblock","0")
|
||||
|
|
@ -149,7 +150,7 @@ These methods "may be called" if needed.
|
|||
#define %clearnothreadallow %feature("nothreadallow","")
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/*
|
||||
Directors
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue