On Wed, 25 Jun 2003, Elliot Lee wrote: > The problem is that pygdk_block_threads assumes that an accompanying > pygdk_unblock_threads has previously been called, when in fact it hasn't. > This can happen in situations when a thread calls a non-thread-wrapped gtk > function that emits a signal (e.g. gtk_entry_set_text()), and that signal > is connected to a python function.
The attached patch seems to fix this particular problem. > On a related note, pygdk_{block,unblock}_threads should really call > gdk_threads_{leave,enter} for sanity's sake. This still is an issue - I can't just put the calls into pygdk_{block,unblock}_threads. -- Elliot Humpty Dumpty was pushed.
--- pygtk-1.99.16/gtk/gdk.override.sopwith 2003-06-26 10:41:28.000000000 -0400 +++ pygtk-1.99.16/gtk/gdk.override 2003-06-26 16:42:52.000000000 -0400 @@ -68,36 +68,48 @@ static GStaticPrivate lock_count_key = G_STATIC_PRIVATE_INIT; static PyInterpreterState *pyinterpstate = NULL; +static gint * +pygdk_get_lock_count(void) +{ + gint *lock_count = g_static_private_get(&lock_count_key); + + if(!lock_count) + { + lock_count = g_malloc(sizeof(gint)); + *lock_count = 1; + g_static_private_set(&lock_count_key, lock_count, NULL); + } + + return lock_count; +} + static void pygdk_block_threads (void) { - gint lock_count = GPOINTER_TO_INT(g_static_private_get(&lock_count_key)); - - if (lock_count == 0) { - PyThreadState *_save; + PyThreadState *_save; + gint *lock_count = pygdk_get_lock_count(); - _save = g_static_private_get(&pythreadstate_key); - if (_save == NULL) { - _save = PyThreadState_New(pyinterpstate); - } - Py_BLOCK_THREADS; - } - lock_count++; - g_static_private_set(&lock_count_key, GINT_TO_POINTER(lock_count), NULL); + (*lock_count)++; + if(*lock_count == 1) + { + _save = g_static_private_get(&pythreadstate_key); + g_assert(_save); + Py_BLOCK_THREADS; + g_static_private_set(&pythreadstate_key, NULL, NULL); + } } + static void pygdk_unblock_threads (void) { - gint lock_count = GPOINTER_TO_INT(g_static_private_get(&lock_count_key)); - - lock_count--; - if (lock_count == 0) { - PyThreadState *_save; + PyThreadState *_save; + gint *lock_count = pygdk_get_lock_count(); + if(*lock_count == 1) { Py_UNBLOCK_THREADS; g_static_private_set(&pythreadstate_key, _save, NULL); } - g_static_private_set(&lock_count_key, GINT_TO_POINTER(lock_count), NULL); + (*lock_count)--; } #endif @@ -110,7 +122,6 @@ PyEval_InitThreads(); gdk_threads_init(); - g_static_private_set(&lock_count_key, GINT_TO_POINTER(1), NULL); pyinterpstate = PyThreadState_Get()->interp;
_______________________________________________ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/