From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11994 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] stdio: implement fopencookie(3) Date: Tue, 10 Oct 2017 16:56:54 -0400 Message-ID: <20171010205654.GJ1627@brightrain.aerifal.cx> References: <20171010180356.11352-1-nenolod@dereferenced.org> <20171010205117.3deabfc7@inria.fr> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1507669031 8657 195.159.176.226 (10 Oct 2017 20:57:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 10 Oct 2017 20:57:11 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12007-gllmg-musl=m.gmane.org@lists.openwall.com Tue Oct 10 22:57:05 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1e21aI-0001Oc-FO for gllmg-musl@m.gmane.org; Tue, 10 Oct 2017 22:57:02 +0200 Original-Received: (qmail 16066 invoked by uid 550); 10 Oct 2017 20:57:07 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 16048 invoked from network); 10 Oct 2017 20:57:06 -0000 Content-Disposition: inline In-Reply-To: <20171010205117.3deabfc7@inria.fr> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11994 Archived-At: On Tue, Oct 10, 2017 at 08:51:17PM +0200, Jens Gustedt wrote: > Hello William, > > On Tue, 10 Oct 2017 18:03:56 +0000 William Pitcock > wrote: > > > The fopencookie(3) function allows the programmer to create a custom > > stdio implementation, using four hook functions which operate on a > > "cookie" data type. > > I know it is not your fault, but the naming conventions in this new > interface are realy bad design. > > > +typedef struct { > > + ssize_t (*read)(void *cookie, char *buf, size_t size); > > + ssize_t (*write)(void *cookie, const char *buf, size_t size); > > + int (*seek)(void *cookie, off_t *offset, int whence); > > + int (*close)(void *cookie); > > +} cookie_io_functions_t; > > > +FILE *fopencookie(void *cookie, const char *mode, cookie_io_functions_t io_funcs); > > The members may clash with macro names. E.g an implementation would be > allowed to overload "close" with a macro. This is not possible if the > implementation would want to use this interface here at the same time. > > User code could legitimately want to use a macro "seek" for its own > purpose. > > Could you at least avoid to use user-space names as function > parameters? Here you should just omit cookie, buf, size, offset, > whence, mode and io_funcs. I think in musl parameters in prototypes > usually don't have names. If you think that we should have them (they > sort of document the interface) you should put them into a reserved > namespace with leading underscore or so, or at least prefix them with > cookie_ I agree with most of the principles here (esp. how bad the public interface of this function is), but there's not a whole lot that can be done. Your one request is reasonable and in fact mandatory for musl header policy: we do not use parameter named at all in prototypes. So it should read just: FILE *fopencookie(void *, const char *, cookie_io_functions_t); Also note that while standard functions in POSIX can additionally be defined as function-like macros, they can't be object-like macros, so (*read), etc. are safe due to the parentheses. Rich