all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Ted Zlatanov <tzz@lifelogs.com>
Cc: gnutls-devel@gnu.org, emacs-devel@gnu.org
Subject: Re: Emacs core TLS support
Date: Mon, 06 Sep 2010 23:00:51 +0200	[thread overview]
Message-ID: <jwvmxruehco.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87wrqzhrjv.fsf@lifelogs.com> (Ted Zlatanov's message of "Mon, 06 Sep 2010 09:31:32 -0500")

> Yeah, I'll do that for `gnutls-bye' with a CONT parameter.  It's just a
> NILP check to handle booleans IIUC (there's no CHECK_BOOLEAN, so it's
> either NILP or EQ to Qt).

Yes, NILP is the way to test it (anything that's not nil is considered
as a way to say "true").

>>> +DEFUN ("gnutls-cred-set", Fgnutls_cred_set, 
>>> +       Sgnutls_cred_set, 2, 2, 0,
>>> +       doc: /* Enables GNU TLS authentication for PROCESS.
>>> +TYPE is an integer indicating the type of the credentials, either
>>> +`gnutls-anon', `gnutls-srp' or `gnutls-x509pki'.
SM> Again, the above formulation means that the caller should pass those
SM> symbols rather than value associated with the corresponding variables.

> In this case I think that's the right approach actually so we shouldn't
> have defconsts.  See new definition, it uses two local Lisp_Objects for
> the symbol names.
> Where should I allocate those constant Lisp_Objects
> globally properly?

It's typically declared as global (static or not, depending on whether
it's used in other files) and initialized in syms_of_<foo>.
Look at other syms_of_<foo> to see what it looks like.

> And should I default to anonymous?

I don't know what that means.

>>> +#ifdef HAVE_GNUTLS
>>> +    /* XXX Store GNU TLS state and auth mechanisms in Lisp_Objects. */
>>> +    Lisp_Object gnutls_state;
>>> +    Lisp_Object x509_cred, x509_callback;
>>> +    Lisp_Object anon_cred;
>>> +    Lisp_Object srp_cred;
>>> +#endif

These extra slots don't actually Lisp objects, so this type is wrong
(and it forces you to use casts: any use of cast is a sign of
a problem, tho admittedly C often makes problems unavoidable).
If you check the "struct Lisp_Process" in process.h you'll see this:

    /* After this point, there are no Lisp_Objects any more.  */
    /* alloc.c assumes that `pid' is the first such non-Lisp slot.  */

so the slots you add at the end are ignored by the GC (which is what
you want in your case, since they're not Lisp objects and hence the GC
wouldn't know what to do with them) and can be of any type.  So just use
the types you need here such that casts aren't needed.

> I'd like to take the direction of a more Lisp-y API on top of the GnuTLS
> API.  So any constants should be limited to the function bodies and I'd
> like to stick to symbols (as with gnutls-cred-set in the new patch).

BTW, if it makes the code simpler, you can use the following trick: use
symbols, but associate an integer to each symbol by way of
symbol properties.
I.e. something like

   static Lisp_Object Qgnutls_foo;

   gnutls_function (Lisp_Object arg1, ...)
   {
      arg1 = Fget (arg1, Qgnutls_code);
      int op = INTEGERP (arg1) ? XINT (arg1) : ....;
      if (op < n1 || op > n2)
         error ("Invalid op code");
      gnutls_foo (..., op, ...);
   }

   syms_of_gnutls ()
   {
      ...
      Qgnutls_foo = intern ("gnutls-foo");
      ...
      Fput (Qgnutls_foo, Qgnutls_code, make_number (GNUTLS_FOO));
   }

It's not super-lightweight, but it can be more convenient than a bunch
of (EQ (foo, Qgnutls_bar)) if there are many different possible values.

>>> +  ret = gnutls_init((gnutls_session_t*)&(XPROCESS(proc)->gnutls_state), 
AS> Aliasing violation.
> Can you explain please?

Casts are evil, try real hard to stay away from them (he said, and then
added a few casts).

AS> IMHO all your functions should return t on success and either some error
AS> symbol on failure or even raise an error.
> Yes, but I'm not sure which one.  Can you recommend?

 error ("some informative string");

> I don't know enough (the choice of using Lisp_Objects was in the
> original patch) to know what to do instead of using Lisp_Objects.  Why
> not, first of all?

The type you declare should correspond to the type of the objects you
store there.  Always.  If you stick to this principle and avoid freeing
live objects (and stay within array bounds, and a few more such things)
your code will be more portable and won't dump core (hence will be
generally easier to debug).


        Stefan

  parent reply	other threads:[~2010-09-06 21:00 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-13 21:53 Emacs core TLS support Ted Zlatanov
2010-01-13 23:46 ` Chong Yidong
2010-01-14 14:09   ` Ted Zlatanov
2010-01-14 15:44     ` Stefan Monnier
2010-01-14 16:38       ` Ted Zlatanov
2010-01-29 19:59         ` Ted Zlatanov
2010-08-12 23:00           ` Ted Zlatanov
2010-08-13 11:04             ` James Cloos
2010-08-13 15:07               ` Ted Zlatanov
2010-08-13 15:51                 ` Julien Danjou
2010-08-13 16:11                   ` Eli Zaretskii
2010-08-13 15:53                 ` David Kastrup
2010-08-13 16:11                   ` Julien Danjou
2010-08-13 15:57                 ` Chong Yidong
2010-08-13 17:25                   ` Ted Zlatanov
2010-08-14  0:15                     ` Chong Yidong
2010-09-05  4:57                       ` Ted Zlatanov
2010-09-05  8:06                         ` Andreas Schwab
2010-09-05 22:47                         ` Stefan Monnier
2010-09-06  7:47                           ` Andreas Schwab
2010-09-06 14:31                           ` Ted Zlatanov
2010-09-06 15:53                             ` Andreas Schwab
2010-09-06 17:18                             ` Andreas Schwab
2010-09-09 15:12                               ` Ted Zlatanov
2010-09-09 22:00                                 ` Lars Magne Ingebrigtsen
2010-09-10  8:33                                   ` Andreas Schwab
2010-09-10 10:59                                     ` Lars Magne Ingebrigtsen
2010-09-10 14:06                                       ` Ted Zlatanov
2010-09-11 12:45                                         ` Stefan Monnier
2010-09-14 15:34                                           ` Ted Zlatanov
2010-09-06 21:00                             ` Stefan Monnier [this message]
2010-09-06 23:13                               ` Ted Zlatanov
2010-09-11 14:59                                 ` Ted Zlatanov
2010-09-11 15:00                                   ` Ted Zlatanov
2010-09-12 10:58                                     ` Stefan Monnier
2010-09-14 15:45                                       ` Ted Zlatanov
2010-09-13  7:49                                   ` Nikos Mavrogiannopoulos
2010-09-14 18:30                                     ` Ted Zlatanov
2010-09-14 18:55                                       ` Nikos Mavrogiannopoulos
2010-09-14 19:10                                         ` Lars Magne Ingebrigtsen
2010-09-15 11:20                                           ` Ted Zlatanov
2010-09-15  1:25                                         ` Ted Zlatanov
2010-09-15 11:01                                     ` Ted Zlatanov
2010-09-15 12:13                                       ` Nikos Mavrogiannopoulos
2010-09-15 15:40                                         ` Ted Zlatanov
2010-09-26  6:09                                         ` Ted Zlatanov
2010-09-26 15:32                                           ` Lars Magne Ingebrigtsen
2010-09-26 21:50                                           ` James Cloos
2010-09-27 13:37                                             ` Lars Magne Ingebrigtsen
2010-09-27 13:56                                               ` Lars Magne Ingebrigtsen
2010-09-27 14:03                                                 ` Lars Magne Ingebrigtsen
2010-09-27 14:11                                                 ` Lars Magne Ingebrigtsen
2010-09-27 14:21                                                 ` Lars Magne Ingebrigtsen
2010-09-27 14:40                                                   ` Lars Magne Ingebrigtsen
2010-09-27 14:56                                                     ` Ted Zlatanov
2010-09-27 15:13                                                       ` Lars Magne Ingebrigtsen
2010-09-27 15:02                                                     ` Bruce Stephens
2010-09-27 15:07                                                       ` Lars Magne Ingebrigtsen
2010-09-27 15:18                                                         ` Lars Magne Ingebrigtsen
2010-09-27 15:11                                                     ` Ted Zlatanov
2010-09-27 15:14                                                       ` Lars Magne Ingebrigtsen
2010-09-27 14:42                                                 ` Ted Zlatanov
2010-09-29 12:53                                                   ` Lars Magne Ingebrigtsen
2010-09-29 13:25                                                     ` Lars Magne Ingebrigtsen
2010-09-29 18:36                                                       ` Jason Earl
2010-09-29 20:05                                                         ` Ted Zlatanov
2010-09-29 20:32                                                           ` Jason Earl
2010-09-29 20:35                                                             ` Lars Magne Ingebrigtsen
2010-09-29 21:33                                                               ` Jason Earl
2010-09-29 17:06                                                     ` Ted Zlatanov
2010-09-29 17:44                                                       ` Ted Zlatanov
2010-09-29 18:43                                                         ` Lars Magne Ingebrigtsen
2010-09-29 18:43                                                       ` Lars Magne Ingebrigtsen
2010-10-03 14:21                                                       ` Ted Zlatanov
2010-10-03 14:48                                                         ` Ted Zlatanov
2010-10-03 22:37                                                           ` Lars Magne Ingebrigtsen
2010-10-04  1:23                                                             ` final GnuTLS API! (was: Emacs core TLS support) Ted Zlatanov
2010-10-04 10:49                                                               ` final GnuTLS API! Lars Magne Ingebrigtsen
2010-10-04 14:44                                                                 ` Ted Zlatanov
2010-09-27 14:36                                             ` Emacs core TLS support Ted Zlatanov
2010-09-27 18:25                                               ` James Cloos
2010-09-27 18:45                                                 ` Ted Zlatanov
2010-09-27 19:07                                                   ` Lars Magne Ingebrigtsen
2010-09-27 19:38                                                     ` Lars Magne Ingebrigtsen
2010-09-21 11:37                                       ` Simon Josefsson
2010-09-26  6:12                                         ` Ted Zlatanov
2010-09-30 10:10                                           ` Simon Josefsson
2010-10-04  3:42                                             ` Ted Zlatanov
2010-10-04  6:24                                               ` Nikos Mavrogiannopoulos
2010-08-13 13:54             ` Leo
2010-08-13 14:50               ` Ted Zlatanov
2010-08-14 19:20                 ` Leo
  -- strict thread matches above, loose matches on Subject: below --
2010-01-14  1:37 MON KEY

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvmxruehco.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=gnutls-devel@gnu.org \
    --cc=tzz@lifelogs.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.