On Friday, 04 March 2005 at 16:37, Aaron Crane wrote: > Brendan Cully writes: > > > struct s *p = ...; > > > int fd = (p->open)(name, mode); > > > (p->close)(fd); > > > > I actually don't mind this version. In a way I like it better than > > the global rename, even though it's about the same amount of work. It > > makes me feel like the namespace is a little less polluted :) > > The thing I really dislike about it is that everyone who will ever work > on such code will need to know about this particular dark corner of C: > at the very least, that a problem exists, and that this is the > workaround for it. All it takes is for one person to forget, or not to > have known about this in the first place, and suddenly the build breaks > for some people. Renaming the members seems much safer to me. I suppose so. I also like the symmetry between the declaration in the struct and its usage: if it gets renamed in one place it should get renamed in the other. You don't get that just by renaming the member. But I suppose that's a bit pedantic, as long as a decent name is chosen. I've attached a patch that renames the CONNECTION and SASL_DATA function pointers. I hope I haven't missed anything.
Index: mutt_sasl.c =================================================================== RCS file: /home/roessler/cvs/mutt/mutt_sasl.c,v retrieving revision 3.11 diff -u -p -r3.11 mutt_sasl.c --- mutt_sasl.c 3 Feb 2005 17:01:43 -0000 3.11 +++ mutt_sasl.c 4 Mar 2005 17:22:25 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-3 Brendan Cully <brendan@xxxxxxxxxx> + * Copyright (C) 2000-5 Brendan Cully <brendan@xxxxxxxxxx> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -429,17 +429,17 @@ void mutt_sasl_setup_conn (CONNECTION* c /* preserve old functions */ sasldata->sockdata = conn->sockdata; - sasldata->open = conn->open; - sasldata->close = conn->close; - sasldata->read = conn->read; - sasldata->write = conn->write; + sasldata->msasl_open = conn->conn_open; + sasldata->msasl_close = conn->conn_close; + sasldata->msasl_read = conn->conn_read; + sasldata->msasl_write = conn->conn_write; /* and set up new functions */ conn->sockdata = sasldata; - conn->open = mutt_sasl_conn_open; - conn->close = mutt_sasl_conn_close; - conn->read = mutt_sasl_conn_read; - conn->write = mutt_sasl_conn_write; + conn->conn_open = mutt_sasl_conn_open; + conn->conn_close = mutt_sasl_conn_close; + conn->conn_read = mutt_sasl_conn_read; + conn->conn_write = mutt_sasl_conn_write; } /* mutt_sasl_cb_log: callback to log SASL messages */ @@ -515,7 +515,7 @@ static int mutt_sasl_conn_open (CONNECTI sasldata = (SASL_DATA*) conn->sockdata; conn->sockdata = sasldata->sockdata; - rc = (sasldata->open) (conn); + rc = (sasldata->msasl_open) (conn); conn->sockdata = sasldata; return rc; @@ -532,10 +532,10 @@ static int mutt_sasl_conn_close (CONNECT /* restore connection's underlying methods */ conn->sockdata = sasldata->sockdata; - conn->open = sasldata->open; - conn->close = sasldata->close; - conn->read = sasldata->read; - conn->write = sasldata->write; + conn->conn_open = sasldata->msasl_open; + conn->conn_close = sasldata->msasl_close; + conn->conn_read = sasldata->msasl_read; + conn->conn_write = sasldata->msasl_write; /* release sasl resources */ sasl_dispose (&sasldata->saslconn); @@ -545,7 +545,7 @@ static int mutt_sasl_conn_close (CONNECT FREE (&sasldata); /* call underlying close */ - rc = (conn->close) (conn); + rc = (conn->conn_close) (conn); return rc; } @@ -585,7 +585,7 @@ static int mutt_sasl_conn_read (CONNECTI do { /* call the underlying read function to fill the buffer */ - rc = (sasldata->read) (conn, buf, len); + rc = (sasldata->msasl_read) (conn, buf, len); if (rc <= 0) goto out; @@ -609,7 +609,7 @@ static int mutt_sasl_conn_read (CONNECTI rc = olen; } else - rc = (sasldata->read) (conn, buf, len); + rc = (sasldata->msasl_read) (conn, buf, len); out: conn->sockdata = sasldata; @@ -649,7 +649,7 @@ static int mutt_sasl_conn_write (CONNECT goto fail; } - rc = (sasldata->write) (conn, pbuf, plen); + rc = (sasldata->msasl_write) (conn, pbuf, plen); #ifndef USE_SASL2 FREE (&pbuf); #endif @@ -663,7 +663,7 @@ static int mutt_sasl_conn_write (CONNECT } else /* just write using the underlying socket function */ - rc = (sasldata->write) (conn, buf, len); + rc = (sasldata->msasl_write) (conn, buf, len); conn->sockdata = sasldata; Index: mutt_sasl.h =================================================================== RCS file: /home/roessler/cvs/mutt/mutt_sasl.h,v retrieving revision 3.1 diff -u -p -r3.1 mutt_sasl.h --- mutt_sasl.h 12 Nov 2002 08:20:08 -0000 3.1 +++ mutt_sasl.h 4 Mar 2005 17:22:25 -0000 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000-1 Brendan Cully <brendan@xxxxxxxxxx> + * Copyright (C) 2000-5 Brendan Cully <brendan@xxxxxxxxxx> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -51,10 +51,10 @@ typedef struct /* underlying socket data */ void* sockdata; - int (*open) (CONNECTION* conn); - int (*close) (CONNECTION* conn); - int (*read) (CONNECTION* conn, char* buf, size_t len); - int (*write) (CONNECTION* conn, const char* buf, size_t count); + int (*msasl_open) (CONNECTION* conn); + int (*msasl_close) (CONNECTION* conn); + int (*msasl_read) (CONNECTION* conn, char* buf, size_t len); + int (*msasl_write) (CONNECTION* conn, const char* buf, size_t count); } SASL_DATA; Index: mutt_socket.c =================================================================== RCS file: /home/roessler/cvs/mutt/mutt_socket.c,v retrieving revision 3.7 diff -u -p -r3.7 mutt_socket.c --- mutt_socket.c 3 Feb 2005 17:01:43 -0000 3.7 +++ mutt_socket.c 4 Mar 2005 17:22:25 -0000 @@ -1,6 +1,6 @@ /* * Copyright (C) 1998 Michael R. Elkins <me@xxxxxxxx> - * Copyright (C) 1999-2001 Brendan Cully <brendan@xxxxxxxxxx> + * Copyright (C) 1999-2005 Brendan Cully <brendan@xxxxxxxxxx> * Copyright (C) 1999-2000 Tommi Komulainen <Tommi.Komulainen@xxxxxx> * * This program is free software; you can redistribute it and/or modify @@ -56,7 +56,7 @@ int mutt_socket_open (CONNECTION* conn) if (socket_preconnect ()) return -1; - return conn->open (conn); + return conn->conn_open (conn); } int mutt_socket_close (CONNECTION* conn) @@ -66,7 +66,7 @@ int mutt_socket_close (CONNECTION* conn) if (conn->fd < 0) dprint (1, (debugfile, "mutt_socket_close: Attempt to close closed connection.\n")); else - rc = conn->close (conn); + rc = conn->conn_close (conn); conn->fd = -1; conn->ssf = 0; @@ -84,7 +84,7 @@ int mutt_socket_read (CONNECTION* conn, return -1; } - rc = conn->read (conn, buf, len); + rc = conn->conn_read (conn, buf, len); /* EOF */ if (rc == 0) { @@ -111,7 +111,7 @@ int mutt_socket_write_d (CONNECTION *con } len = mutt_strlen (buf); - if ((rc = conn->write (conn, buf, len)) < 0) + if ((rc = conn->conn_write (conn, buf, len)) < 0) { dprint (1, (debugfile, "mutt_socket_write: error writing, closing socket\n")); @@ -135,7 +135,7 @@ int mutt_socket_readchar (CONNECTION *co if (conn->bufpos >= conn->available) { if (conn->fd >= 0) - conn->available = conn->read (conn, conn->inbuf, sizeof (conn->inbuf)); + conn->available = conn->conn_read (conn, conn->inbuf, sizeof (conn->inbuf)); else { dprint (1, (debugfile, "mutt_socket_readchar: attempt to read from closed connection.\n")); @@ -277,10 +277,10 @@ CONNECTION* mutt_conn_find (const CONNEC } else { - conn->read = raw_socket_read; - conn->write = raw_socket_write; - conn->open = raw_socket_open; - conn->close = raw_socket_close; + conn->conn_read = raw_socket_read; + conn->conn_write = raw_socket_write; + conn->conn_open = raw_socket_open; + conn->conn_close = raw_socket_close; } return conn; Index: mutt_socket.h =================================================================== RCS file: /home/roessler/cvs/mutt/mutt_socket.h,v retrieving revision 3.0 diff -u -p -r3.0 mutt_socket.h --- mutt_socket.h 24 Jan 2002 12:10:50 -0000 3.0 +++ mutt_socket.h 4 Mar 2005 17:22:25 -0000 @@ -1,6 +1,6 @@ /* * Copyright (C) 1998 Brandon Long <blong@xxxxxxxxxxx> - * Copyright (C) 1999-2001 Brendan Cully <brendan@xxxxxxxxxx> + * Copyright (C) 1999-2005 Brendan Cully <brendan@xxxxxxxxxx> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -44,10 +44,10 @@ typedef struct _connection struct _connection *next; void *sockdata; - int (*read) (struct _connection* conn, char* buf, size_t len); - int (*write) (struct _connection *conn, const char *buf, size_t count); - int (*open) (struct _connection *conn); - int (*close) (struct _connection *conn); + int (*conn_read) (struct _connection* conn, char* buf, size_t len); + int (*conn_write) (struct _connection *conn, const char *buf, size_t count); + int (*conn_open) (struct _connection *conn); + int (*conn_close) (struct _connection *conn); } CONNECTION; int mutt_socket_open (CONNECTION* conn); Index: mutt_ssl.c =================================================================== RCS file: /home/roessler/cvs/mutt/mutt_ssl.c,v retrieving revision 3.6 diff -u -p -r3.6 mutt_ssl.c --- mutt_ssl.c 3 Feb 2005 17:01:43 -0000 3.6 +++ mutt_ssl.c 4 Mar 2005 17:22:26 -0000 @@ -116,9 +116,9 @@ int mutt_ssl_starttls (CONNECTION* conn) /* hmm. watch out if we're starting TLS over any method other than raw. */ conn->sockdata = ssldata; - conn->read = ssl_socket_read; - conn->write = ssl_socket_write; - conn->close = tls_close; + conn->conn_read = ssl_socket_read; + conn->conn_write = ssl_socket_write; + conn->conn_close = tls_close; conn->ssf = SSL_CIPHER_get_bits (SSL_get_current_cipher (ssldata->ssl), &maxbits); @@ -233,14 +233,14 @@ int ssl_socket_setup (CONNECTION * conn) { if (ssl_init() < 0) { - conn->open = ssl_socket_open_err; + conn->conn_open = ssl_socket_open_err; return -1; } - conn->open = ssl_socket_open; - conn->read = ssl_socket_read; - conn->write = ssl_socket_write; - conn->close = ssl_socket_close; + conn->conn_open = ssl_socket_open; + conn->conn_read = ssl_socket_read; + conn->conn_write = ssl_socket_write; + conn->conn_close = ssl_socket_close; return 0; } @@ -373,9 +373,9 @@ static int tls_close (CONNECTION* conn) int rc; rc = ssl_socket_close (conn); - conn->read = raw_socket_read; - conn->write = raw_socket_write; - conn->close = raw_socket_close; + conn->conn_read = raw_socket_read; + conn->conn_write = raw_socket_write; + conn->conn_close = raw_socket_close; return rc; } Index: mutt_ssl_gnutls.c =================================================================== RCS file: /home/roessler/cvs/mutt/mutt_ssl_gnutls.c,v retrieving revision 3.4 diff -u -p -r3.4 mutt_ssl_gnutls.c --- mutt_ssl_gnutls.c 11 Feb 2005 04:12:03 -0000 3.4 +++ mutt_ssl_gnutls.c 4 Mar 2005 17:22:26 -0000 @@ -77,10 +77,10 @@ int mutt_gnutls_socket_setup (CONNECTION if (tls_init() < 0) return -1; - conn->open = tls_socket_open; - conn->read = tls_socket_read; - conn->write = tls_socket_write; - conn->close = tls_socket_close; + conn->conn_open = tls_socket_open; + conn->conn_read = tls_socket_read; + conn->conn_write = tls_socket_write; + conn->conn_close = tls_socket_close; return 0; } @@ -151,9 +151,9 @@ int mutt_gnutls_starttls (CONNECTION* co if (tls_negotiate (conn) < 0) return -1; - conn->read = tls_socket_read; - conn->write = tls_socket_write; - conn->close = tls_starttls_close; + conn->conn_read = tls_socket_read; + conn->conn_write = tls_socket_write; + conn->conn_close = tls_starttls_close; return 0; } @@ -298,9 +298,9 @@ static int tls_starttls_close (CONNECTIO int rc; rc = tls_socket_close (conn); - conn->read = raw_socket_read; - conn->write = raw_socket_write; - conn->close = raw_socket_close; + conn->conn_read = raw_socket_read; + conn->conn_write = raw_socket_write; + conn->conn_close = raw_socket_close; return rc; } Index: mutt_ssl_nss.c =================================================================== RCS file: /home/roessler/cvs/mutt/mutt_ssl_nss.c,v retrieving revision 3.2 diff -u -p -r3.2 mutt_ssl_nss.c --- mutt_ssl_nss.c 3 Feb 2005 17:01:43 -0000 3.2 +++ mutt_ssl_nss.c 4 Mar 2005 17:22:26 -0000 @@ -374,9 +374,9 @@ mutt_nss_socket_setup (CONNECTION * con) { if (mutt_nss_init ()) return -1; - con->open = mutt_nss_socket_open; - con->read = mutt_nss_socket_read; - con->write = mutt_nss_socket_write; - con->close = mutt_nss_socket_close; + con->conn_open = mutt_nss_socket_open; + con->conn_read = mutt_nss_socket_read; + con->conn_write = mutt_nss_socket_write; + con->conn_close = mutt_nss_socket_close; return 0; } Index: mutt_tunnel.c =================================================================== RCS file: /home/roessler/cvs/mutt/mutt_tunnel.c,v retrieving revision 3.1 diff -u -p -r3.1 mutt_tunnel.c --- mutt_tunnel.c 3 Feb 2005 17:01:43 -0000 3.1 +++ mutt_tunnel.c 4 Mar 2005 17:22:26 -0000 @@ -49,10 +49,10 @@ static int tunnel_socket_write (CONNECTI /* -- public functions -- */ int mutt_tunnel_socket_setup (CONNECTION *conn) { - conn->open = tunnel_socket_open; - conn->close = tunnel_socket_close; - conn->read = tunnel_socket_read; - conn->write = tunnel_socket_write; + conn->conn_open = tunnel_socket_open; + conn->conn_close = tunnel_socket_close; + conn->conn_read = tunnel_socket_read; + conn->conn_write = tunnel_socket_write; return 0; }
Attachment:
pgp920XnU1lBM.pgp
Description: PGP signature