From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3245 invoked from network); 12 Aug 2005 13:27:42 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 12 Aug 2005 13:27:42 -0000 Received: (qmail 59471 invoked from network); 12 Aug 2005 13:27:34 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 12 Aug 2005 13:27:34 -0000 Received: (qmail 18362 invoked by alias); 12 Aug 2005 13:27:30 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21606 Received: (qmail 18350 invoked from network); 12 Aug 2005 13:27:29 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 12 Aug 2005 13:27:29 -0000 Received: (qmail 59241 invoked from network); 12 Aug 2005 13:27:29 -0000 Received: from dsl3-63-249-88-2.cruzio.com (HELO dot.blorf.net) (63.249.88.2) by a.mx.sunsite.dk with SMTP; 12 Aug 2005 13:27:21 -0000 Received: by dot.blorf.net (Postfix, from userid 1000) id C486F38BB; Fri, 12 Aug 2005 06:27:19 -0700 (PDT) Date: Fri, 12 Aug 2005 06:27:19 -0700 From: Wayne Davison To: Peter Stephenson Cc: zsh-workers@sunsite.dk Subject: Re: PATCH: silencing compiler warnings from gcc 4 Message-ID: <20050812132719.GA1879@blorf.net> References: <20050811200252.GA19497@blorf.net> <20050812123114.00f88c0b.pws@csr.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Kj7319i9nmIyA2yE" Content-Disposition: inline In-Reply-To: <20050812123114.00f88c0b.pws@csr.com> User-Agent: Mutt/1.5.9i X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Aug 12, 2005 at 12:31:14PM +0100, Peter Stephenson wrote: > But maybe it simply means if inline isn't available, we end up calling > two functions to get a simple strlen(). Yes, that's what my patch did. I had been thinking about optimizing that in the same way you suggested. I'm currently debating whether it might be enough to only use the inline functions if __GNUC__ is defined (since the value of the inline functions is at compile-time, not runtime). The only argument against this that I can come up with is that there may be some conditional code (at some point) that won't get compiled by gcc, and thus it won't get type-checked. The argument for only doing this with gcc is that we're sure that the inline functions are doing the right thing. Since it seems that we agree that this is a good thing for at least gcc, I've checked in a patch that uses inline functions for gcc and attached that patch to this email. If we want to extend this to use inline functions on every compiler that supports inline functions, the second attached patch should accomplish that -- it changes configure to add a new define, INLINE_AVAILABLE, if inline functions are possible. ..wayne.. --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="signedness.diff" --- Src/Zle/zle.h 10 Aug 2005 10:56:41 -0000 1.15 +++ Src/Zle/zle.h 12 Aug 2005 13:12:37 -0000 @@ -89,10 +89,22 @@ typedef int ZLE_INT_T; #define ZS_memmove memmove #define ZS_memset memset #define ZS_memcmp memcmp -#define ZS_strlen strlen -#define ZS_strcpy strcpy -#define ZS_strncpy strncpy -#define ZS_strncmp strncmp + +#ifdef __GNUC__ +static inline size_t ZS_strlen(ZLE_STRING_T s) +{ return strlen((char*)s); } +static inline ZLE_STRING_T ZS_strcpy(ZLE_STRING_T t, ZLE_STRING_T f) +{ return (ZLE_STRING_T)strcpy((char*)t, (char*)f); } +static inline ZLE_STRING_T ZS_strncpy(ZLE_STRING_T t, ZLE_STRING_T f, size_t l) +{ return (ZLE_STRING_T)strncpy((char*)t, (char*)f, l); } +static inline int ZS_strncmp(ZLE_STRING_T s1, ZLE_STRING_T s2, size_t l) +{ return strncmp((char*)s1, (char*)s2, l); } +#else +#define ZS_strlen(s) strlen((char*)(s)) +#define ZS_strcpy(t,f) strcpy((char*)(t),(char*)(f)) +#define ZS_strncpy(t,f,l) strncpy((char*)(t),(char*)(f),(l)) +#define ZS_strncmp(s1,s2,l) strncmp((char*)(s1),(char*)(s2),(l)) +#endif #define ZC_iblank iblank #define ZC_icntrl icntrl --Kj7319i9nmIyA2yE Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="signedness2.patch" --- configure.ac 1 Aug 2005 09:54:56 -0000 1.37 +++ configure.ac 12 Aug 2005 13:14:41 -0000 @@ -437,6 +437,14 @@ AC_SUBST(LIBLDFLAGS)dnl AC_PROG_CPP dnl Figure out how to run C preprocessor. AC_PROG_GCC_TRADITIONAL dnl Do we need -traditional flag for gcc. AC_C_CONST dnl Does compiler support `const'. +AC_C_INLINE + +AH_TEMPLATE([INLINE_AVAILABLE], +[Define to 1 if inline functions are possible.]) +case $ac_cv_c_inline in + no) ;; + *) AC_DEFINE(INLINE_AVAILABLE) ;; +esac dnl Default preprocessing on Mac OS X produces warnings case "$host_os" in --- Src/Zle/zle.h 12 Aug 2005 13:12:37 -0000 1.16 +++ Src/Zle/zle.h 12 Aug 2005 13:14:41 -0000 @@ -90,7 +90,7 @@ typedef int ZLE_INT_T; #define ZS_memset memset #define ZS_memcmp memcmp -#ifdef __GNUC__ +#ifdef INLINE_AVAILABLE static inline size_t ZS_strlen(ZLE_STRING_T s) { return strlen((char*)s); } static inline ZLE_STRING_T ZS_strcpy(ZLE_STRING_T t, ZLE_STRING_T f) --Kj7319i9nmIyA2yE--