+2013-09-01 Eli Zaretskii <eliz@gnu.org>
+
+ * eval.c (unbind_for_thread_switch): Accept a 'struct
+ thread_state *' argument and use specpdl_ptr and specpdl of that
+ thread. Fixes crashes if find_symbol_value signals an error.
+
+ * thread.c (post_acquire_global_lock): Update current_thread
+ before calling unbind_for_thread_switch. Pass the previous thread
+ to unbind_for_thread_switch.
+
2013-08-31 Eli Zaretskii <eliz@gnu.org>
* systhread.c (sys_cond_init): Set the 'initialized' member to
}
void
-unbind_for_thread_switch (void)
+unbind_for_thread_switch (struct thread_state *thr)
{
union specbinding *bind;
- for (bind = specpdl_ptr; bind != specpdl; --bind)
+ for (bind = thr->m_specpdl_ptr; bind != thr->m_specpdl; --bind)
{
if (bind->kind >= SPECPDL_LET)
{
extern void set_unwind_protect_ptr (ptrdiff_t, void (*) (void *), void *);
extern Lisp_Object unbind_to (ptrdiff_t, Lisp_Object);
extern void rebind_for_thread_switch (void);
-extern void unbind_for_thread_switch (void);
+extern void unbind_for_thread_switch (struct thread_state *);
extern _Noreturn void error (const char *, ...) ATTRIBUTE_FORMAT_PRINTF (1, 2);
extern _Noreturn void verror (const char *, va_list)
ATTRIBUTE_FORMAT_PRINTF (1, 0);
post_acquire_global_lock (struct thread_state *self)
{
Lisp_Object buffer;
+ struct thread_state *prev_thread = current_thread;
- if (self != current_thread)
+ /* Do this early on, so that code below could signal errors (e.g.,
+ unbind_for_thread_switch might) correctly, because we are already
+ running in the context of the thread pointed by SELF. */
+ current_thread = self;
+
+ if (prev_thread != current_thread)
{
- /* CURRENT_THREAD is NULL if the previously current thread
+ /* PREV_THREAD is NULL if the previously current thread
exited. In this case, there is no reason to unbind, and
trying will crash. */
- if (current_thread != NULL)
- unbind_for_thread_switch ();
- current_thread = self;
+ if (prev_thread != NULL)
+ unbind_for_thread_switch (prev_thread);
rebind_for_thread_switch ();
}