Many functions in emacs contain the sequence
{
count = SPECPDL_INDEX ();
record_unwind_protect
val = Fprogn (args);
return unbind_to (count, val);
}


like the  function attached below,

Can you explain me the logic of specpdl please ?



DEFUN ("save-current-buffer", Fsave_current_buffer, Ssave_current_buffer, 0, UNEVALLED, 0,
....
  (Lisp_Object args)
{
  Lisp_Object val;
  int count = SPECPDL_INDEX ();

  record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());

  val = Fprogn (args);
  return unbind_to (count, val);
}