public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix btowc and wctob in C++
@ 2006-03-27 16:44 Jakub Jelinek
  2006-03-27 20:13 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2006-03-27 16:44 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

Doing:

#include <wchar.h>

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  <jakub@redhat.com>

	* 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix btowc and wctob in C++
  2006-03-27 16:44 [PATCH] Fix btowc and wctob in C++ Jakub Jelinek
@ 2006-03-27 20:13 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2006-03-27 20:13 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

[-- Attachment #1: Type: text/plain, Size: 101 bytes --]

Applied.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 253 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-03-27 20:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-27 16:44 [PATCH] Fix btowc and wctob in C++ Jakub Jelinek
2006-03-27 20:13 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).