mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
standardise on using c99 limits (define old values to the new ones)
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29658 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c8a6832349
commit
92bceae15f
3 changed files with 85 additions and 65 deletions
|
@ -40,18 +40,33 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
/* We need to define _GNU_SOURCE on systems (SuSE) to get LONG_LONG_MAX. */
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#if defined(HAVE_STDINT_H)
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LIMITS_H)
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#if !defined(HANDLE_LLONG_MAX) && defined(HANDLE_LONG_LONG_MAX)
|
||||
#define LLONG_MAX LONG_LONG_MAX
|
||||
#define LLONG_MIN LONG_LONG_MIN
|
||||
#define ULLONG_MAX ULONG_LONG_MAX
|
||||
#endif
|
||||
|
||||
#if defined(HANDLE_LLONG_MAX) && !defined(LONG_LONG_MAX)
|
||||
#error handle_llong_max defined without llong_max being defined
|
||||
#elif defined(HANDLE_LONG_LONG_MAX) && !defined(LONG_LONG_MAX)
|
||||
#error handle_long_long_max defined without long_long_max being defined
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ALLOCA_H
|
||||
#include <alloca.h>
|
||||
#endif
|
||||
#include <limits.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -104,26 +119,6 @@ typedef uint32_t wint_t;
|
|||
typedef unsigned long long uintmax_t;
|
||||
#endif
|
||||
|
||||
/* BSD and Solaris have this */
|
||||
#if defined(HANDLE_LLONG_MAX) && !defined(HANDLE_LONG_LONG_MAX)
|
||||
#define LONG_LONG_MAX LLONG_MAX
|
||||
#define LONG_LONG_MIN LLONG_MIN
|
||||
#define ULONG_LONG_MAX ULLONG_MAX
|
||||
#else
|
||||
/* Darwin 1.0 CPP can't handle this */
|
||||
#ifndef HANDLE_LONG_LONG_MAX
|
||||
#undef LONG_LONG_MAX
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(HANDLE_LONG_LONG_MAX) && !defined(LONG_LONG_MAX)
|
||||
#error handle_long_long_max defined without long_long_max being defined
|
||||
#else
|
||||
#if defined(HANDLE_LLONG_MAX) && !defined(LONG_LONG_MAX)
|
||||
#error handle_llong_max defined without llong_max being defined
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#import "GNUstepBase/Unicode.h"
|
||||
|
||||
|
@ -638,8 +633,8 @@ parse_one_spec (const unichar *format, size_t posn, struct printf_spec *spec,
|
|||
case 'Z':
|
||||
/* ints are size_ts. */
|
||||
NSCParameterAssert (sizeof (size_t) <= sizeof (unsigned long long int));
|
||||
#if defined(LONG_LONG_MAX)
|
||||
#if LONG_MAX != LONG_LONG_MAX
|
||||
#if defined(LLONG_MAX)
|
||||
#if LONG_MAX != LLONG_MAX
|
||||
spec->info.is_long_double = sizeof (size_t) > sizeof (unsigned long int);
|
||||
#endif
|
||||
#endif
|
||||
|
@ -647,8 +642,8 @@ parse_one_spec (const unichar *format, size_t posn, struct printf_spec *spec,
|
|||
break;
|
||||
case 't':
|
||||
NSCParameterAssert (sizeof (ptrdiff_t) <= sizeof (long long int));
|
||||
#if defined(LONG_LONG_MAX)
|
||||
#if LONG_MAX != LONG_LONG_MAX
|
||||
#if defined(LLONG_MAX)
|
||||
#if LONG_MAX != LLONG_MAX
|
||||
spec->info.is_long_double = (sizeof (ptrdiff_t) > sizeof (long int));
|
||||
#endif
|
||||
#endif
|
||||
|
@ -656,8 +651,8 @@ parse_one_spec (const unichar *format, size_t posn, struct printf_spec *spec,
|
|||
break;
|
||||
case 'j':
|
||||
NSCParameterAssert (sizeof (uintmax_t) <= sizeof (unsigned long long int));
|
||||
#if defined(LONG_LONG_MAX)
|
||||
#if LONG_MAX != LONG_LONG_MAX
|
||||
#if defined(LLONG_MAX)
|
||||
#if LONG_MAX != LLONG_MAX
|
||||
spec->info.is_long_double = (sizeof (uintmax_t)
|
||||
> sizeof (unsigned long int));
|
||||
#endif
|
||||
|
@ -684,8 +679,8 @@ parse_one_spec (const unichar *format, size_t posn, struct printf_spec *spec,
|
|||
case 'o':
|
||||
case 'X':
|
||||
case 'x':
|
||||
#if defined(LONG_LONG_MAX)
|
||||
#if LONG_MAX != LONG_LONG_MAX
|
||||
#if defined(LLONG_MAX)
|
||||
#if LONG_MAX != LLONG_MAX
|
||||
if (spec->info.is_long_double)
|
||||
spec->data_arg_type = PA_INT|PA_FLAG_LONG_LONG;
|
||||
else
|
||||
|
@ -775,8 +770,8 @@ static inline void GSStrAppendUnichar(GSStr s, unichar u)
|
|||
/* For handling long_double and longlong we use the same flag. If
|
||||
`long' and `long long' are effectively the same type define it to
|
||||
zero. */
|
||||
#if defined(LONG_LONG_MAX)
|
||||
#if LONG_MAX == LONG_LONG_MAX
|
||||
#if defined(LLONG_MAX)
|
||||
#if LONG_MAX == LLONG_MAX
|
||||
# define is_longlong 0
|
||||
#else
|
||||
# define is_longlong is_long_double
|
||||
|
@ -1116,7 +1111,7 @@ NSDictionary *locale)
|
|||
int left = specs[nspecs_done].info.left;
|
||||
int showsign = specs[nspecs_done].info.showsign;
|
||||
int group = specs[nspecs_done].info.group;
|
||||
#if defined(LONG_LONG_MAX) && (LONG_MAX != LONG_LONG_MAX)
|
||||
#if defined(LLONG_MAX) && (LONG_MAX != LLONG_MAX)
|
||||
int is_long_double = specs[nspecs_done].info.is_long_double;
|
||||
#endif
|
||||
int is_short = specs[nspecs_done].info.is_short;
|
||||
|
|
|
@ -32,30 +32,39 @@
|
|||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STDINT_H)
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LIMITS_H)
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#if !defined(HANDLE_LLONG_MAX) && defined(HANDLE_LONG_LONG_MAX)
|
||||
#define LLONG_MAX LONG_LONG_MAX
|
||||
#define LLONG_MIN LONG_LONG_MIN
|
||||
#define ULLONG_MAX ULONG_LONG_MAX
|
||||
#endif
|
||||
|
||||
#if defined(HANDLE_LLONG_MAX) && !defined(LONG_LONG_MAX)
|
||||
#error handle_llong_max defined without llong_max being defined
|
||||
#elif defined(HANDLE_LONG_LONG_MAX) && !defined(LONG_LONG_MAX)
|
||||
#error handle_long_long_max defined without long_long_max being defined
|
||||
#endif
|
||||
|
||||
|
||||
#import "Foundation/NSCoder.h"
|
||||
#import "Foundation/NSDecimalNumber.h"
|
||||
#import "Foundation/NSException.h"
|
||||
#import "Foundation/NSValue.h"
|
||||
#import "GNUstepBase/NSObject+GNUstepBase.h"
|
||||
|
||||
#if defined(HANDLE_LLONG_MAX) && !defined(HANDLE_LONG_LONG_MAX)
|
||||
#define LONG_LONG_MAX LLONG_MAX
|
||||
#define LONG_LONG_MIN LLONG_MIN
|
||||
#define ULONG_LONG_MAX ULLONG_MAX
|
||||
#endif
|
||||
|
||||
/*
|
||||
* NSNumber implementation. This matches the behaviour of Apple's
|
||||
* implementation. Values in the range -1 to 12 inclusive are mapped to
|
||||
* singletons. All other values are mapped to the smallest signed value that
|
||||
* will store them, unless they are greater than LONG_LONG_MAX, in which case
|
||||
* will store them, unless they are greater than LLONG_MAX, in which case
|
||||
* they are stored in an unsigned long long.
|
||||
*/
|
||||
|
||||
|
@ -484,7 +493,7 @@ if (aValue >= -1 && aValue <= 12)\
|
|||
{
|
||||
NSUnsignedLongLongNumber *n;
|
||||
|
||||
if (aValue < (unsigned long long) LONG_LONG_MAX)
|
||||
if (aValue < (unsigned long long) LLONG_MAX)
|
||||
{
|
||||
return [self numberWithLongLong: (long long) aValue];
|
||||
}
|
||||
|
|
|
@ -27,12 +27,39 @@
|
|||
$Date$ $Revision$
|
||||
*/
|
||||
|
||||
/* We need to define _GNU_SOURCE on systems (SuSE) to get LONG_LONG_MAX. */
|
||||
#import "config.h"
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#import "config.h"
|
||||
#if defined(HAVE_STDINT_H)
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LIMITS_H)
|
||||
#include <limits.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_FLOAT_H)
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
#if !defined(HANDLE_LLONG_MAX) && defined(HANDLE_LONG_LONG_MAX)
|
||||
#define LLONG_MAX LONG_LONG_MAX
|
||||
#define LLONG_MIN LONG_LONG_MIN
|
||||
#define ULLONG_MAX ULONG_LONG_MAX
|
||||
#endif
|
||||
|
||||
#if defined(HANDLE_LLONG_MAX) && !defined(LONG_LONG_MAX)
|
||||
#error handle_llong_max defined without llong_max being defined
|
||||
#elif defined(HANDLE_LONG_LONG_MAX) && !defined(LONG_LONG_MAX)
|
||||
#error handle_long_long_max defined without long_long_max being defined
|
||||
#endif
|
||||
|
||||
#include <math.h>
|
||||
#include <ctype.h> /* FIXME: May go away once I figure out Unicode */
|
||||
|
||||
#define EXPOSE_NSScanner_IVARS 1
|
||||
#import "GNUstepBase/Unicode.h"
|
||||
#import "Foundation/NSScanner.h"
|
||||
|
@ -41,19 +68,8 @@
|
|||
#import "Foundation/NSUserDefaults.h"
|
||||
#import "GNUstepBase/NSObject+GNUstepBase.h"
|
||||
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <ctype.h> /* FIXME: May go away once I figure out Unicode */
|
||||
#import "GSPrivate.h"
|
||||
|
||||
/* BSD and Solaris have this */
|
||||
#if defined(HANDLE_LLONG_MAX) && !defined(HANDLE_LONG_LONG_MAX)
|
||||
#define LONG_LONG_MAX LLONG_MAX
|
||||
#define LONG_LONG_MIN LLONG_MIN
|
||||
#define ULONG_LONG_MAX ULLONG_MAX
|
||||
#endif
|
||||
|
||||
|
||||
@class GSCString;
|
||||
@interface GSCString : NSObject // Help the compiler
|
||||
|
@ -557,16 +573,16 @@ typedef GSString *ivars;
|
|||
* <br/>
|
||||
* Returns YES if anything is scanned, NO otherwise.
|
||||
* <br/>
|
||||
* On overflow, LONG_LONG_MAX or LONG_LONG_MIN is put into
|
||||
* On overflow, LLONG_MAX or LLONG_MIN is put into
|
||||
* <em>longLongValue</em>
|
||||
* <br/>
|
||||
* Scans past any excess digits
|
||||
*/
|
||||
- (BOOL) scanLongLong: (long long *)value
|
||||
{
|
||||
#if defined(LONG_LONG_MAX)
|
||||
#if defined(LLONG_MAX)
|
||||
unsigned long long num = 0;
|
||||
const unsigned long long limit = ULONG_LONG_MAX / 10;
|
||||
const unsigned long long limit = ULLONG_MAX / 10;
|
||||
BOOL negative = NO;
|
||||
BOOL overflow = NO;
|
||||
BOOL got_digits = NO;
|
||||
|
@ -621,21 +637,21 @@ typedef GSString *ivars;
|
|||
{
|
||||
if (negative)
|
||||
{
|
||||
if (overflow || (num > (unsigned long long)LONG_LONG_MIN))
|
||||
*value = LONG_LONG_MIN;
|
||||
if (overflow || (num > (unsigned long long)LLONG_MIN))
|
||||
*value = LLONG_MIN;
|
||||
else
|
||||
*value = -num;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (overflow || (num > (unsigned long long)LONG_LONG_MAX))
|
||||
*value = LONG_LONG_MAX;
|
||||
if (overflow || (num > (unsigned long long)LLONG_MAX))
|
||||
*value = LLONG_MAX;
|
||||
else
|
||||
*value = num;
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
#else /* defined(LONG_LONG_MAX) */
|
||||
#else /* defined(LLONG_MAX) */
|
||||
/*
|
||||
* Provide compile-time warning and run-time exception.
|
||||
*/
|
||||
|
@ -643,7 +659,7 @@ typedef GSString *ivars;
|
|||
[NSException raise: NSGenericException
|
||||
format: @"Can't use long long variables."];
|
||||
return NO;
|
||||
#endif /* defined(LONG_LONG_MAX) */
|
||||
#endif /* defined(LLONG_MAX) */
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue