From dc88d66f1aa98873becd21900046cae7bccbc14c Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 9 Jun 2004 19:04:56 +0000 Subject: [PATCH] ctype support. 2004-06-09 Frank Ch. Eigler ctype support. * configure.in: Look for ctype header and glibc implementation. * mf-hooks2.c (__ctype_{b,toupper,tolower}_loc): Sample ctype array hooks for glibc 2.3. * mf-runtime.h.in: Wrap them. * mf-runtime.c (__mf_init): Leave marker regarding other ctype implementations. * testsuite/libmudflap.c/pass47-frag.c: New test. * configure, config.h.in: Regenerated. From-SVN: r82848 --- libmudflap/ChangeLog | 12 +++ libmudflap/config.h.in | 12 +++ libmudflap/configure | 92 ++++++++++++++++++- libmudflap/configure.in | 5 +- libmudflap/mf-hooks2.c | 76 +++++++++++++++ libmudflap/mf-runtime.c | 6 ++ libmudflap/mf-runtime.h.in | 3 + .../testsuite/libmudflap.c/pass47-frag.c | 10 ++ 8 files changed, 213 insertions(+), 3 deletions(-) create mode 100644 libmudflap/testsuite/libmudflap.c/pass47-frag.c diff --git a/libmudflap/ChangeLog b/libmudflap/ChangeLog index e2b034b9ed2..2bcf83d7656 100644 --- a/libmudflap/ChangeLog +++ b/libmudflap/ChangeLog @@ -1,3 +1,15 @@ +2004-06-09 Frank Ch. Eigler + + ctype support. + * configure.in: Look for ctype header and glibc implementation. + * mf-hooks2.c (__ctype_{b,toupper,tolower}_loc): Sample ctype + array hooks for glibc 2.3. + * mf-runtime.h.in: Wrap them. + * mf-runtime.c (__mf_init): Leave marker regarding other ctype + implementations. + * testsuite/libmudflap.c/pass47-frag.c: New test. + * configure, config.h.in: Regenerated. + 2004-06-04 Frank Ch. Eigler Portability improvements, e.g., libmudflap/15293. diff --git a/libmudflap/config.h.in b/libmudflap/config.h.in index a9c7ed65dfc..bdcd239e59c 100644 --- a/libmudflap/config.h.in +++ b/libmudflap/config.h.in @@ -6,6 +6,9 @@ /* Define to 1 if you have the `backtrace_symbols' function. */ #undef HAVE_BACKTRACE_SYMBOLS +/* Define to 1 if you have the header file. */ +#undef HAVE_CTYPE_H + /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H @@ -108,6 +111,15 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H +/* Define to 1 if you have the `__ctype_b_loc' function. */ +#undef HAVE___CTYPE_B_LOC + +/* Define to 1 if you have the `__ctype_tolower_loc' function. */ +#undef HAVE___CTYPE_TOLOWER_LOC + +/* Define to 1 if you have the `__ctype_toupper_loc' function. */ +#undef HAVE___CTYPE_TOUPPER_LOC + /* Name of package */ #undef PACKAGE diff --git a/libmudflap/configure b/libmudflap/configure index c5f6b609807..0f49ab9eee2 100755 --- a/libmudflap/configure +++ b/libmudflap/configure @@ -3428,8 +3428,9 @@ done + for ac_header in stdint.h execinfo.h signal.h dlfcn.h \ - netdb.h sys/ipc.h sys/sem.h sys/shm.h sys/wait.h sys/socket.h + netdb.h sys/ipc.h sys/sem.h sys/shm.h sys/wait.h sys/socket.h ctype.h do as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` if eval "test \"\${$as_ac_Header+set}\" = set"; then @@ -3835,6 +3836,93 @@ fi done + + + +for ac_func in __ctype_b_loc __ctype_tolower_loc __ctype_toupper_loc +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6 +if eval "test \"\${$as_ac_var+set}\" = set"; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +#line $LINENO "configure" +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ +#ifdef __STDC__ +# include +#else +# include +#endif +/* Override any gcc2 internal prototype to avoid an error. */ +#ifdef __cplusplus +extern "C" +{ +#endif +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +char (*f) () = $ac_func; +#endif +#ifdef __cplusplus +} +#endif + +int +main () +{ +return f != $ac_func; + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5 + (eval $ac_link) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -s conftest$ac_exeext' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +eval "$as_ac_var=no" +fi +rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext +fi +echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5 +echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6 +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + cat >conftest.$ac_ext <<_ACEOF #line $LINENO "configure" /* confdefs.h. */ @@ -4672,7 +4760,7 @@ test x"$pic_mode" = xno && libtool_flags="$libtool_flags --prefer-non-pic" case $host in *-*-irix6*) # Find out which ABI we are using. - echo '#line 4675 "configure"' > conftest.$ac_ext + echo '#line 4763 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? diff --git a/libmudflap/configure.in b/libmudflap/configure.in index 67bc2d4261a..6e03ed5bbbb 100644 --- a/libmudflap/configure.in +++ b/libmudflap/configure.in @@ -63,7 +63,7 @@ AC_TRY_COMPILE([ enable_shared=no]) AC_CHECK_HEADERS(stdint.h execinfo.h signal.h dlfcn.h \ - netdb.h sys/ipc.h sys/sem.h sys/shm.h sys/wait.h sys/socket.h) + netdb.h sys/ipc.h sys/sem.h sys/shm.h sys/wait.h sys/socket.h ctype.h) AC_CHECK_FUNCS(backtrace backtrace_symbols gettimeofday signal) dnl Check for 64-bit stdio calls related to Large File Support @@ -72,6 +72,9 @@ AC_CHECK_FUNCS(fopen64 fseeko64 ftello64 stat64) dnl Check for nonstandard functions AC_CHECK_FUNCS(strnlen memrchr strncpy memmem sethostname) +dnl Check for glibc ctype functions +AC_CHECK_FUNCS(__ctype_b_loc __ctype_tolower_loc __ctype_toupper_loc) + AC_TRY_COMPILE([#include #include #include ],[union semun foo;], [mf_have_semun=1], [mf_have_semun=0]) diff --git a/libmudflap/mf-hooks2.c b/libmudflap/mf-hooks2.c index ccd9931be86..ff08d42ef76 100644 --- a/libmudflap/mf-hooks2.c +++ b/libmudflap/mf-hooks2.c @@ -63,6 +63,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include +#include #include #ifdef HAVE_SYS_SOCKET_H #include @@ -1643,3 +1644,78 @@ WRAPPER2(int, shmdt, const void *shmaddr) #endif /* HAVE_SYS_IPC/SEM/SHM_H */ + + + +/* ctype stuff. This is host-specific by necessity, as the arrays + that is used by most is*()/to*() macros are implementation-defined. */ + +/* GLIBC 2.3 */ +#ifdef HAVE___CTYPE_B_LOC +WRAPPER2(unsigned short **, __ctype_b_loc, void) +{ + static unsigned short * last_buf = (void *) 0; + static unsigned short ** last_ptr = (void *) 0; + unsigned short ** ptr = (unsigned short **) __ctype_b_loc (); + unsigned short * buf = * ptr; + if (ptr != last_ptr) + { + /* XXX: unregister last_ptr? */ + last_ptr = ptr; + __mf_register (last_ptr, sizeof(last_ptr), __MF_TYPE_STATIC, "ctype_b_loc **"); + } + if (buf != last_buf) + { + last_buf = buf; + __mf_register ((void *) (last_buf - 128), 384 * sizeof(unsigned short), __MF_TYPE_STATIC, + "ctype_b_loc []"); + } + return ptr; +} +#endif + +#ifdef HAVE___CTYPE_TOUPPER_LOC +WRAPPER2(int **, __ctype_toupper_loc, void) +{ + static int * last_buf = (void *) 0; + static int ** last_ptr = (void *) 0; + int ** ptr = (int **) __ctype_toupper_loc (); + int * buf = * ptr; + if (ptr != last_ptr) + { + /* XXX: unregister last_ptr? */ + last_ptr = ptr; + __mf_register (last_ptr, sizeof(last_ptr), __MF_TYPE_STATIC, "ctype_toupper_loc **"); + } + if (buf != last_buf) + { + last_buf = buf; + __mf_register ((void *) (last_buf - 128), 384 * sizeof(int), __MF_TYPE_STATIC, + "ctype_toupper_loc []"); + } + return ptr; +} +#endif + +#ifdef HAVE___CTYPE_TOLOWER_LOC +WRAPPER2(int **, __ctype_tolower_loc, void) +{ + static int * last_buf = (void *) 0; + static int ** last_ptr = (void *) 0; + int ** ptr = (int **) __ctype_tolower_loc (); + int * buf = * ptr; + if (ptr != last_ptr) + { + /* XXX: unregister last_ptr? */ + last_ptr = ptr; + __mf_register (last_ptr, sizeof(last_ptr), __MF_TYPE_STATIC, "ctype_tolower_loc **"); + } + if (buf != last_buf) + { + last_buf = buf; + __mf_register ((void *) (last_buf - 128), 384 * sizeof(int), __MF_TYPE_STATIC, + "ctype_tolower_loc []"); + } + return ptr; +} +#endif diff --git a/libmudflap/mf-runtime.c b/libmudflap/mf-runtime.c index ca42ab7ebbd..19e9fe28cc2 100644 --- a/libmudflap/mf-runtime.c +++ b/libmudflap/mf-runtime.c @@ -63,6 +63,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include #include #include +#include #include "mf-runtime.h" #include "mf-impl.h" @@ -685,6 +686,11 @@ __wrap_main (int argc, char* argv[]) __mf_register (stdin, sizeof (*stdin), __MF_TYPE_STATIC, "stdin"); __mf_register (stdout, sizeof (*stdout), __MF_TYPE_STATIC, "stdout"); __mf_register (stderr, sizeof (*stderr), __MF_TYPE_STATIC, "stderr"); + + /* Make some effort to register ctype.h static arrays. */ + /* XXX: e.g., on Solaris, may need to register __ctype, _ctype, __ctype_mask, __toupper, etc. */ + /* On modern Linux GLIBC, these are thread-specific and changeable, and are dealt + with in mf-hooks2.c. */ } #ifdef PIC diff --git a/libmudflap/mf-runtime.h.in b/libmudflap/mf-runtime.h.in index 11f1f8de5fe..7b0467b5e56 100644 --- a/libmudflap/mf-runtime.h.in +++ b/libmudflap/mf-runtime.h.in @@ -177,6 +177,9 @@ extern int __mf_set_options (const char *opts); #pragma redefine_extname shmctl __mfwrap_shmctl #pragma redefine_extname shmat __mfwrap_shmat #pragma redefine_extname shmdt __mfwrap_shmdt +#pragma redefine_extname __ctype_b_loc __mfwrap___ctype_b_loc +#pragma redefine_extname __ctype_toupper_loc __mfwrap___ctype_toupper_loc +#pragma redefine_extname __ctype_tolower_loc __mfwrap___ctype_tolower_loc /* Disable glibc macros. */ #define __NO_STRING_INLINES diff --git a/libmudflap/testsuite/libmudflap.c/pass47-frag.c b/libmudflap/testsuite/libmudflap.c/pass47-frag.c new file mode 100644 index 00000000000..9e4ac50ef3f --- /dev/null +++ b/libmudflap/testsuite/libmudflap.c/pass47-frag.c @@ -0,0 +1,10 @@ +#include +#include + +int main () +{ + char* buf = "hello"; + return ! ((toupper (buf[0]) == 'H' && toupper ('z') == 'Z' && + tolower (buf[4]) == 'o' && tolower ('X') == 'x' && + isdigit (buf[3])) == 0 && isalnum ('4')); +} -- 2.30.2