From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11691 invoked by alias); 27 Mar 2006 16:44:28 -0000 Received: (qmail 11663 invoked by uid 22791); 27 Mar 2006 16:44:28 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 27 Mar 2006 16:44:27 +0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id k2RGiFTg020620; Mon, 27 Mar 2006 18:44:15 +0200 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id k2RGiFIf020619; Mon, 27 Mar 2006 18:44:15 +0200 Date: Mon, 27 Mar 2006 16:44:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix btowc and wctob in C++ Message-ID: <20060327164414.GB30252@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2006-03/txt/msg00042.txt.bz2 Hi! Doing: #include void *p = (void *) btowc; at -O1+ in C++ (or similarly if for whatever reason the inline isn't always inlined) results in endless recursion: .section .text.btowc,"axG",@progbits,btowc,comdat .align 2 .p2align 4,,15 .weak btowc .type btowc, @function btowc: jmp btowc .size btowc, .-btowc The optimization really relies on the GNU C extern inline behavior. We use the same __*_alias trick in plenty of the _FORTIFY_SOURCE headers, but none of them is used for C++ nor for non-GCC compilers. __USE_EXTERN_INLINES implies GCC 2.7+, so we just need to check for C++. 2006-03-27 Jakub Jelinek * wcsmbs/wchar.h (btowc, wctob): Don't optimize in C++. --- libc/wcsmbs/wchar.h.jj 2006-03-17 08:37:07.000000000 +0100 +++ libc/wcsmbs/wchar.h 2006-03-27 18:38:07.000000000 +0200 @@ -321,6 +321,7 @@ __END_NAMESPACE_C99 #ifdef __USE_EXTERN_INLINES /* Define inline function as optimization. */ +# ifndef __cplusplus /* We can use the BTOWC and WCTOB optimizations since we know that all locales must use ASCII encoding for the values in the ASCII range and because the wchar_t encoding is always ISO 10646. */ @@ -335,6 +336,7 @@ extern __inline int __NTH (wctob (wint_t __wc)) { return (__builtin_constant_p (__wc) && __wc >= L'\0' && __wc <= L'\x7f' ? (int) __wc : __wctob_alias (__wc)); } +# endif extern __inline size_t __NTH (mbrlen (__const char *__restrict __s, size_t __n, Jakub