Ticket #364: python.i-diff-against-reformatted-original.patch

File python.i-diff-against-reformatted-original.patch, 1.6 KB (added by Olly Betts, 12 years ago)

patch against reformatted original to show actual changes better

  • (a) reformatted-python.i.orig vs. (b) python.i

    a b  
    2828 * overhead of thread locking when the user's code isn't using threads. */
    2929#define SWIG_PYTHON_NO_USE_GIL
    3030
     31static __thread PyThreadState * swig_pythreadstate = NULL;
     32
    3133class XapianSWIG_Python_Thread_Block {
    3234    bool status;
    33     PyGILState_STATE state;
    3435  public:
    3536    XapianSWIG_Python_Thread_Block()
    36         : status(PyEval_ThreadsInitialized()) {
     37        : status(PyEval_ThreadsInitialized() && swig_pythreadstate) {
    3738        if (status) {
    38             state = PyGILState_Ensure();
     39            PyEval_RestoreThread(swig_pythreadstate);
     40            swig_pythreadstate = NULL;
    3941        }
    4042    }
    4143    void end() {
    4244        if (status) {
    43             PyGILState_Release(state);
     45            if (swig_pythreadstate) Py_FatalError("swig_pythreadstate set in XapianSWIG_Python_Thread_Block::end()");
     46            swig_pythreadstate = PyEval_SaveThread();
    4447            status = false;
    4548        }
    4649    }
     
    4952
    5053class XapianSWIG_Python_Thread_Allow {
    5154    bool status;
    52     PyThreadState *save;
    5355  public:
    5456    XapianSWIG_Python_Thread_Allow() : status(PyEval_ThreadsInitialized()) {
    5557        if (status) {
    56             save = PyEval_SaveThread();
     58            if (swig_pythreadstate) Py_FatalError("swig_pythreadstate set in XapianSWIG_Python_Thread_Allow ctor");
     59            swig_pythreadstate = PyEval_SaveThread();
    5760        }
    5861    }
    5962    void end() {
    6063        if (status) {
    61             PyEval_RestoreThread(save);
     64            if (!swig_pythreadstate) Py_FatalError("swig_pythreadstate unset in XapianSWIG_Python_Thread_Block::end()");
     65            PyEval_RestoreThread(swig_pythreadstate);
     66            swig_pythreadstate = NULL;
    6267            status = false;
    6368        }
    6469    }