unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* How and when to use GCPRO?
@ 2010-12-27  9:21 Leo
  2010-12-27 10:15 ` Andreas Schwab
  0 siblings, 1 reply; 19+ messages in thread
From: Leo @ 2010-12-27  9:21 UTC (permalink / raw)
  To: emacs-devel

Hello,

I wonder if anyone can point me to a more detailed explanation of how
and when to use GCPRO other than what's in the elisp manual.

Is there any symptom in a gdb session that one should suspect a GCPRO is
missing?

For example, Could someone comment on the following function I just
wrote, which tries to add support for feature expressions like in common
lisp?

static Lisp_Object
eval_feature_expression (form)
     Lisp_Object form;
{
  Lisp_Object val, exp;
  struct gcpro gcpro1;

  if (! NILP(Fatom(form)))
    return NILP(Fmemq(form, Vfeatures)) ? Qnil:Qt;

  if (EQ (Fcar(form), Qnot))
    {
      if (XINT(Flength(form)) != 2)
        error ("Invalid feature expression");
      val = eval_feature_expression (Fcar(Fcdr(form)));
      return NILP(val) ? Qt:Qnil;
    }

  if (EQ (Fcar(form), Qand))
    {
      if (NILP (Fcdr (form)))
        error ("Invalid feature expression");
      val = eval_feature_expression (Fcar (Fcdr (form)));
      if (NILP (Fcdr (Fcdr (form))))
        return val;
      else if (NILP(val))
        return Qnil;
      else
        {
          GCPRO1(exp);
          exp = Fcons (Qand, (Fcdr(Fcdr(form))));
          val = eval_feature_expression (exp);
          UNGCPRO;
          return val;
        }
    }

  if (EQ (Fcar(form), Qor))
    {
      if (NILP (Fcdr (form)))
        error ("Invalid feature expression");
      val = eval_feature_expression (Fcar (Fcdr (form)));
      if (NILP (Fcdr (Fcdr (form))))
        return val;
      else if (NILP (val))
        {
          GCPRO1(exp);
          exp = Fcons (Qor, (Fcdr(Fcdr(form))));
          UNGCPRO;
          return eval_feature_expression (exp);
        }
      else
        return Qt;
    }
  error ("Invalid feature expression");
}

I am also reading the XEmacs internals manual on GCPROing but I have
little idea what is still true for GNU Emacs.

Thanks in advance and happy holidays.

Leo




^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2010-12-28 17:07 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-27  9:21 How and when to use GCPRO? Leo
2010-12-27 10:15 ` Andreas Schwab
2010-12-27 10:38   ` Leo
2010-12-27 11:17     ` Andreas Schwab
2010-12-27 16:00   ` Stefan Monnier
2010-12-27 17:51     ` Andreas Schwab
2010-12-28  1:01       ` Stefan Monnier
2010-12-28  1:33         ` Daniel Colascione
2010-12-28  2:17           ` Stefan Monnier
2010-12-28  3:37             ` Daniel Colascione
2010-12-28  4:15               ` Stefan Monnier
2010-12-28  4:36                 ` Conservative scanning (was: Re: How and when to use GCPRO?) Daniel Colascione
2010-12-28 17:07               ` How and when to use GCPRO? Richard Stallman
2010-12-27 19:15     ` Leo
2010-12-27 19:26     ` Common Lisp like feature expressions (was: How and when to use GCPRO?) Leo
2010-12-27 19:38       ` Andreas Schwab
2010-12-27 19:57         ` Leo
2010-12-28  1:01           ` Common Lisp like feature expressions Stefan Monnier
2010-12-28 15:26             ` Leo

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).