zend_long.h revision b7a7b1a6
18ee2a4a9SAnatol Belski/*
28ee2a4a9SAnatol Belski   +----------------------------------------------------------------------+
38ee2a4a9SAnatol Belski   | Zend Engine                                                          |
48ee2a4a9SAnatol Belski   +----------------------------------------------------------------------+
58ee2a4a9SAnatol Belski   | Copyright (c) 1998-2013 Zend Technologies Ltd. (http://www.zend.com) |
68ee2a4a9SAnatol Belski   +----------------------------------------------------------------------+
78ee2a4a9SAnatol Belski   | This source file is subject to version 2.00 of the Zend license,     |
8b7a7b1a6SStanislav Malyshev   | that is bundled with this package in the file LICENSE, and is        |
98ee2a4a9SAnatol Belski   | available through the world-wide-web at the following url:           |
108ee2a4a9SAnatol Belski   | http://www.zend.com/license/2_00.txt.                                |
118ee2a4a9SAnatol Belski   | If you did not receive a copy of the Zend license and are unable to  |
128ee2a4a9SAnatol Belski   | obtain it through the world-wide-web, please send a note to          |
138ee2a4a9SAnatol Belski   | license@zend.com so we can mail you a copy immediately.              |
148ee2a4a9SAnatol Belski   +----------------------------------------------------------------------+
158ee2a4a9SAnatol Belski   | Authors: Anatol Belski <ab@php.net>                                  |
168ee2a4a9SAnatol Belski   +----------------------------------------------------------------------+
178ee2a4a9SAnatol Belski*/
188ee2a4a9SAnatol Belski
198ee2a4a9SAnatol Belski/* $Id$ */
208ee2a4a9SAnatol Belski
218ee2a4a9SAnatol Belski
224d997f63SAnatol Belski#ifndef ZEND_LONG_H
234d997f63SAnatol Belski#define ZEND_LONG_H
248ee2a4a9SAnatol Belski
25c3e3c98eSAnatol Belski#include "main/php_stdint.h"
268ee2a4a9SAnatol Belski
27baee5922SAnatol Belski/* This is the heart of the whole int64 enablement in zval. */
288ee2a4a9SAnatol Belski#if defined(__X86_64__) || defined(__LP64__) || defined(_LP64) || defined(_WIN64)
295d062b61SAnatol Belski# define ZEND_ENABLE_ZVAL_LONG64 1
308ee2a4a9SAnatol Belski#endif
318ee2a4a9SAnatol Belski
32202e8db1SAnatol Belski/* Integer types. */
335d062b61SAnatol Belski#ifdef ZEND_ENABLE_ZVAL_LONG64
345d030000SAnatol Belskitypedef int64_t zend_long;
355d030000SAnatol Belskitypedef uint64_t zend_ulong;
365d030000SAnatol Belskitypedef int64_t zend_off_t;
375d030000SAnatol Belski# define ZEND_LONG_MAX INT64_MAX
385d030000SAnatol Belski# define ZEND_LONG_MIN INT64_MIN
395d030000SAnatol Belski# define ZEND_ULONG_MAX UINT64_MAX
405d030000SAnatol Belski# ifdef _WIN64
41b9514bb8SAnatol Belski#   define Z_L(i) i##i64
42455741fcSAnatol Belski#   define Z_UL(i) i##Ui64
438ee2a4a9SAnatol Belski# else
44b9514bb8SAnatol Belski#   define Z_L(i) i##LL
45455741fcSAnatol Belski#   define Z_UL(i) i##ULL
468ee2a4a9SAnatol Belski# endif
4728b7a033SAnatol Belski# define SIZEOF_ZEND_LONG 8
488ee2a4a9SAnatol Belski#else
49c429c74bSAnatol Belskitypedef int32_t zend_long;
50c429c74bSAnatol Belskitypedef uint32_t zend_ulong;
51c429c74bSAnatol Belskitypedef int32_t zend_off_t;
52c429c74bSAnatol Belski# define ZEND_LONG_MAX INT32_MAX
53c429c74bSAnatol Belski# define ZEND_LONG_MIN INT32_MIN
54c429c74bSAnatol Belski# define ZEND_ULONG_MAX UINT32_MAX
55964e1174SNikita Popov# define Z_L(i) INT32_C(i)
56964e1174SNikita Popov# define Z_UL(i) UINT32_C(i)
575d030000SAnatol Belski# define SIZEOF_ZEND_LONG 4
588ee2a4a9SAnatol Belski#endif
598ee2a4a9SAnatol Belski
608ee2a4a9SAnatol Belski
61202e8db1SAnatol Belski/* Conversion macros. */
624d997f63SAnatol Belski#define ZEND_LTOA_BUF_LEN 65
638ee2a4a9SAnatol Belski
645d062b61SAnatol Belski#ifdef ZEND_ENABLE_ZVAL_LONG64
65c429c74bSAnatol Belski# define ZEND_LONG_FMT "%" PRId64
66c429c74bSAnatol Belski# define ZEND_ULONG_FMT "%" PRIu64
67c429c74bSAnatol Belski# define ZEND_LONG_FMT_SPEC PRId64
68c429c74bSAnatol Belski# define ZEND_ULONG_FMT_SPEC PRIu64
698ee2a4a9SAnatol Belski# ifdef PHP_WIN32
704d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) _i64toa_s((i), (s), (len), 10)
714d997f63SAnatol Belski#  define ZEND_ATOL(i, s) i = _atoi64((s))
724d997f63SAnatol Belski#  define ZEND_STRTOL(s0, s1, base) _strtoi64((s0), (s1), (base))
734d997f63SAnatol Belski#  define ZEND_STRTOUL(s0, s1, base) _strtoui64((s0), (s1), (base))
744d997f63SAnatol Belski#  define ZEND_STRTOL_PTR _strtoi64
754d997f63SAnatol Belski#  define ZEND_STRTOUL_PTR _strtoui64
768ee2a4a9SAnatol Belski#  define ZEND_ABS _abs64
778ee2a4a9SAnatol Belski# else
784d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) \
798ee2a4a9SAnatol Belski	do { \
80c429c74bSAnatol Belski		int st = snprintf((s), (len), ZEND_LONG_FMT, (i)); \
818ee2a4a9SAnatol Belski		(s)[st] = '\0'; \
828ee2a4a9SAnatol Belski 	} while (0)
834d997f63SAnatol Belski#  define ZEND_ATOL(i, s) (i) = atoll((s))
844d997f63SAnatol Belski#  define ZEND_STRTOL(s0, s1, base) strtoll((s0), (s1), (base))
854d997f63SAnatol Belski#  define ZEND_STRTOUL(s0, s1, base) strtoull((s0), (s1), (base))
864d997f63SAnatol Belski#  define ZEND_STRTOL_PTR strtoll
874d997f63SAnatol Belski#  define ZEND_STRTOUL_PTR strtoull
88d6930c9aSAnatol Belski#  define ZEND_ABS imaxabs
898ee2a4a9SAnatol Belski# endif
908ee2a4a9SAnatol Belski#else
914d997f63SAnatol Belski# define ZEND_STRTOL(s0, s1, base) strtol((s0), (s1), (base))
924d997f63SAnatol Belski# define ZEND_STRTOUL(s0, s1, base) strtoul((s0), (s1), (base))
93c429c74bSAnatol Belski# define ZEND_LONG_FMT "%" PRId32
94c429c74bSAnatol Belski# define ZEND_ULONG_FMT "%" PRIu32
95c429c74bSAnatol Belski# define ZEND_LONG_FMT_SPEC PRId32
96c429c74bSAnatol Belski# define ZEND_ULONG_FMT_SPEC PRIu32
978ee2a4a9SAnatol Belski# ifdef PHP_WIN32
984d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) _ltoa_s((i), (s), (len), 10)
994d997f63SAnatol Belski#  define ZEND_ATOL(i, s) i = atol((s))
1008ee2a4a9SAnatol Belski# else
1014d997f63SAnatol Belski#  define ZEND_LTOA(i, s, len) \
1028ee2a4a9SAnatol Belski	do { \
103c429c74bSAnatol Belski		int st = snprintf((s), (len), ZEND_LONG_FMT, (i)); \
1048ee2a4a9SAnatol Belski		(s)[st] = '\0'; \
1058ee2a4a9SAnatol Belski 	} while (0)
1064d997f63SAnatol Belski#  define ZEND_ATOL(i, s) (i) = atol((s))
1078ee2a4a9SAnatol Belski# endif
1084d997f63SAnatol Belski# define ZEND_STRTOL_PTR strtol
1094d997f63SAnatol Belski# define ZEND_STRTOUL_PTR strtoul
1108ee2a4a9SAnatol Belski# define ZEND_ABS abs
1118ee2a4a9SAnatol Belski#endif
1128ee2a4a9SAnatol Belski
11361d37e05SDmitry Stogov#if SIZEOF_ZEND_LONG == 4
11461d37e05SDmitry Stogov# define MAX_LENGTH_OF_LONG 11
11561d37e05SDmitry Stogov# define LONG_MIN_DIGITS "2147483648"
11661d37e05SDmitry Stogov#elif SIZEOF_ZEND_LONG == 8
11761d37e05SDmitry Stogov# define MAX_LENGTH_OF_LONG 20
11861d37e05SDmitry Stogov# define LONG_MIN_DIGITS "9223372036854775808"
11961d37e05SDmitry Stogov#else
12061d37e05SDmitry Stogov# error "Unknown SIZEOF_ZEND_LONG"
12161d37e05SDmitry Stogov#endif
12261d37e05SDmitry Stogov
12361d37e05SDmitry Stogovstatic const char long_min_digits[] = LONG_MIN_DIGITS;
1248ee2a4a9SAnatol Belski
1254d997f63SAnatol Belski#endif /* ZEND_LONG_H */
1268ee2a4a9SAnatol Belski
1278ee2a4a9SAnatol Belski/*
1288ee2a4a9SAnatol Belski * Local variables:
1298ee2a4a9SAnatol Belski * tab-width: 4
1308ee2a4a9SAnatol Belski * c-basic-offset: 4
1318ee2a4a9SAnatol Belski * indent-tabs-mode: t
1328ee2a4a9SAnatol Belski * End:
1338ee2a4a9SAnatol Belski */
134