cvs: ZendEngine2 / zend_alloc.c zend_multiply.h zend_types.h
"Dmitry Stogov" <[email protected]>
| Newsgroups | gmane.comp.php.cvs.zend |
|---|---|
| Message-ID | <cvsdmitry1216907209@cvsserver> |
dmitry Thu Jul 24 13:46:49 2008 UTC
Modified files:
/ZendEngine2 zend_alloc.c zend_multiply.h zend_types.h
Log:
Optimized ZEND_SIGNED_MULTIPLY_LONG() (Matt)
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_alloc.c?r1=1.214&r2=1.215&diff_format=u
Index: ZendEngine2/zend_alloc.c
diff -u ZendEngine2/zend_alloc.c:1.214 ZendEngine2/zend_alloc.c:1.215
--- ZendEngine2/zend_alloc.c:1.214 Mon Jul 21 17:06:16 2008
+++ ZendEngine2/zend_alloc.c Thu Jul 24 13:46:48 2008
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_alloc.c,v 1.214 2008/07/21 17:06:16 dmitry Exp $ */
+/* $Id: zend_alloc.c,v 1.215 2008/07/24 13:46:48 dmitry Exp $ */
#include "zend.h"
#include "zend_alloc.h"
@@ -2402,6 +2402,19 @@
return res;
}
+#elif SIZEOF_SIZE_T == 4 && defined(HAVE_ZEND_LONG64)
+
+static inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
+{
+ zend_ulong64 res = (zend_ulong64)nmemb * (zend_ulong64)size + (zend_ulong64)offset;
+
+ if (UNEXPECTED(res > (zend_ulong64)0xFFFFFFFFL)) {
+ zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
+ return 0;
+ }
+ return (size_t) res;
+}
+
#else
static inline size_t safe_address(size_t nmemb, size_t size, size_t offset) /* {{{ */
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_multiply.h?r1=1.14&r2=1.15&diff_format=u
Index: ZendEngine2/zend_multiply.h
diff -u ZendEngine2/zend_multiply.h:1.14 ZendEngine2/zend_multiply.h:1.15
--- ZendEngine2/zend_multiply.h:1.14 Mon Dec 31 07:12:07 2007
+++ ZendEngine2/zend_multiply.h Thu Jul 24 13:46:48 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_multiply.h,v 1.14 2007/12/31 07:12:07 sebastian Exp $ */
+/* $Id: zend_multiply.h,v 1.15 2008/07/24 13:46:48 dmitry Exp $ */
#if defined(__i386__) && defined(__GNUC__)
@@ -31,6 +31,19 @@
else (lval) = __tmpvar; \
} while (0)
+#elif SIZEOF_LONG == 4 && defined(HAVE_ZEND_LONG64)
+
+#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
+ zend_long64 __result = (zend_long64) (a) * (zend_long64) (b); \
+ if (__result > LONG_MAX || __result < LONG_MIN) { \
+ (dval) = (double) __result; \
+ (usedval) = 1; \
+ } else { \
+ (lval) = (long) __result; \
+ (usedval) = 0; \
+ } \
+} while (0)
+
#else
#define ZEND_SIGNED_MULTIPLY_LONG(a, b, lval, dval, usedval) do { \
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_types.h?r1=1.12&r2=1.13&diff_format=u
Index: ZendEngine2/zend_types.h
diff -u ZendEngine2/zend_types.h:1.12 ZendEngine2/zend_types.h:1.13
--- ZendEngine2/zend_types.h:1.12 Mon Dec 31 07:12:07 2007
+++ ZendEngine2/zend_types.h Thu Jul 24 13:46:48 2008
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_types.h,v 1.12 2007/12/31 07:12:07 sebastian Exp $ */
+/* $Id: zend_types.h,v 1.13 2008/07/24 13:46:48 dmitry Exp $ */
#ifndef ZEND_TYPES_H
#define ZEND_TYPES_H
@@ -28,6 +28,20 @@
typedef unsigned long zend_ulong;
typedef unsigned short zend_ushort;
+#define HAVE_ZEND_LONG64
+#ifdef ZEND_WIN32
+typedef __int64 zend_long64;
+typedef unsigned __int64 zend_ulong64;
+#elif SIZEOF_LONG_LONG_INT == 8
+typedef long long int zend_long64;
+typedef unsigned long long int zend_ulong64;
+#elif SIZEOF_LONG_LONG == 8
+typedef long long zend_long64;
+typedef unsigned long long zend_ulong64;
+#else
+# undef HAVE_ZEND_LONG64
+#endif
+
#ifdef _WIN64
typedef __int64 zend_intptr_t;
typedef unsigned __int64 zend_uintptr_t;
--
Zend Engine CVS Mailing List (http://cvs.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php