broken register_printf fix

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3660 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 1999-02-05 06:10:49 +00:00
parent 571d4548e7
commit 76865f335a
7 changed files with 356 additions and 318 deletions

View file

@ -1,3 +1,15 @@
1999-02-04 Adam Fedor <fedor@gnu.org>
* config/config.printf.c: New file.
* configure.in: Test for broken register_printf function.
* Source/NSLog.m (_NSLog_standard_printf_handler): Use fputs to
avoid possible double expansion of format chars.
1999-02-04 Matthias Klose <doko@cs.tu-berlin.de>
* Source/include/NSObject.h: eval value in ASSIGN macro only once.
Thu Feb 4 13:10:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSString.m: ([-dataUsingEncoding:allowLossyConversion:])

View file

@ -244,17 +244,18 @@ extern NSRecursiveLock *gnustep_global_lock;
* appropriate retain and release operations.
*/
#define ASSIGN(object,value) ({\
if (value != object) \
typeof (value) __value = (value); \
if (__value != object) \
{ \
if (value) \
if (__value) \
{ \
[value retain]; \
[__value retain]; \
} \
if (object) \
{ \
[object release]; \
} \
object = value; \
object = __value; \
} \
})

View file

@ -37,7 +37,7 @@ NSLog_printf_handler *_NSLog_printf_handler;
static void
_NSLog_standard_printf_handler (NSString* message)
{
fprintf (stderr, [message cString]);
fputs ([message cString], stderr);
}
void

View file

@ -288,7 +288,6 @@ testScanRadixUnsignedInt (void)
testScanRadixUnsignedIntFinish (@"FOO", NO, 0, 0);
testScanRadixUnsignedIntFinish (@" FOO", NO, 0, 0);
testScanRadixUnsignedIntFinish (@" 0x ", NO, 0, 0);
#endif
}
/*

71
config/config.printf.c Normal file
View file

@ -0,0 +1,71 @@
/* See if we have a broken register_printf function (e.g. an old version of glibc) */
#include <stdio.h>
#include <printf.h>
#include <stdarg.h>
/* <sattler@volker.cs.Uni-Magdeburg.DE>, with libc-5.3.9 thinks this
flag PRINTF_ATSIGN_VA_LIST should be 0, but for me, with libc-5.0.9,
it crashes. -mccallum
Apparently GNU libc 2.xx needs this to be 0 also, along with Linux
libc versions 5.2.xx and higher (including libc6, which is just GNU
libc). -chung */
#define PRINTF_ATSIGN_VA_LIST \
(defined(_LINUX_C_LIB_VERSION_MINOR) \
&& _LINUX_C_LIB_VERSION_MAJOR <= 5 \
&& _LINUX_C_LIB_VERSION_MINOR < 2)
#if ! PRINTF_ATSIGN_VA_LIST
static int
arginfo_func (const struct printf_info *info, size_t n, int *argtypes)
{
*argtypes = PA_POINTER;
return 1;
}
#endif /* !PRINTF_ATSIGN_VA_LIST */
static int
handle_printf_atsign (FILE *stream,
const struct printf_info *info,
#if PRINTF_ATSIGN_VA_LIST
va_list *ap_pointer)
#elif defined(_LINUX_C_LIB_VERSION_MAJOR) \
&& _LINUX_C_LIB_VERSION_MAJOR < 6
const void **const args)
#else /* GNU libc needs the following. */
const void *const *args)
#endif
{
#if ! PRINTF_ATSIGN_VA_LIST
const void *ptr = *args;
#endif
char * string_object;
int len;
/* xxx This implementation may not pay pay attention to as much
of printf_info as it should. */
#if PRINTF_ATSIGN_VA_LIST
string_object = va_arg (*ap_pointer, char *);
#else
string_object = *((char **) ptr);
#endif
len = fprintf(stream, "%s", string_object);
return len;
}
int main()
{
char *d = "hi there";
register_printf_function ('@',
handle_printf_atsign,
#if PRINTF_ATSIGN_VA_LIST
0);
#else
arginfo_func);
#endif
printf("test %s = %@\n", d, d);
return 0;
}

568
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -498,7 +498,16 @@ AC_CHECK_FUNCS(strerror)
#--------------------------------------------------------------------
# This function needed by NSString for handling of %@ printf directive.
#--------------------------------------------------------------------
AC_CHECK_FUNCS(register_printf_function)
AC_CHECK_FUNC(register_printf_function, register_printf=1,
register_printf=0)
if test $register_printf = 1; then
AC_TRY_RUN([#include "$srcdir/config/config.printf.c"],
working_register_printf=1, working_register_printf=0,
working_register_printf=1)
if test $working_register_printf = 1; then
AC_DEFINE(HAVE_REGISTER_PRINTF_FUNCTION)
fi
fi
#--------------------------------------------------------------------
# Tools for making a DLL.