* python/python-internal.h (PyGILState_Ensure): New define.

(PyGILState_Release): Likewise.
	(PyEval_InitThreads): Likewise.
	(PyThreadState_Swap): Likewise.
	(PyEval_InitThreads): Likewise.
	* python/python.c (_initialize_python): Initialize threads.
	Release GIL.
	(eval_python_from_control_command): Acquire GIL.
	(python_command): Likewise.
	* python/python-internal.h (make_cleanup_py_restore_gil):
	Declare.
	* python/python-utils.c (py_gil_restore): New function.
	(make_cleanup_py_restore_gil): Likewise.
This commit is contained in:
Tom Tromey
2008-11-21 14:59:56 +00:00
parent 3c9ab205d3
commit ca30a76297
4 changed files with 67 additions and 2 deletions

View File

@ -46,6 +46,23 @@ make_cleanup_py_decref (PyObject *py)
return make_cleanup (py_decref, (void *) py);
}
/* A cleanup function to restore the thread state. */
static void
py_gil_restore (void *p)
{
PyGILState_STATE *state = p;
PyGILState_Release (*state);
}
/* Return a new cleanup which will restore the Python GIL state. */
struct cleanup *
make_cleanup_py_restore_gil (PyGILState_STATE *state)
{
return make_cleanup (py_gil_restore, state);
}
/* Converts a Python 8-bit string to a unicode string object. Assumes the
8-bit string is in the host charset. If an error occurs during conversion,
returns NULL with a python exception set.